diff --git a/src/generators/java-axon-events-generator.js b/src/generators/java-axon-events-generator.js index c7dca54..d375f2a 100644 --- a/src/generators/java-axon-events-generator.js +++ b/src/generators/java-axon-events-generator.js @@ -1,13 +1,16 @@ const javaModels = require('../java-model') +const javaUnions = require('../java-unions') const javaType = require('../java-type') const Mustache = require('mustache') const fs = require('fs') const path = require('path') const templateModel = fs.readFileSync(path.resolve(path.join('templates', 'axon-event.java.mustache')), 'utf-8') +const templateUnion = fs.readFileSync(path.resolve(path.join('templates', 'union.java.mustache')), 'utf-8') module.exports = (service) => { + const unions = javaUnions.mapUnions(service.unions, service.models, service.namespace) let models = service.models.map(model => { let aggregateAttribute = (model.attributes.find(attr => attr.name === 'aggregateId') || { value: {} }).value let aggregateId = {} @@ -27,7 +30,17 @@ module.exports = (service) => { contents: Mustache.render(templateModel, { service, ...model }) } }) - return modelFiles + const unionFiles = unions.map(union => { + return { + name: `${union.name}.java`, + dir: union.dir, + contents: Mustache.render(templateUnion, { service, ...e }) + } + }) + return [ + ...modelFiles, + ...unionFiles + ] } \ No newline at end of file diff --git a/src/generators/java-models-generator.js b/src/generators/java-models-generator.js index 7d0faa1..fcc55d3 100644 --- a/src/generators/java-models-generator.js +++ b/src/generators/java-models-generator.js @@ -1,13 +1,16 @@ const javaModels = require('../java-model') +const javaUnions = require('../java-unions') const Mustache = require('mustache') const fs = require('fs') const path = require('path') const templateModel = fs.readFileSync(path.resolve(path.join('templates', 'lombok-model.java.mustache')), 'utf-8') const templateEnum = fs.readFileSync(path.resolve(path.join('templates', 'lombok-enum.java.mustache')), 'utf-8') +const templateUnion = fs.readFileSync(path.resolve(path.join('templates', 'union.java.mustache')), 'utf-8') module.exports = (service) => { + const unions = javaUnions.mapUnions(service.unions, service.models, service.namespace) const models = javaModels.mapJavaModels(service.models, service.namespace) const enums = javaModels.mapJavaEnums(service.enums, service.namespace) @@ -25,9 +28,17 @@ module.exports = (service) => { contents: Mustache.render(templateEnum, { service, ...e }) } }) + const unionFiles = unions.map(union => { + return { + name: `${union.name}.java`, + dir: union.dir, + contents: Mustache.render(templateUnion, { service, ...e }) + } + }) return [ ...modelFiles, - ...enumFiles + ...enumFiles, + ...unionFiles ] diff --git a/src/java-unions.js b/src/java-unions.js index d7ef397..b6a0da0 100644 --- a/src/java-unions.js +++ b/src/java-unions.js @@ -8,6 +8,7 @@ module.exports = { return unions.map(union => { union.package = `${namespace}.${suffix}` union.name = utils.pascalcase(union.name) + union.dir = union.package.replace(/\./g, '/') union.types.forEach(type => { models.forEach(model => { diff --git a/templates/axon-event.java.mustache b/templates/axon-event.java.mustache index b2b8b12..7076249 100644 --- a/templates/axon-event.java.mustache +++ b/templates/axon-event.java.mustache @@ -20,7 +20,7 @@ import lombok.*; @Data @NoArgsConstructor @AllArgsConstructor -public class {{name}} {{#implements.length}}implements {{#implements}}.{{/implements}}{{/implement.length}} { +public class {{name}} {{#implements.length}}implements {{#implements}}.{{/implements}}{{/implements.length}} { @TargetAggregateIdentifier private {{{aggregateId.type.name}}} {{aggregateId.name}}; diff --git a/templates/lombok-model.java.mustache b/templates/lombok-model.java.mustache index 63014f7..0cc7497 100644 --- a/templates/lombok-model.java.mustache +++ b/templates/lombok-model.java.mustache @@ -21,13 +21,13 @@ import {{{.}}}; {{/imports}} /** - * {{model.description}} + * {{description}} * See https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}#model-{{model.name}} * **/ @Data @NoArgsConstructor -public class {{name}} {{#implements.length}}implements {{#implements}}.{{/implements}}{{/implement.length}}{ +public class {{name}} {{#implements.length}}implements {{#implements}}.{{/implements}}{{/implements.length}}{ {{#fields}} {{#description}}/** {{.}} **/{{/description}} diff --git a/templates/union.java.mustache b/templates/union.java.mustache new file mode 100644 index 0000000..d6d3ed1 --- /dev/null +++ b/templates/union.java.mustache @@ -0,0 +1,20 @@ +/** + * Auto-generated from apibuilder.io service specification. + * apidoc-version : {{service.apidoc.version}} + * organisation : {{service.organization.key}} + * service-version : {{service.version}} + * + * Documentation at: + * https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}} + * +**/ +package {{package}}; + +/** + * {{description}} + * See https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}#model-{{model.name}} + * +**/ +public interface {{name}} { + +} \ No newline at end of file