Giter Club home page Giter Club logo

openapi3-generator's People

Contributors

apoloa avatar crayon2000 avatar fiddlededee avatar fmvilas avatar francoconci avatar peterlenagh avatar philsturgeon avatar ratanparai avatar richardklose avatar russell avatar scipilot avatar vsesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

openapi3-generator's Issues

Parser error just gives "oops"

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.

Feature Request: Create one file per path

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.

Feature - Generate complete CRUD functionality with json files

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:

  • Automatic generation of json-data files using the example values
  • Automatic generation of models from the schemas in the yaml-files
  • Automatic generation of services for creating, updating, deleting and viewing the respective model in the corresponding json file
  • Overwriting of automatically generated files, if concrete file exists in template folder
  • Checking for mandatory fields in the Model from yaml file

If its possible to create a new branch and open a pull request with me as contributor?

Cheers!

Best,

Matthias Suessmeier

Missing helper: "inline" when using a different template directory

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.

Errors swallowed during generateOperationFiles

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?

Wrong output location, if template path contains special characters

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.

error when generating markdown from tests/openapi3/api-with-examples.yaml

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:

image

No need to use the word "swagger" anywhere

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?

File upload spec generates invalid code

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 .

Demo

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.

#ref in additional properties

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.

image

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.

Empty table cells in markdown when using additionalProperties

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?

Turn up logging?

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.

asciidoctor template

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.

Suggestion: overwrite no-overwrite feature

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:

  1. don't-overwrite flag
  2. delete all folders called 'auto'

This is what I want to achieve with the suggested features:

  • files containing "dumb code", e.g. routes/auto/$$path$$.js will be overwritten each time
  • files destined for business logic e.g. services/$$path$$.js will be written, but not overwritten.

Advantages:

  • by deleting the 'auto' folders each time, all unused/old files will be deleted.
  • business-logic-code-files will be preserved. No more accidental losses. If you want to to re-generate a specific file, e.g. to track changes in the specs, simply move the file to another folder, re-run the code generator, and start merging the changes. For more drastic measures, just remove the don't overwrite flag and all files will be overwritten as usual.

how to resolve $ref references

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.

requestBody is not present in express

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.

TypeError: Cannot read property 'length' of undefined

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

skip files not working with $$path$$ files

The skip option doesn't detect existing files if the template file is called $$path$$.*, e.g. $$path$$.js.hbs.

Steps to reproduce:

  • Create new npm project in empty folder
  • Install latest version of openapi3
  • Save this openapi.yaml into project folder
  • run npx openapi3-generator openapi.yaml express
  • re-run npx openapi3-generator openapi.yaml express
  • Check console output: none of the src/api/routes or src/api/routes were skipped.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.