You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there are optional fields in the post request body, the generated ts code converts these optional fields to mandatory.
e.g. "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "searchCriteria": { "$ref": "#/components/schemas/SearchLessonCriteria" } } } } } } "SearchLessonCriteria": { "required": ["showTransient", "status"], "type": "object", "properties": { "text": { "type": "string" } } }
The generated ts code is export interface SearchLessonCriteria { text: string }
Generating the cli code on my machine with swagger-code cli does keep it optional.
The reason seems to be missing {{^required}}?{{/required}} after var name in file modelGeneric.mustache
When there are optional fields in the post request body, the generated ts code converts these optional fields to mandatory.
e.g.
"requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "searchCriteria": { "$ref": "#/components/schemas/SearchLessonCriteria" } } } } } }
"SearchLessonCriteria": { "required": ["showTransient", "status"], "type": "object", "properties": { "text": { "type": "string" } } }
The generated ts code is
export interface SearchLessonCriteria { text: string }
Generating the cli code on my machine with swagger-code cli does keep it optional.
The reason seems to be missing
{{^required}}?{{/required}}
after var name in file modelGeneric.mustachechimp-datasources-generator/lib/typescript-fetch/modelGeneric.mustache
Line 17 in 3a51e38
Suggested fix at above line:
{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
I have raised a PR for this. Hopefully this helps.
The text was updated successfully, but these errors were encountered: