OpenAPITools / OpenAPITools/openapi-generator

[BUG] Oneof under #/components/schemas/ generates invalid code for OAS 3.0

Open
#9,791 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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
openapi-generator version

oneOf block in this spec produces undefined model OneOfarraystring. I have tried and reproduced this with Java and Go generators and looks like this behavior is consistent for all the generators.

OpenAPI declaration file content or url
{
  "openapi": "3.0.0",
  "info": {
    "title": "",
    "version": "v2"
  },
  "servers": [
    {
      "url": ""
    }
  ],
  "externalDocs": {
    "description": "",
    "x-amf-title": "About",
    "url": ""
  },
  "paths": {
    "/database/databases": {
      "get": {
        "description": "List databases.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/database_databases_query"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/database_databases"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "database_databases": {
        "description": ".",
        "type": "array",
        "items": {}
      },
      "database_databases_query": {
        "description": ".",
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "uuid": {
            "description": "Database uuid filter",
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "string"
              }
            ]
          },
          "status": {
            "description": "Database status filter",
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "enum": [
                    "CREATE_IN_PROGRESS",
                    "CREATED",
                    "UPDATE_IN_PROGRESS",
                    "DELETE_IN_PROGRESS",
                    "DELETED"
                  ],
                  "type": "string"
                }
              },
              {
                "enum": [
                  "CREATE_IN_PROGRESS",
                  "CREATED",
                  "UPDATE_IN_PROGRESS",
                  "DELETE_IN_PROGRESS",
                  "DELETED"
                ]
              }
            ]
          }
        }
      }
    }
  }
}

Generation Details
openapi-generator-cli   generate -i api-oas3-modified.json -g go-server -o  generated-sdk/go-server --enable-post-process-file
openapi-generator-cli   generate -i api-oas3-modified.json -g go -o  generated-sdk/go --enable-post-process-file
openapi-generator-cli   generate -i api-oas3-modified.json -g java -o  generated-sdk/java --enable-post-process-file
Steps to reproduce
  1. Put spec in a file
  2. Run generation cli commands above
  3. Search for OneOfarraystring in DatabaseDatabasesQuery model in generated code
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied api-oas3-modified.json and run the listed openapi-generator-cli commands for go-server, go, and java. Inspect the DatabaseDatabasesQuery models for the undefined OneOfarraystring reference; done means the reproduced oneOf schemas no longer generate invalid model references across the affected generators.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java
Domain
api, backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.