Skip to content

Commit 164f693

Browse files
Release v0.11.2 to latest (#223)
2 parents e9617d1 + d9f9d1e commit 164f693

File tree

3 files changed

+62
-60
lines changed

3 files changed

+62
-60
lines changed

bin/apikana

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var argc = process.argv.length;
1111

1212
require('../src/logo');
1313

14-
if(!process.version.startsWith('v8') && !process.version.startsWith('v10')) {
14+
if (!process.version.startsWith('v8') && !process.version.startsWith('v10')) {
1515
log(colors.bold(colors.red('Expected node version v8.x or v10.x but current version is ' + process.version)));
1616
process.exit(1);
1717
}
@@ -25,26 +25,26 @@ if (argc === 2) {
2525
process.exit(1);
2626
}
2727
switch (process.argv[2]) {
28-
case 'init':
29-
require('../src/init/init');
30-
break;
31-
case 'start':
32-
generate();
33-
break;
34-
case 'stop':
35-
require('../src/server/stop').stop(params.port(), function () {
36-
log('Stopped');
37-
});
38-
break;
39-
case 'create-sample':
40-
createSample();
41-
break;
42-
case 'validate-samples':
43-
validateSamples();
44-
break;
45-
default:
46-
help();
47-
break;
28+
case 'init':
29+
require('../src/init/init');
30+
break;
31+
case 'start':
32+
generate();
33+
break;
34+
case 'stop':
35+
require('../src/server/stop').stop(params.port(), function () {
36+
log('Stopped');
37+
});
38+
break;
39+
case 'create-sample':
40+
createSample();
41+
break;
42+
case 'validate-samples':
43+
validateSamples();
44+
break;
45+
default:
46+
help();
47+
break;
4848
}
4949
}
5050

@@ -55,30 +55,30 @@ function help() {
5555
log(' source', ' Directory containing the APIs and models. Default: src');
5656
log(colors.gray(' --api=<file>'), ' The main api file (yaml or json). Default: openapi/api.yaml');
5757
log(colors.gray(' --models=<path>'), ' The directory containing the models, if no api file is given.\n' +
58-
' Default: ts');
58+
' Default: ts');
5959
log(colors.gray(' --style=<path>'), ' The directory containing css files for the swagger GUI.\n' +
60-
' Default: style');
60+
' Default: style');
6161
log(colors.gray(' --config=<file>'), ' Read additional options from a file in JSON format.');
6262
log(colors.gray(' --javaPackage=<name>'), ' Java package to use.');
63-
log(colors.gray(' --pathPrefix=<prefix>'), ' The common prefix for api paths to be used in generated *Paths files.\n'+
64-
' Default: none');
63+
log(colors.gray(' --pathPrefix=<prefix>'), ' The common prefix for api paths to be used in generated *Paths files.\n' +
64+
' Default: none');
6565
log(colors.gray(' --basePath=<path>'), ' Override basePath specified in api file');
66-
log(colors.gray(' --generate1stGenPaths=<boolean>'),'\n' +
67-
' Enable/disable generator for 1st generation path constants.\n' +
68-
' Since: v0.5.1\n' +
69-
' Default: true (enabled)');
70-
log(colors.gray(' --generate2ndGenPaths=<boolean>'),'\n' +
71-
' Enable/disable generator for 2nd generation path constants.\n' +
72-
' Since: v0.5.1\n' +
73-
' Default: true (enabled)');
74-
log(colors.gray(' --generate3rdGenPaths=<boolean>'),'\n' +
75-
' Enable/disable generator for 3rd generation path constants.\n' +
76-
' Since: v0.5.0\n' +
77-
' Default: false (disabled)');
78-
log(colors.gray(' --deploy=<boolean>'), ' If the sources should be copied into the target directory. \n'+
79-
' Default: false');
80-
log(colors.gray(' --dependencyPath=<path>'), ' Directory containing API dependencies.\n'+
81-
' Default: node_modules/-api-dependencies');
66+
log(colors.gray(' --generate1stGenPaths=<boolean>'), '\n' +
67+
' Enable/disable generator for 1st generation path constants.\n' +
68+
' Since: v0.5.1\n' +
69+
' Default: true (enabled)');
70+
log(colors.gray(' --generate2ndGenPaths=<boolean>'), '\n' +
71+
' Enable/disable generator for 2nd generation path constants.\n' +
72+
' Since: v0.5.1\n' +
73+
' Default: true (enabled)');
74+
log(colors.gray(' --generate3rdGenPaths=<boolean>'), '\n' +
75+
' Enable/disable generator for 3rd generation path constants.\n' +
76+
' Since: v0.5.0\n' +
77+
' Default: false (disabled)');
78+
log(colors.gray(' --deploy=<boolean>'), ' If the sources should be copied into the target directory. \n' +
79+
' Default: false');
80+
log(colors.gray(' --dependencyPath=<path>'), ' Directory containing API dependencies.\n' +
81+
' Default: node_modules/-api-dependencies');
8282
log(colors.gray(' --port=<number>'), ' Port to serve the HTML documentation. Default: 8333');
8383
log(colors.gray(' --serve=<boolean>'), ' If the HTML documentation should be served over HTTP. Default: true');
8484
log(colors.gray(' --openBrowser=<boolean>'), ' If the browser should be opened at first start. Default: true');
@@ -130,23 +130,25 @@ function generate() {
130130
});
131131

132132
function run(defaults) {
133-
var plop = nodePlop(__dirname + '/../src/plopfile_start.js', { defaults });
133+
var plop = nodePlop(__dirname + '/../src/plopfile_start.js', {defaults});
134134
var generator = plop.getGenerator('start');
135-
const model = Object.assign({}, packageJSON, { api: openapi });
136-
137-
// Workaround for validatorjs to fix wildcard on `paths`
138-
const paths = [];
139-
Object.values(model.api.paths).forEach(path => paths.push(path));
140-
model.api.paths = paths;
135+
const model = Object.assign({}, packageJSON, {api: openapi});
141136

142137
if (defaults.validation) {
143-
const Validator = require('validatorjs')
144-
const validator = new Validator(model.api, defaults.validation);
145-
if(!validator.check()) {
146-
log(colors.bold(colors.red('Validation of the OpenAPI definition has failed with ' + validator.errorCount + ' errors')));
138+
139+
// Workaround for validatorjs to validate also 'paths' with wildcard
140+
var openapiToValidate = JSON.parse(JSON.stringify(openapi));
141+
openapiToValidate.paths = Object.values(openapiToValidate.paths);
142+
143+
const Validator = require('validatorjs');
144+
145+
const validator = new Validator(openapiToValidate, defaults.validation);
146+
if (!validator.check()) {
147+
log(colors.bold(colors.red('Validation of the OpenAPI (api.yaml) has failed with ' + validator.errorCount + ' error(s).')));
148+
log(colors.bold(colors.red('Validation rules your API must conform are defined in: ' + path.join(defaults.dir, 'index.js'))));
147149
Object.entries(validator.errors.all()).forEach(errorEntry => {
148-
const [errorField, error] = errorEntry;
149-
log(colors.bold(colors.red(errorField + ": " + error)))
150+
const [errorField, error] = errorEntry;
151+
log(colors.bold(colors.red(errorField + ": " + error)))
150152
});
151153
process.exit(1);
152154
}
@@ -160,7 +162,7 @@ function generate() {
160162
var defaultsVersion = packageJSON.devDependencies['apikana-defaults'];
161163

162164
if (defaultsVersion) {
163-
if(defaultsVersion != "0.0.0") {
165+
if (defaultsVersion != "0.0.0") {
164166
process.stdout.write("Using defaults " + defaultsVersion + "\n");
165167
}
166168
var defaultsDir = path.join(process.cwd(), 'node_modules', 'apikana-defaults');
@@ -170,12 +172,12 @@ function generate() {
170172
} else {
171173
process.stdout.write("Loading defaults... ");
172174
manager.install('apikana-defaults').then((e) => {
173-
process.stdout.write("found "+e.version+"\n");
175+
process.stdout.write("found " + e.version + "\n");
174176
var defaults = manager.require('apikana-defaults');
175177
var defaultsDir = path.join(os.tmpdir(), 'apikana-plugin-packages', 'apikana-defaults');
176178
defaults.dir = defaultsDir;
177179
var version = JSON.parse(fs.readFileSync(path.join(defaultsDir, 'package.json'))).version;
178-
if(version != "0.0.0") {
180+
if (version != "0.0.0") {
179181
log(colors.bold(`WARNING: | The build is unpredictable because of an implicit dependency.`));
180182
log(colors.bold(` | It may break anytime when a new version of the dependency is available in the registry.`));
181183
log(colors.bold(` | To fix this, freeze the dependency in your API project:`));

npm-shrinkwrap.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apikana",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
44
"description": "Integrated tools for REST API design - アピ",
55
"main": "index.js",
66
"bin": {

0 commit comments

Comments
 (0)