openapi-contrib / openapi3-generator Goto Github PK
View Code? Open in Web Editor NEWUse your API OpenAPI 3 definition to generate code, documentation, and literally anything you need.
License: Apache License 2.0
Use your API OpenAPI 3 definition to generate code, documentation, and literally anything you need.
License: Apache License 2.0
Aaww ๐ฉ. Something went wrong:
Error: Lexical error on line 1. Unrecognized text.
Bud1
^
at Parser.parseError (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:268:19)
at Object.parseError (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:395:36)
at Object.next (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:523:33)
at Object.lex (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:527:30)
at lex (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:298:36)
at Parser.parse (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:321:34)
at HandlebarsEnvironment.parse (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/base.js:46:43)
at compileInput (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:515:19)
at ret (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:524:18)
at fs.readFile (/Users/phil.sturgeon/src/we-sdk-generator/node_modules/openapi3-generator/lib/generator.js:46:30)
Love the poop emoji, but I need to know what went wrong, and where.
The # ref are all generated inline in a table when it should be generated separately as their own tables. I have attached the openAPI json file and the generated markdown for your reference.
Also the the hyperlinks generated from the #ref are empty
openapi.zip
Currently, the generator creates one file per top-level path component -- that is, if you have paths a/b/c
and a/d/e
[1] and a path template named routes/$$path$$/route.js.hbs
it only creates one file routes/a/route.js
. I'd like it to create a/b/c.js
or optionally a_b_c.js
(assuming I change the path template to routes/$$path$$.js
), so I can create path-specific scripts for testing purposes.
We don't get parameters example in the Markdown template. That'd be very useful.
Hi,
I'm creating some new features to create a full functional crud-server with json data files and models from the schemas of the openapi.yaml. In Detail:
If its possible to create a new branch and open a pull request with me as contributor?
Cheers!
Best,
Matthias Suessmeier
Hi, thanks for making this generator. It's such a great idea to be able to generate from your own templates. I intend to make a "partial" application template which fits into an existing server application, so that I can re-generate (just controllers and a sub-router) freely without having to edit any boilerplate to integrate each version.
I have copied your example "express" template into my application (without making any changes yet), but when I use the "t" parameter to use this copy I get a missing handlebars helper error.
It begins the generation process, makes the folder structure and the readme with my API name, and the editor files, but nothing else. So it's reading my yaml, and finding the templates OK.
If I remove the -t param, it generates from your internal template OK. All I'm trying to do is copy the template folder to another location, and then providing the -t to that new location.
My structure is:
express/src/OAI/generator/templates/express - a copy of your "express" template
express/lib/API/ - output area
og -o express/lib/API -t express/src/OAI/generator/templates/ myapi.yaml express
Aaww ๐ฉ. Something went wrong:
Error: Missing helper: "inline"
at Object.<anonymous> (/Users/me/.nvm/versions/node/v9.4.0/lib/node_modules/openapi3-generator/node_modules/handlebars/dist/cjs/handlebars/helpers/helper-missing.js:19:13)
at Object.eval [as main] (eval at createFunctionContext (/Users/me/.nvm/versions/node/v9.4.0/lib/node_modules/openapi3-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:8:85)
at main (/Users/me/.nvm/versions/node/v9.4.0/lib/node_modules/openapi3-generator/node_modules/handlebars/dist/cjs/handlebars/runtime.js:175:32)
at ret (/Users/me/.nvm/versions/node/v9.4.0/lib/node_modules/openapi3-generator/node_modules/handlebars/dist/cjs/handlebars/runtime.js:178:12)
at ret (/Users/me/.nvm/versions/node/v9.4.0/lib/node_modules/openapi3-generator/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:526:21)
at fs.readFile (/Users/me/.nvm/versions/node/v9.4.0/lib/node_modules/openapi3-generator/lib/generator.js:43:30)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:528:3)
I can see the helper is in the templates/express/.helpers/all.js file. This is being found OK and loaded by registerHelpers()
in generator.js
.
I added a log to all.js
:
console.log("registering inline helper...");
Handlebars.registerHelper('inline', (str) => {
return str ? str.replace(/\n/g, '') : '';
});
which shows up:
og -o express/lib/API -t express/src/OAI/generator/templates/ myapi.yaml express
registering inline helper...
Aaww ๐ฉ. Something went wrong:
Error: Missing helper: "inline"
Any help would be appreciated.
There's a bug here: https://github.com/openapi-contrib/openapi3-generator/blob/0.13.0/lib/generator.js#L144-L147
Promise.all(
_.map(files, (operation, operation_name) => generateOperationFile(config, operation, operation_name))
).then(resolve).catch(reject);
resolve();
The outer promise here is being resolved before the Promise.all
has a chance to finish, and if there's a rejection, it is ignored. I was running this tool from a docker container and only 75% of the expected files were being generated. I tracked it down to errors on that line not being handled properly..... With the resolve
removed, I get the error back properly:
Error: EMFILE: too many open files, open '/api-docs/templates/my-template/$$path$$.js'
Why I'm getting that in docker and not locally is still a mystery to me... but this routine seems inefficient. As as test I logged out the name of the file that was being read here: https://github.com/openapi-contrib/openapi3-generator/blob/0.13.0/lib/generator.js#L96-L97
const generateOperationFile = (config, operation, operation_name) => new Promise((resolve, reject) => {
console.log(path.join(config.root, config.file_name))
fs.readFile(path.join(config.root, config.file_name), 'utf8', (err, data) => {
And I get the same file logged out a couple thousands times.... Because it's a Promise.all I imagine node will try to load all of them at the same time, and I'm guessing in my particular case, there's not enough file descriptors available and it blows up.... Further, I logged out the file path that it writes in this routine, and it's writing out the same file multiple times.... Seems like the data structure being passed generated / passed in there could do with a Sets instead to avoid duplicates?
If the project path contains special characters, the code for creating the target_file
path in generator.js (line 100 and following) doesn't work as intended.
e.g. if the paths look like this:
template path: /some+dir/project/templates/some-file
templates root: /some+dir/project/templates
the replacement of /some+dir/project/templates
in the template file path doesn't work, because the +
is interpreted as a regular expression instruction.
I think all special chars for regular expressions should be escaped here.
Command:
node cli.js tests/openapi3/api-with-examples.yaml markdown
results in:
TypeError: Cannot read property 'allOf' of undefined
at resolveAllOf (/Users/d.pitard/workspace/openapi3-generator/lib/beautifier.js:17:14)
at beautifySchema (/Users/d.pitard/workspace/openapi3-generator/lib/beautifier.js:54:3)
at _.each (/Users/d.pitard/workspace/openapi3-generator/lib/beautifier.js:104:11)
at /Users/d.pitard/workspace/openapi3-generator/node_modules/lodash/lodash.js:4911:15
at baseForOwn (/Users/d.pitard/workspace/openapi3-generator/node_modules/lodash/lodash.js:2996:24)
at /Users/d.pitard/workspace/openapi3-generator/node_modules/lodash/lodash.js:4880:18
at Function.forEach (/Users/d.pitard/workspace/openapi3-generator/node_modules/lodash/lodash.js:9344:14)
at _.each (/Users/d.pitard/workspace/openapi3-generator/lib/beautifier.js:103:11)
at /Users/d.pitard/workspace/openapi3-generator/node_modules/lodash/lodash.js:4911:15
at baseForOwn (/Users/d.pitard/workspace/openapi3-generator/node_modules/lodash/lodash.js:2996:24)
with:
Hey, as this is an OpenAPI v3.0 tool, I wouldn't expect to see the word "swagger" showing up anywhere for anything. That is no longer the name of the specification, just the name of a few tools by SmartBear.
Can we get rid of the word Swagger before this hits a v1.0?
I am trying to build a resource file upload service but it seems to generate invalid code, but maybe I am doing it wrong:
Given a post operation like this:
post:
operationId: createResource
summary: Create new resource
description: create a remote resources
requestBody:
content:
application/octet-stream:
schema:
type: string
format: binary
The generated API gets a parameter of @requestbody Resource body but the Delegate has a parameter of MultipartFile body
Am I doing something wrong? Anyone with a working example of File upload would appreciated .
Hello,
I have great respect of people who publish open source projects: You are making this world a better place. I stumbled about this site via a search for an openAPI Documentation generator. Please allow me to suggest to very prominently include a link to an example/demo documentation that is generated by our library. otherwise lots of people will not take the time to install it to see how the documentation looks like. thanks and keep up the good work.
Hi. I try to make a template for asciidoc (asciidoctor, in fact). With test examples everythin is great. But I faced the following problem.
Here is the part of specification:
ModelMetaData:
required:
- members
- attributes
properties:
members:
description:
Meta data for members
additionalProperties: # key - memberId
$ref: '#/components/schemas/MemberMetaData'
attributes:
description:
Meta data for attributes
additionalProperties: # key - attributeId
$ref: '#/components/schemas/AttributeMetaData'
MemberMetaData:
required:
- text
properties:
text:
description:
id of the member as a text
type: string
aggregateText:
description:
aggregate of the member as a text
type: string
formulaeText:
description:
formulae of the member as a text
type: string
AttributeMetaData:
required:
- text
properties:
text:
description:
id of the attribute as a text
type: string
In the resulting table I get summaryAsHTML, descriptionAsHTML and generatedExample as extra rows and get empty descriptions.
The same problem is with Markdown template.
Here is the template code, that iterates through properties:
{{#each prop.additionalProperties.properties}}
{{> schemaProp prop=. propName=@key required=(isRequired ../prop.additionalProperties @key) path=(buildPath ../propName ../path @key)}}
{{/each}}
If the problem can be fixed in a template, just give a hint, I'll make PR for Markdown and if you don't mind I can make PR for asciidoc template.
I use additionalProperties
to define a dictionary as suggested here.
When the dictionary value is object, the resulting markdown will have rows for summaryAsHTML
, descriptionAsHTML
, generatedExample
with empty cells in Type and Description columns. This somehow breaks the HTML parsing of the table.
openapi: 3.0.0
info:
description: Test specs
version: "0.0.0"
title: Test specs
paths:
/test:
get:
summary: retrieves a dictionary
responses:
'200':
description: success response
content:
application/json:
schema:
type: object
additionalProperties:
type: object
properties:
x:
type: string
y:
type: string
# Test specs
Test specs
## Table of Contents
* [Paths](#paths)
- [`GET` /test](#op-get-test)
* [Schemas](#schemas)
## Paths
### `GET` /test
<a id="op-get-test" />
> retrieves a dictionary
#### Responses
##### โถ 200 - success response
###### Headers
_No headers specified_
###### application/json
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Accepted values</th>
</tr>
</thead>
<tbody>
<tr>
<td>Response</td>
<td>
object
</td>
<td></td>
<td><em>Any</em></td>
</tr>
<tr>
<td>Response.x</td>
<td>
string
</td>
<td></td>
<td><em>Any</em></td>
</tr>
<tr>
<td>Response.y</td>
<td>
string
</td>
<td></td>
<td><em>Any</em></td>
</tr>
<tr>
<td>Response.summaryAsHTML</td>
<td>
</td>
<td></td>
<td><em>Any</em></td>
</tr>
<tr>
<td>Response.descriptionAsHTML</td>
<td>
</td>
<td></td>
<td><em>Any</em></td>
</tr>
<tr>
<td>Response.generatedExample</td>
<td>
</td>
<td></td>
<td><em>Any</em></td>
</tr>
</tbody>
</table>
</div>
Any suggestions?
Is it possible to configure openapi3-generator to do more logging than simply printing out 'done!'?
I have a very large (but unfortunately proprietary) API spec that the generator is reporting as successfully having generated against, but the output directory is empty. Since the spec passes validation, I would like to try and figure out where the generator is going wrong but the only thing it's telling me is that my API has been successfully generated, and pointing to an empty folder.
Hi, I added PR with asciidoctor template #29. Please approve or reject it. In the latter case I'll just add it as a separate template project to my github account.
First of all: great tool, I am using it for a new project of mine and these "dynamic templates" are really helpful.
To make this tool even greater, I'd suggest the following features:
routes/auto/$$path$$.js
will be overwritten each timeservices/$$path$$.js
will be written, but not overwritten.I have the following OpenAPI3 section:
arrayProperty:
type: array
items:
$ref: '#/components/schemas/ArrayItem'
I can get the "content" of the property items with the following Handlebar
{{#each property.items as |item itemName|}}
{{itemName}} {{item}}
{{/each}}
with the following output:
items:
type string
summaryAsHTML
descriptionAsHTML
generatedExample string
How can I resolve this reference? I'd like to access the properties of the ArrayItem and not the properties of the $ref object itself.
Any hint would be greatly appreciated.
Hi,
I am generating code for petstore-expanded.yaml. However I found that requestBody schema is not present in router.
og -o ./my-docs petstore.yaml express
Kindly guide.
After installing the generator and try the example commands to start the generator, I get the following error:
TypeError: Cannot read property 'length' of undefined
at sharedStart (/usr/local/lib/node_modules/openapi3-generator/lib/beautifier.js:8:45)
at module.exports (/usr/local/lib/node_modules/openapi3-generator/lib/beautifier.js:177:24)
at bundle.catch.then (/usr/local/lib/node_modules/openapi3-generator/lib/generator.js:284:17)
at
The skip option doesn't detect existing files if the template file is called $$path$$.*
, e.g. $$path$$.js.hbs
.
Steps to reproduce:
npx openapi3-generator openapi.yaml express
npx openapi3-generator openapi.yaml express
Thanks for this project!
This line has bug in windows. Please fix it.Thanks.
Maybe can use this.
const subdir = config.root.replace(config.templates_dir, '.');
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.