question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wing328commented, 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.

0reactions
nikolastencommented, Oct 26, 2021

jersey2 and native does not work either

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI models not being generated when using oneOf
I have oneOf generation working for java using openapi-generator 5.4.0 but I do add a discriminator field (like requestType: type: string enum: ...
Read more >
oneOf, anyOf, allOf, not - Swagger
OpenAPI lets you combine and extend model definitions using the allOf keyword. allOf takes an array of object definitions that are used for...
Read more >
Swagger OpenAPI Code Gen "oneOf" : How to generate...
I am creating the spring/java server side rest api code. And when I send a request. The request object is not parsed correctly....
Read more >
Documentation for the java Generator
generator name, java, pass this to the generate command after -g ... none: Do not annotate Model and Api with complementary annotations.
Read more >
Language Guide (proto3) | Protocol Buffers - Google Developers
When using proto3 syntax, this is the default field rule when no other ... this line will cause a compile error inside Google...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found