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

[BUG] Generator try to use oneOf* model but does not create it #8860

Open
5 of 6 tasks
Adi1231234 opened this issue Feb 28, 2021 · 5 comments
Open
5 of 6 tasks

[BUG] Generator try to use oneOf* model but does not create it #8860

Adi1231234 opened this issue Feb 28, 2021 · 5 comments
Labels
Inline Schema Handling Schema contains a complex schema in items/additionalProperties/allOf/oneOf/anyOf Issue: Bug

Comments

@Adi1231234
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

On oneOf usage in openAPI declaration the generator try to use oneOf* model but does not create it in any language

openapi-generator version

5.0.1

OpenAPI declaration file content or url
{
  "openapi": "3.0.0",
  "info": {
    "title": "service",
    "description": "API",
    "version": "1.0",
    "contact": {}
  },
  "tags": [],
  "servers": [],
  "components": {
    "schemas": {
      "Category": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "parentCategoryId": { "type": "number" }
        },
        "required": ["name", "parentCategoryId"]
      },
      "GetManyCategoryResponseDto": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Category" }
          },
          "count": { "type": "number" },
          "total": { "type": "number" },
          "page": { "type": "number" },
          "pageCount": { "type": "number" }
        },
        "required": ["data", "count", "total", "page", "pageCount"]
      }
    }
  },
  "paths": {
    "/categories": {
      "get": {
        "operationId": "getManyBaseCategoriesControllerCategory",
        "summary": "Retrieve many Category",
        "parameters": [
          {
            "name": "fields",
            "description": "Selects resource fields",
            "required": false,
            "in": "query",
            "schema": { "type": "array", "items": { "type": "string" } },
            "style": "form",
            "explode": false
          }
        ],
        "responses": {
          "200": {
            "description": "Get many base response",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/GetManyCategoryResponseDto"
                    },
                    {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Category" }
                    }
                  ]
                }
              }
            }
          }
        },
        "tags": ["Categories"]
      }
    }
  }
}
Generation Details
Steps to reproduce

execute - java -jar openapi-generator-cli.jar generate -i categories.swagger -o out -g (any language)

then at api/categories_api the generated function is:

Future<Response<OneOfGetManyCategoryResponseDtoarray>> getManyBaseCategoriesControllerCategory({ 
  BuiltList<String> fields,
})

the problem is that OneOfGetManyCategoryResponseDtoarray class does not exist in any file.

Related issues/PRs

#3965 - Similar a bit

Suggest a fix
@wing328
Copy link
Member

wing328 commented Mar 1, 2021

java (jersey2, natvie), csharp-netcore, powershell, python, ruby and go have better support for oneOf. Please give these a try when you've time.

@germanschnyder
Copy link

Hi @wing328, are there any plans on adding support for other languages ? I'm working with the openapi to proto generator and I noticed the same. Was trying to map openapi's oneOf to protobuf's oneof. Or at least some pain points / checklist you identified for properly implementing this (i.e. where to add code in the codegen to get it working).

@wing328
Copy link
Member

wing328 commented Mar 4, 2021

We definitely want to add oneOf, anyof support to all generators. At this stage, we rely on contributions from the community to implement the feature with reference to the generators that support these features or those who need these features with a higher priority can consider sponsoring the tasks to make it a higher priority among the community.

For your case, we welcome contributions from you to add oneOf support to the protobuf-schema generator or you can sponsor the enhancement to have it done by the community.

@leus
Copy link

leus commented Oct 2, 2021

java (jersey2, natvie), csharp-netcore, powershell, python, ruby and go have better support for oneOf. Please give these a try when you've time.

csharp-netcore does not generate compilable code for OneOf nor AnyOf, just like in the provided report.

@nikolasten
Copy link

jersey2 and native does not work either

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Inline Schema Handling Schema contains a complex schema in items/additionalProperties/allOf/oneOf/anyOf Issue: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants