-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
[DefaultCodegen] Incorrect name for request body parameter of array types #376
Comments
why can't we use |
Internally we are using Swagger-Parser to read the model. If we read an OAS2, the tool also do an on-the-fly conversion “OAS2 -> OAS3”. Here is what we get from the parser when we read your example spec: openapi: 3.0.1
info:
title: ContainerApplication
description: Container Application Model Description
version: 1.0.0
servers:
- url: http://localhost:32000/api/v1.0
tags:
- name: ApplicationEndpointTest
description: |
"Test of endpoints "
x-displayName: ApplicationEndpointTest
paths:
/default/EndpointTest:
post:
tags:
- ApplicationEndpointTest
description: post a request
operationId: callEndpoint
requestBody:
description: Requests to post
content:
application/json:
schema:
$ref: '#/components/schemas/listitems'
required: true
responses:
200:
description: Successful response
content: {}
404:
description: The request was not successfully executed.
content: {}
components:
schemas:
listitems:
type: array
description: list of items
items:
type: string In OAS3 the Request body does not have a name... I have raised swagger-api/swagger-parser#748 in order to keep this information during the conversion. Feel free to indicate there that you are interested by the feature. |
PR #1721 was merged. @etherealjoy can you verify if your issue is fixed with the latest |
@jmini |
Description
When the logs below show up
There is an issue in sanitizing the name of the parameter.
For example for aspnetcore the output is below
One of the issues with this is related to how arrays in a request body are handled in
DefaultCodegen
the function is called from
where
and then in
fromRequestBody
mostInnerItem.complexType
is null for arrays of primitive or maps therefore here intoArrayModelParamName
sanitization happens with anull
resulting in NPE for generators which don't overloadtoVarName
properly.TL;DR;
Problem is here
codegenParameter.baseName = mostInnerItem.complexType;
below is incorrect
openapi-generator version
master
OpenAPI declaration file content or url
Command line used for generation
java -jar ~/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar \ generate -i ./api.yaml -g aspnetcore -o genserver
Related issues/PRs
#373
Suggest a fix/enhancement
This part is handled correctly in case of array of Models but for the primitive and arrays it causes a warning log which can trigger NPE in some generators and causes a wrong parameter name to be created.
The text was updated successfully, but these errors were encountered: