Skip to content

Commit 9c83409

Browse files
committed
Merge branch 'master' of github.com:fmvilas/openapi3-generator
2 parents 58602ca + 21dfffd commit 9c83409

File tree

10 files changed

+29
-31
lines changed

10 files changed

+29
-31
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ Assuming we have the following OpenAPI Spec:
6060
openapi: "3.0.0"
6161
info:
6262
version: 1.0.0
63-
title: Swagger Petstore
63+
title: OpenAPI Petstore
6464
license:
6565
name: MIT
6666
servers:
67-
- url: http://petstore.swagger.io/v1
67+
- url: http://petstore.openapi.io/v1
6868
paths:
6969
/pet:
7070
get:...
@@ -108,7 +108,7 @@ In addition to that, the code generator adds a bit [more data](#data-passed-to-h
108108
#### Examples:
109109
##### Dynamically require files in JavaScript
110110
```mustache
111-
{{#each @root.swagger.endpoints}}
111+
{{#each @root.openapi.endpoints}}
112112
const {{.}} = require('./routes/{{.}}.route.js')
113113
{{/each}}
114114
```
@@ -122,8 +122,7 @@ const user = require('./routes/user.route.js')
122122
| Param | Type | Description |
123123
| --- | --- | --- |
124124
|openapi|object|The OpenAPI spec.|
125-
|swagger|object|The OpenAPI spec (convenience alias).|
126-
|swagger.endpoints| object | All first level endpoints (e.g `pet` and `user`) |
125+
|openapi.endpoints| object | All first level endpoints (e.g `pet` and `user`) |
127126

128127
### Custom handlebars helpers
129128
If your template needs Handlebars helpers, you can define them in a directory called `.helpers` inside your template.

lib/beautifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ module.exports = (openapi) => {
172172
});
173173
});
174174

175-
openapi.endpoints = _.unique(_.pluck(openapi.paths, 'endpointName'));
175+
openapi.endpoints = _.uniq(_.map(openapi.paths, 'endpointName'));
176176

177177
const commonPrefix = sharedStart(Object.keys(openapi.paths));
178178
const levels = commonPrefix.split('/').length - 1;

lib/generator.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This module generates a code skeleton for an API using OpenAPI/Swagger.
2+
* This module generates a code skeleton for an API using OpenAPI.
33
* @module codegen
44
*/
55

@@ -74,7 +74,7 @@ const generateOperationFile = (config, operation, operation_name) => new Promise
7474
closebrace: '}' ,
7575
operation_name: operation_name.replace(/[}{]/g, ''),
7676
operation,
77-
swagger: config.data.swagger
77+
openapi: config.data.openapi
7878
});
7979

8080
fs.writeFile(target_file, content, 'utf8', (err) => {
@@ -92,7 +92,7 @@ const generateOperationFile = (config, operation, operation_name) => new Promise
9292
*/
9393
const generateOperationFiles = config => new Promise((resolve, reject) => {
9494
const files = {};
95-
_.each(config.data.swagger.paths, (path, path_name) => {
95+
_.each(config.data.openapi.paths, (path, path_name) => {
9696
const operation_name = path.endpointName;
9797
if (files[operation_name] === undefined) {
9898
files[operation_name] = [];
@@ -118,7 +118,7 @@ const generateOperationFiles = config => new Promise((resolve, reject) => {
118118
*
119119
* @private
120120
* @param {Object} config Configuration options
121-
* @param {Object|String} config.swagger Swagger JSON or a string pointing to a Swagger file.
121+
* @param {Object|String} config.openapi OpenAPI JSON or a string pointing to a OpenAPI file.
122122
* @param {String} config.target_dir Absolute path to the directory where the files will be generated.
123123
* @param {String} config.templates Absolute path to the templates that should be used.
124124
* @return {Promise}
@@ -136,7 +136,7 @@ const generateDirectoryStructure = config => new Promise((resolve, reject) => {
136136
walker.on('file', async (root, stats, next) => {
137137
try {
138138
if (stats.name.includes('$$path$$')) {
139-
// this file should be handled for each in swagger.paths
139+
// this file should be handled for each in openapi.paths
140140
await generateOperationFiles({
141141
root,
142142
templates_dir,
@@ -269,11 +269,11 @@ const bundle = async (openapi, baseDir) => {
269269
};
270270

271271
/**
272-
* Generates a code skeleton for an API given an OpenAPI/Swagger file.
272+
* Generates a code skeleton for an API given an OpenAPI file.
273273
*
274274
* @module codegen.generate
275275
* @param {Object} config Configuration options
276-
* @param {Object|String} config.openapi OpenAPI/Swagger JSON or a string pointing to an OpenAPI/Swagger file.
276+
* @param {Object|String} config.openapi OpenAPI JSON or a string pointing to an OpenAPI file.
277277
* @param {String} config.target_dir Path to the directory where the files will be generated.
278278
* @return {Promise}
279279
*/
@@ -299,7 +299,6 @@ codegen.generate = config => new Promise((resolve, reject) => {
299299
templates: path.resolve(__dirname, '../templates')
300300
});
301301

302-
config.swagger = config.openapi;
303302
config.templates = `${config.templates}/${config.template}`;
304303

305304
async function start () {

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "openapi3-generator",
33
"main": "./lib/generator.js",
4-
"version": "0.6.1",
4+
"version": "0.7.0",
55
"description": "Use your API OpenAPI 3 definition to generate code, documentation, and literally anything you need.",
66
"bin": {
77
"og": "./cli.js",
@@ -51,7 +51,7 @@
5151
"handlebars": "^4.0.4",
5252
"js-yaml": "^3.10.0",
5353
"json-schema-ref-parser": "^4.0.4",
54-
"lodash": "3.10.1",
54+
"lodash": "^4.17.11",
5555
"markdown-it": "^8.4.2",
5656
"oas-validator": "^1.1.7",
5757
"openapi-sampler": "^1.0.0-beta.13",

templates/express/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# {{swagger.info.title}}
1+
# {{openapi.info.title}}
22

3-
{{swagger.info.description}}
3+
{{openapi.info.description}}

templates/express/config/common.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defaults: &defaults
33
port: 3000
44

55
logger:
6-
name: {{swagger.info.title}}
6+
name: {{openapi.info.title}}
77
level: debug
88
levels:
99
trace:

templates/express/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "{{package.name}}",
3-
"description": "{{inline swagger.info.description}}",
4-
"version": "{{swagger.info.version}}",
3+
"description": "{{inline openapi.info.description}}",
4+
"version": "{{openapi.info.version}}",
55
"scripts": {
66
"start": "node src/bin/www",
77
"dev": "node src/bin/www | bunyan"

templates/express/src/api/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ app.use(cookieParser());
1414
/*
1515
* Routes
1616
*/
17-
{{#each @root.swagger.endpoints}}
18-
{{#endsWith @root.swagger.basePath '/'}}
19-
app.use('{{@root.swagger.basePath}}{{..}}', require('./routes/{{..}}'));
17+
{{#each @root.openapi.endpoints}}
18+
{{#endsWith @root.openapi.basePath '/'}}
19+
app.use('{{@root.openapi.basePath}}{{..}}', require('./routes/{{..}}'));
2020
{{else}}
21-
app.use('{{@root.swagger.basePath}}/{{..}}', require('./routes/{{..}}'));
21+
app.use('{{@root.openapi.basePath}}/{{..}}', require('./routes/{{..}}'));
2222
{{/endsWith}}
2323
{{/each}}
2424

templates/markdown/openapi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# {{swagger.info.title}}
1+
# {{openapi.info.title}}
22

3-
{{{swagger.info.descriptionAsHTML}}}
3+
{{{openapi.info.descriptionAsHTML}}}
44

55
## Table of Contents
66

0 commit comments

Comments
 (0)