Skip to content

Commit

Permalink
Merge pull request #159 from swisspush/develop
Browse files Browse the repository at this point in the history
Release 0.9.15
  • Loading branch information
lbovet authored Nov 6, 2020
2 parents 04a0b36 + 427f7c9 commit 3cdda62
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/
*.tgz
test/dist/
generated-logo.js
/default-types.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apikana",
"version": "0.9.14",
"version": "0.9.15",
"description": "Integrated tools for REST API design - アピ",
"main": "index.js",
"bin": {
Expand Down
7 changes: 4 additions & 3 deletions src/generate-avro.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = function() {
return new_obj
};

jsonSchemaAvro.convert = async (schema, recordSuffix, splitIdForMain, enumSuffix) => {
jsonSchemaAvro.convert = async (schema, recordSuffix, splitIdForMain, enumSuffix, config) => {
if (!schema) {
throw new Error('No schema given')
}
Expand All @@ -93,6 +93,7 @@ module.exports = function() {
enumSuffix = '_enum';
}

jsonSchemaAvro._config = config || {};
jsonSchemaAvro._splitIdForMain = splitIdForMain;
jsonSchemaAvro._enumSuffix = enumSuffix;
jsonSchemaAvro._globalTypesCache = new Map();
Expand Down Expand Up @@ -200,7 +201,7 @@ module.exports = function() {
return jsonSchemaAvro._convertArrayProperty(item, schema[item], jsonSchemaAvro._isRequired(required, item))
}
else if (jsonSchemaAvro._hasEnum(schema[item])) {
return jsonSchemaAvro._convertEnumProperty(item, schema[item], jsonSchemaAvro._isRequired(required, item))
return jsonSchemaAvro._convertEnumProperty(item, schema[item], schema[item].description, jsonSchemaAvro._isRequired(required, item))
}
else if (jsonSchemaAvro._isCombinationOf(schema[item])) {
return jsonSchemaAvro._convertCombinationOfProperty(item, schema[item])
Expand Down Expand Up @@ -375,7 +376,7 @@ module.exports = function() {
doc: doc || contents.description || '',
};

if (valid) {
if ( !jsonSchemaAvro._config.enumAsString && valid) {
var enumName = contents.id || `${name}${jsonSchemaAvro._enumSuffix}`;
if(enums[enumName] && sameArray(contents.enum, enums[enumName])) {
enumProp.type = enumName;
Expand Down
3 changes: 2 additions & 1 deletion src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ module.exports = {
fs.writeFileSync(path.resolve(jsonSchemaOutputDir, fileName + '.json'), JSON.stringify(fullSchema, 6, 2));
var avroOutputDir = path.resolve(dest, 'model/avro-full')
fse.mkdirsSync(avroOutputDir);
return jsonSchemaAvro().convert(fullSchema).then(avroSchema =>
var avroConfig = generateEnv.variables().customConfig.avro;
return jsonSchemaAvro().convert(fullSchema, undefined, undefined, undefined, avroConfig).then(avroSchema =>
fs.writeFileSync(path.resolve(avroOutputDir, fileName + '.avsc'), JSON.stringify(avroSchema, 6, 2)));
});

Expand Down
1 change: 1 addition & 0 deletions src/plopfile_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ module.exports = function (plop, cfg) {
actions: (answers) => {
answers.customConfig = Object.assign({}, answers);
delete answers.customConfig.npmPackage;
answers.customConfig.avro = { enumAsString: true }
var actions = [];

var summary = Object.entries({
Expand Down

0 comments on commit 3cdda62

Please sign in to comment.