quarkiverse / quarkus-openapi-generator

OpenAPI Generator - REST Client Generator
Apache License 2.0
121 stars 83 forks source link

Wrong handling when spec includes both properties and items #513

Open fjtirado opened 1 year ago

fjtirado commented 1 year ago

From following snippet

"operationId": "update-roles-of-user",
 "parameters": [
 {
 "name": "idp-id",
 "in": "path",
 "description": "ID of the identity provider.",
 "required": true,
 "example": "idp-1",
 "schema": {
 "$ref": "#/components/schemas/ID"
 }
 },
 {
 "name": "user-id",
 "in": "path",
 "description": "ID of the user as given by the identity provider.",
 "required": true,
 "example": "user-1",
 "schema": {
 "type": "string"
 }
 }
 ],
 "requestBody": {
 "description": "Add, remove or overwrite the roles of the user.",
 "content": {
 "application/json": {
 "schema": {
 "type": "object",
 "properties": {
 "op": {
 "type": "string",
 "description": "add: add these roles to the existing roles the user has. \nremove: remove these roles from the existing roles the user has. \noverwrite: completely overwrite the existing roles the user has with these roles.\n",
 "enum": [
 "add",
 "remove",
 "overwrite"
 ]
 },
 "roles": {
 "type": "array",
 "items": {
 "type": "string"
 },
 "description": "List of role IDs",
 "example": [
 "role-1",
 "role-2"
 ]
 }
 },
 "items": {
 "type": "string"
 }
 }
 }
 },
 "required": true
 }

Items should be ignored and properties used to generate a pojo, but currently the generator is doing the other way around

mcruzdev commented 1 year ago

Hi @hbelmiro and @fjtirado , how are you? I think that I can get this one!

fjtirado commented 1 year ago

@mcruzdev I was looking into it The culprit is here https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java#L2709 That creates an ArraySchema, which causes this method https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java#L268 to ignore the properties part and do not create the request POJO I tried to replace the OpenApiDeserializer by my own, but thats prevented by this line https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java#L67 Changing the options path is also blocked by this https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java#L635 So I guess we needs to see how to extends InlineModelResolver. Just contact me at zulip https://kie.zulipchat.com and we will discuss

fjtirado commented 1 year ago

@mcruzdev Follow up of my previous comment, InlineModelResolver is not an option either https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java#L246 Anyway, lets talk and see how this can be fixed