From 53de0174a93894507a924cc17c45123cdb8cd92e Mon Sep 17 00:00:00 2001 From: Semen Date: Wed, 17 Jun 2020 14:20:30 +0300 Subject: [PATCH] fix: remove non-object generated classes (#62) --- ...rseOperations.js => 01_inverseOperations.js} | 0 ...antParts.js => 02_removeNotRelevantParts.js} | 0 hooks/03_removeNonObjectSchemas.js | 17 +++++++++++++++++ ...odelFileNames.js => 04_fixModelFileNames.js} | 2 +- ...ckageProcessor.js => 05_packageProcessor.js} | 0 5 files changed, 18 insertions(+), 1 deletion(-) rename hooks/{inverseOperations.js => 01_inverseOperations.js} (100%) rename hooks/{removeNotRelevantParts.js => 02_removeNotRelevantParts.js} (100%) create mode 100644 hooks/03_removeNonObjectSchemas.js rename hooks/{fixModelFileNames.js => 04_fixModelFileNames.js} (92%) rename hooks/{packageProcessor.js => 05_packageProcessor.js} (100%) diff --git a/hooks/inverseOperations.js b/hooks/01_inverseOperations.js similarity index 100% rename from hooks/inverseOperations.js rename to hooks/01_inverseOperations.js diff --git a/hooks/removeNotRelevantParts.js b/hooks/02_removeNotRelevantParts.js similarity index 100% rename from hooks/removeNotRelevantParts.js rename to hooks/02_removeNotRelevantParts.js diff --git a/hooks/03_removeNonObjectSchemas.js b/hooks/03_removeNonObjectSchemas.js new file mode 100644 index 000000000..52a4ff234 --- /dev/null +++ b/hooks/03_removeNonObjectSchemas.js @@ -0,0 +1,17 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = { + 'generate:after': generator => { + const asyncapi = generator.asyncapi; + const schemas = asyncapi.allSchemas(); + + for (let [key, value] of schemas) { + if (value.type() !== 'object') { + try { + fs.unlinkSync(path.resolve(generator.targetDir, `src/main/java/com/asyncapi/model/${key}.java`)); + } catch (e) {} + } + } + } +}; \ No newline at end of file diff --git a/hooks/fixModelFileNames.js b/hooks/04_fixModelFileNames.js similarity index 92% rename from hooks/fixModelFileNames.js rename to hooks/04_fixModelFileNames.js index b6a3cf719..e412db254 100644 --- a/hooks/fixModelFileNames.js +++ b/hooks/04_fixModelFileNames.js @@ -15,7 +15,7 @@ module.exports = { } } for (let [key, value] of schemas) { - if (_.upperFirst(key) !== key) { + if (_.upperFirst(key) !== key && value.type() === 'object') { fs.renameSync(path.resolve(generator.targetDir, `src/main/java/com/asyncapi/model/${key}.java`), path.resolve(generator.targetDir, `src/main/java/com/asyncapi/model/${_.upperFirst(key)}.java`)); } diff --git a/hooks/packageProcessor.js b/hooks/05_packageProcessor.js similarity index 100% rename from hooks/packageProcessor.js rename to hooks/05_packageProcessor.js