Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requestBody is not present in express #22

Open
mehtatejas opened this issue Apr 30, 2019 · 8 comments
Open

requestBody is not present in express #22

mehtatejas opened this issue Apr 30, 2019 · 8 comments

Comments

@mehtatejas
Copy link

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.

@fmvilas
Copy link
Collaborator

fmvilas commented Apr 30, 2019

Hi @mehtatejas. I'm not sure I understand your concern. Can you please provide a better explanation? Thanks.

@fmvilas
Copy link
Collaborator

fmvilas commented Apr 30, 2019

Oh, I understood now. You're right, this is missing. It's being done via parameters with in: body property.

Would you mind adding this feature? It's should be a matter of iterating over requestBody here: https://github.com/fmvilas/openapi3-generator/blob/master/templates/express/src/api/routes/%24%24path%24%24.js.hbs#L15.

@mehtatejas
Copy link
Author

Hi @fmvilas.

I tried as follows :

{{#each ../requestBody  as |a content|}}
    {{#match content "content"}}
    {{#each a as |b json|}}
        {{#each b as |c schema|}}
          {{#match schema "schema"}}
            {{#each c as |d properties|}}
              {{#match properties "properties"}}
                {{#each d as |e properties|}}
{{properties}}: req.body.{{properties}}{{#unless @last}},{{/unless}}
                {{/each}}
              {{/match}}
            {{/each}}
          {{/match}}
        {{/each}}
      
    {{/each}}
    {{/match}}
{{/each}}

However, I am not sure this is correct approach

@fmvilas
Copy link
Collaborator

fmvilas commented Apr 30, 2019

I haven't tested it but I think is like this:

{{#each ../requestBody.content.['application/json'].schema.properties as |prop|}}
  {{prop}}: req.body.{{prop}}{{#unless @last}},{{/unless}}
{{/each}}

There's no need to check for existence in Handlebars. For instance, in the expression ../requestBody.content.['application/json'].schema.properties, if ../requestBody.content is undefined nothing will happen and it will not fail.

@mehtatejas
Copy link
Author

Following code works.

{{#each ../requestBody.content}}
  {{#each this.schema.properties}}
{{@key}}: req.body.{{@key}}{{#unless @last}},{{/unless}}
  {{/each}}     
{{/each}}

@fmvilas
Copy link
Collaborator

fmvilas commented Apr 30, 2019

Can you paste your OpenAPI description here? Just the excerpt where requestBody is.

@mehtatejas
Copy link
Author

https://github.com/fmvilas/openapi3-generator/blob/master/tests/openapi3/petstore-expanded.yaml

post:
description: Creates a new pet in the store. Duplicates are allowed
operationId: addPet
requestBody:
description: Pet to add to the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/NewPet'

@fmvilas
Copy link
Collaborator

fmvilas commented Apr 30, 2019

Oh! I see. Yeah it should be correct 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants