107 lines
3.5 KiB
JavaScript
107 lines
3.5 KiB
JavaScript
const mapper = require('../src/java-model')
|
|
|
|
const service = {
|
|
namespace: "de.nclazz.test.v0",
|
|
models: [
|
|
{
|
|
"name": "user",
|
|
"plural": "users",
|
|
"fields": [
|
|
{
|
|
"name": "id",
|
|
"type": "string",
|
|
"required": true,
|
|
"attributes": [],
|
|
"annotations": [],
|
|
"description": "ID of the user as a 32 char long hex string.",
|
|
"minimum": 32,
|
|
"maximum": 32
|
|
},
|
|
{
|
|
"name": "name",
|
|
"type": "string",
|
|
"required": true,
|
|
"attributes": [],
|
|
"annotations": [],
|
|
"description": "Name of the user, which can be the email address.",
|
|
"minimum": 8,
|
|
"maximum": 32
|
|
},
|
|
{
|
|
"name": "email",
|
|
"type": "string",
|
|
"required": true,
|
|
"attributes": [],
|
|
"annotations": [
|
|
"personal_data"
|
|
],
|
|
"description": "Email of the user.",
|
|
"minimum": 4,
|
|
"maximum": 64
|
|
},
|
|
{
|
|
"name": "status",
|
|
"type": "userStatus",
|
|
"required": true,
|
|
"attributes": [],
|
|
"annotations": [],
|
|
"description": "Status of the user as described in the user_status enum."
|
|
},
|
|
{
|
|
"name": "roles",
|
|
"type": "[role]",
|
|
"required": true,
|
|
"attributes": [],
|
|
"annotations": [],
|
|
"description": "Roles assigned to the user."
|
|
}
|
|
],
|
|
"attributes": [],
|
|
"interfaces": [],
|
|
"description": "A user defined by an id and an username."
|
|
}
|
|
],
|
|
enums: [
|
|
{
|
|
"name": "userStatus",
|
|
"plural": "userStatuses",
|
|
"values": [
|
|
{
|
|
"name": "active",
|
|
"attributes": [],
|
|
"description": "User is active and has access to the system."
|
|
},
|
|
{
|
|
"name": "inactive",
|
|
"attributes": [],
|
|
"description": "User is not active and has no access to the system."
|
|
},
|
|
{
|
|
"name": "created",
|
|
"attributes": [],
|
|
"description": "User is created but not has not yet access to the system."
|
|
},
|
|
{
|
|
"name": "deleted",
|
|
"attributes": [],
|
|
"description": "User is deleted and can not access the system. Deleted user will stay in the system for a while, before completely removed."
|
|
}
|
|
],
|
|
"attributes": [],
|
|
"description": "Status of a given user or user role."
|
|
}
|
|
]
|
|
}
|
|
|
|
const mappedModel = mapper.mapJavaModels(service.models, service.namespace)
|
|
|
|
console.log('Model:', mappedModel, '\n--------\n')
|
|
console.log('Fields: ', mappedModel[0].fields, '\n--------\n')
|
|
console.log('Single Field 1: ', mappedModel[0].fields[0], '\n--------\n')
|
|
console.log('Single Field 2: ', mappedModel[0].fields[3], '\n--------\n')
|
|
|
|
|
|
const mappedEnum = mapper.mapJavaEnums(service.enums, service.namespace)
|
|
|
|
console.log('Enum: ', mappedEnum, '\n--------\n')
|
|
console.log('Enum values: ', mappedEnum[0].values, '\n--------\n') |