Open mehtatejas opened 5 years ago
Hi @mehtatejas. I'm not sure I understand your concern. Can you please provide a better explanation? Thanks.
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.
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
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.
Following code works.
{{#each ../requestBody.content}}
{{#each this.schema.properties}}
{{@key}}: req.body.{{@key}}{{#unless @last}},{{/unless}}
{{/each}}
{{/each}}
Can you paste your OpenAPI description here? Just the excerpt where requestBody is.
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'
Oh! I see. Yeah it should be correct :+1:
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.