[BUG] openapi-generator problem with nested oneOf?

See original GitHub issue
Description

The openapi-generator client generation crashes on the provided OpenAPI document, which passes validation both using openapi-generator validate and linting using speccy. It seems to be language independent (affects all languages I tried).

openapi-generator version

4.0.0-beta3

OpenAPI declaration file content or url

Gist of JSON here: https://gist.github.com/einarwh/c8526951c3080ddca7b3b791066bb9e3

Command line used for generation

No fancy options, just: openapi-generator generate -i openapi.json -g csharp

Steps to reproduce

Save gist as e.g. openapi.json and run: openapi-generator validate -i openapi.json to verify that the document is valid and then openapi-generator generate -i openapi.json -g csharp to get error message complaining about ‘ResourceId’ model.

Related issues/PRs

Looks very similar to this: https://github.com/OpenAPITools/openapi-generator/issues/2610

Suggest a fix/enhancement

It seems that the problem is due to nested oneOf’s.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
kilimnikcommented, Dec 16, 2019

Is there someone working on supporting oneOf and anyOf to be generated by the C# client generator?

0reactions
arvindpdmncommented, Nov 15, 2022

The issue is beyond nested oneOf. Code generation fails if there’s an array within a oneOf. However, there’s no error if I change it to allOf or anyOf. Here’s a fancy example:

    MyBox:
      oneOf:
        - type: array
          items:
            $ref: 'Stationery.yaml#/components/schemas/Pencil'
          minItems: 1
        - $ref: '#/components/schemas/GeometryBox'

Error with generator 6.2.0:

Caused by: java.lang.RuntimeException: Could not generate model 'MyBox'
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:563)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:912)
        at org.openapitools.generator.gradle.plugin.tasks.GenerateTask.doWork(GenerateTask.kt:770)
        ... 143 more
Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end 1, length 0
        at org.openapitools.codegen.templating.mustache.TitlecaseLambda.titleCase(TitlecaseLambda.java:64)
        at org.openapitools.codegen.templating.mustache.TitlecaseLambda.execute(TitlecaseLambda.java:80)
...

Generator options:

{
        globalProperties = [
            models: "",
            apis: ""
        ]
        generatorName = "csharp-netcore"
        inputSpec = <some-yaml-file>
        outputDir = "$buildDir/generated".toString()
        skipValidateSpec = true
        generateApiTests = false
        generateApiDocumentation = false
        generateModelTests = false
        generateModelDocumentation = false
        configOptions = [
            netCoreProjectFile: "true",
            nonPublicApi: "true",
            targetFramework: "net6.0"
        ]
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

OneOf, nested inside of another OneOf is not shown...
Hello,. I am developing a Spring app with OpenApi. For open API spec (schema.txt) java code is generated by the maven code generator...
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 >
OpenAPI Codegen "oneOf": Java classes not generated ...
I am creating the spring/java server side rest api code using OpenAPI maven plugin. The request class is not such that the passed...
Read more >
An adventure in OpenAPI V3 code generation | Mux blog
It's an easy warning to ignore, especially given that OpenAPI Generator is pretty chatty as it generates code. When you see this warning,...
Read more >
Open-generator-cli problems, or Swagger/OpenApi ...
However, that creates some strange OneOf thing in the swagger.json. I made a bug report. In the meantime, I changed my C# code....
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