From ed169bac618091f7de5df47c226e6b20142cb5d8 Mon Sep 17 00:00:00 2001 From: Semen Date: Fri, 9 Oct 2020 12:23:44 +0300 Subject: [PATCH] feat: Add anyOf and oneOf support (#86) --- hooks/04_processOneOfAnyOf.js | 62 ++++++++++ ...elFileNames.js => 05_fixModelFileNames.js} | 0 ...ageProcessor.js => 99_packageProcessor.js} | 0 package-lock.json | 112 +++++++++++------- package.json | 1 + .../java/com/asyncapi/model/$$message$$.java | 21 +++- .../java/com/asyncapi/model/$$schema$$.java | 31 +++++ 7 files changed, 184 insertions(+), 43 deletions(-) create mode 100644 hooks/04_processOneOfAnyOf.js rename hooks/{04_fixModelFileNames.js => 05_fixModelFileNames.js} (100%) rename hooks/{05_packageProcessor.js => 99_packageProcessor.js} (100%) diff --git a/hooks/04_processOneOfAnyOf.js b/hooks/04_processOneOfAnyOf.js new file mode 100644 index 000000000..64bdd4169 --- /dev/null +++ b/hooks/04_processOneOfAnyOf.js @@ -0,0 +1,62 @@ +const path = require('path'); +const _ = require('lodash'); +const replace = require('replace-in-file'); + +module.exports = { + 'generate:after': generator => { + const asyncapi = generator.asyncapi; + const messages = asyncapi.allMessages(); + const schemas = asyncapi.allSchemas(); + + let objectsRegistry = new Set(); + let interfaces = new Map(); + + let objectProcessing = (className, parameters) => { + // process only if all Schemas in Any\OneOf are not primitive type + if (parameters && parameters.every(obj => obj.type() === 'object')) { + let interfaceName = _.upperFirst(_.camelCase(className)) + '.OneOf'; + // At first collect all Schemas in Any\OneOf and build interface name + parameters.forEach(obj => { + objectsRegistry.add(obj.uid()); + interfaceName += _.upperFirst(_.camelCase(obj.uid())); + }); + // Assign interface name for each Schema in Any\OneOf + parameters.forEach(obj => { + if (interfaces.has(obj.uid())) { + if (!interfaces.get(obj.uid()).includes(interfaceName)) { + interfaces.set(obj.uid(), interfaces.get(obj.uid()) + ', ' + interfaceName); + } + } else { + interfaces.set(obj.uid(), interfaceName); + } + }); + } + } + for (let [key, value] of messages) { + objectProcessing(value.uid(), [].concat(value.payload().anyOf(), value.payload().oneOf()).filter(obj => obj != null)); + } + for (let [key, value] of schemas) { + if (value.type() === 'object') { + // To correctly resolve the name of the parent class, we have to go through the properties + Object.values(value.properties()) + .map(prop => [].concat(prop.anyOf(), prop.oneOf()) + .filter(obj => obj != null)) + .forEach(array => objectProcessing(value.uid(), array)); + } + } + + for (let [key, value] of schemas) { + if (objectsRegistry.has(value.uid()) && value.type() === 'object') { + // Update definitions of model classes + const className = _.upperFirst(_.camelCase(value.uid())); + const reg = new RegExp('public class ' + className, 'g') + const options = { + files: path.resolve(generator.targetDir, `src/main/java/com/asyncapi/model/${key}.java`), + from: reg, + to: 'public class ' + className + ' implements ' + interfaces.get(value.uid()), + }; + replace.sync(options); + } + } + } +}; \ No newline at end of file diff --git a/hooks/04_fixModelFileNames.js b/hooks/05_fixModelFileNames.js similarity index 100% rename from hooks/04_fixModelFileNames.js rename to hooks/05_fixModelFileNames.js diff --git a/hooks/05_packageProcessor.js b/hooks/99_packageProcessor.js similarity index 100% rename from hooks/05_packageProcessor.js rename to hooks/99_packageProcessor.js diff --git a/package-lock.json b/package-lock.json index 155492a0f..250f953b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -528,8 +528,7 @@ "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", - "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", - "dev": true + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" }, "@types/node": { "version": "13.9.3", @@ -612,8 +611,7 @@ "ansi-regex": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", - "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", - "dev": true + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==" }, "ansi-styles": { "version": "3.2.1", @@ -771,7 +769,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", - "dev": true, "requires": { "string-width": "^4.2.0", "strip-ansi": "^6.0.0", @@ -978,8 +975,7 @@ "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", - "dev": true + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" }, "decamelize-keys": { "version": "1.1.0", @@ -1049,8 +1045,7 @@ "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "end-of-stream": { "version": "1.4.4", @@ -1322,8 +1317,7 @@ "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "dev": true + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" }, "get-stream": { "version": "4.1.0", @@ -1551,8 +1545,7 @@ "is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" }, "is-glob": { "version": "4.0.1", @@ -5893,17 +5886,70 @@ "rc": "^1.2.8" } }, + "replace-in-file": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/replace-in-file/-/replace-in-file-6.1.0.tgz", + "integrity": "sha512-URzjyF3nucvejuY13HFd7O+Q6tFJRLKGHLYVvSh+LiZj3gFXzSYGnIkQflnJJulCAI2/RTZaZkpOtdVdW0EhQA==", + "requires": { + "chalk": "^4.0.0", + "glob": "^7.1.6", + "yargs": "^15.3.1" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", - "dev": true + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" }, "require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", - "dev": true + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" }, "resolve": { "version": "1.15.1", @@ -6214,8 +6260,7 @@ "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "dev": true + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, "shebang-command": { "version": "1.2.0", @@ -6359,7 +6404,6 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==", - "dev": true, "requires": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -6379,7 +6423,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", "integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==", - "dev": true, "requires": { "ansi-regex": "^5.0.0" } @@ -6635,8 +6678,7 @@ "which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", - "dev": true + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, "windows-release": { "version": "3.2.0", @@ -6657,7 +6699,6 @@ "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", - "dev": true, "requires": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", @@ -6668,7 +6709,6 @@ "version": "4.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", - "dev": true, "requires": { "@types/color-name": "^1.1.1", "color-convert": "^2.0.1" @@ -6678,7 +6718,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "requires": { "color-name": "~1.1.4" } @@ -6686,8 +6725,7 @@ "color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" } } }, @@ -6705,8 +6743,7 @@ "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", - "dev": true + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" }, "yallist": { "version": "3.1.1", @@ -6727,7 +6764,6 @@ "version": "15.3.1", "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.3.1.tgz", "integrity": "sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA==", - "dev": true, "requires": { "cliui": "^6.0.0", "decamelize": "^1.2.0", @@ -6745,14 +6781,12 @@ "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", - "dev": true + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" }, "find-up": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "dev": true, "requires": { "locate-path": "^5.0.0", "path-exists": "^4.0.0" @@ -6762,7 +6796,6 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "dev": true, "requires": { "p-locate": "^4.1.0" } @@ -6771,7 +6804,6 @@ "version": "2.2.2", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.2.tgz", "integrity": "sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ==", - "dev": true, "requires": { "p-try": "^2.0.0" } @@ -6780,7 +6812,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "dev": true, "requires": { "p-limit": "^2.2.0" } @@ -6788,20 +6819,17 @@ "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==" }, "yargs-parser": { "version": "18.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.1.tgz", "integrity": "sha512-KRHEsOM16IX7XuLnMOqImcPNbLVXMNHYAoFc3BKR8Ortl5gzDbtXvvEoGx9imk5E+X1VeNKNlcHr8B8vi+7ipA==", - "dev": true, "requires": { "camelcase": "^5.0.0", "decamelize": "^1.2.0" diff --git a/package.json b/package.json index 3c0fe5ad1..049520070 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@asyncapi/generator-hooks": "^0.1.0", "fs-extra": "^9.0.0", "lodash": "^4.17.15", + "replace-in-file": "^6.1.0", "tmp": "^0.2.1" }, "devDependencies": { diff --git a/template/src/main/java/com/asyncapi/model/$$message$$.java b/template/src/main/java/com/asyncapi/model/$$message$$.java index 0391ec003..c2349ed93 100644 --- a/template/src/main/java/com/asyncapi/model/$$message$$.java +++ b/template/src/main/java/com/asyncapi/model/$$message$$.java @@ -7,7 +7,26 @@ * Examples: {{message.examples() | examplesToString | safe}}{% endif %} */{% endif %} public class {{messageName | camelCase | upperFirst}} { - {% set payloadName = message.payload().uid() | camelCase | upperFirst %} + {%- if message.payload().anyOf() or message.payload().oneOf() %} + {%- set payloadName = 'OneOf' %}{%- set hasPrimitive = false %} + {%- for obj in message.payload().anyOf() %} + {%- set hasPrimitive = hasPrimitive or obj.type() !== 'object' %} + {%- set payloadName = payloadName + obj.uid() | camelCase | upperFirst %} + {%- endfor %} + {%- for obj in message.payload().oneOf() %} + {%- set hasPrimitive = hasPrimitive or obj.type() !== 'object' %} + {%- set payloadName = payloadName + obj.uid() | camelCase | upperFirst %} + {%- endfor %} + {%- if hasPrimitive %} + {%- set payloadName = 'Object' %} + {%- else %} + public interface {{payloadName}} { + + } + {%- endif %} + {%- else %} + {%- set payloadName = message.payload().uid() | camelCase | upperFirst %} + {%- endif %} private {{payloadName}} payload; public {{payloadName}} getPayload() { diff --git a/template/src/main/java/com/asyncapi/model/$$schema$$.java b/template/src/main/java/com/asyncapi/model/$$schema$$.java index c724b97fe..04b56686c 100644 --- a/template/src/main/java/com/asyncapi/model/$$schema$$.java +++ b/template/src/main/java/com/asyncapi/model/$$schema$$.java @@ -61,6 +61,24 @@ public String toString() { } private @Valid {{propName | camelCase | upperFirst}}Enum {{propName | camelCase}}; + {%- elif prop.anyOf() or prop.oneOf() %} + {%- set propType = 'OneOf' %}{%- set hasPrimitive = false %} + {%- for obj in prop.anyOf() %} + {%- set hasPrimitive = hasPrimitive or obj.type() !== 'object' %} + {%- set propType = propType + obj.uid() | camelCase | upperFirst %} + {%- endfor %} + {%- for obj in prop.oneOf() %} + {%- set hasPrimitive = hasPrimitive or obj.type() !== 'object' %} + {%- set propType = propType + obj.uid() | camelCase | upperFirst %} + {%- endfor %} + {%- if hasPrimitive %} + {%- set propType = 'Object' %} + {%- else %} + public interface {{propType}} { + + } + {%- endif %} + private @Valid {{propType}} {{propName | camelCase}}; {%- else %} {%- if prop.format() %} private @Valid {{prop.format() | toJavaType}} {{propName | camelCase}}; @@ -84,6 +102,19 @@ public String toString() { {%- endif %} {%- elif prop.enum() and (prop.type() === 'string' or prop.type() === 'integer') %} {%- set propType = (propName | camelCase | upperFirst) + 'Enum' %} + {%- elif prop.anyOf() or prop.oneOf() %} + {%- set propType = 'OneOf' %}{%- set hasPrimitive = false %} + {%- for obj in prop.anyOf() %} + {%- set hasPrimitive = hasPrimitive or obj.type() !== 'object' %} + {%- set propType = propType + obj.uid() | camelCase | upperFirst %} + {%- endfor %} + {%- for obj in prop.oneOf() %} + {%- set hasPrimitive = hasPrimitive or obj.type() !== 'object' %} + {%- set propType = propType + obj.uid() | camelCase | upperFirst %} + {%- endfor %} + {%- if hasPrimitive %} + {%- set propType = 'Object' %} + {%- endif %} {%- else %} {%- if prop.format() %} {%- set propType = prop.format() | toJavaType %}