added Java enums
This commit is contained in:
parent
2f11022c90
commit
a4f1227c0d
|
@ -23,5 +23,19 @@ module.exports = {
|
|||
|
||||
return model
|
||||
})
|
||||
},
|
||||
|
||||
mapJavaEnums: (enums, namespace) => {
|
||||
return enums.map(e => {
|
||||
e['values'][ e['values'].length - 1 ].last = true;
|
||||
e.name = utils.pascalcase(e.name)
|
||||
e.package = `${namespace}.models`
|
||||
e.values = e.values.map(value => {
|
||||
value.value = value.value || value.name
|
||||
value.name = value.name.toUpperCase()
|
||||
return value
|
||||
})
|
||||
return e
|
||||
})
|
||||
}
|
||||
}
|
|
@ -60,12 +60,48 @@ const service = {
|
|||
"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 mapped = mapper.mapJavaModels(service.models, service.namespace)
|
||||
const mappedModel = mapper.mapJavaModels(service.models, service.namespace)
|
||||
|
||||
console.log(mapped)
|
||||
console.log(mapped[0].fields)
|
||||
console.log(mapped[0].fields[0])
|
||||
console.log(mapped[0].fields[3])
|
||||
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')
|
Loading…
Reference in a new issue