OpenAPITools / OpenAPITools/openapi-generator

[BUG] oneOf Could not process model

Open
#4,989 3 comments 0 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)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

Running openapi-generator-cli via docker on the latest mockserver spec file throws an error

Exception in thread "main" java.lang.RuntimeException: Could not process model 'Expectations'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:472)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:923)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:416)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
Caused by: java.lang.NullPointerException
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2003)
at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1847)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1166)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:467)
... 3 more

Section of file causing the error is

   "oneOf" : [ {
      "$ref" : "#/components/schemas/Expectation"
    }, {
      "type" : "array",
      "additionalProperties" : false,
      "items" : {
        "$ref" : "#/components/schemas/Expectation"
      }
    } ]

Removing the oneOf and just leaving for example the array section fixes the issue and file generation completes successfully.

openapi-generator version

4.2.2 and 4.2.3-SNAPSHOT run via docker

OpenAPI declaration file content or url

https://api.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.8.x

Command line used for generation

docker run --rm -v "mockserver:/local" openapitools/openapi-generator-cli:v4.2.2 generate -i https://api.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.8.x -c /local/swagger/config.json -g php -o /local

Steps to reproduce

Run docker command above

Related issues/PRs
Suggest a fix

Sorry I only do PHP!

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

Reproduce the failure with the documented Docker command and inspect DefaultCodegen.addProperties, DefaultCodegen.fromModel, and DefaultGenerator.generateModels using the provided oneOf schema. Verify the generator handles the Expectation model and completes PHP generation without the NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java, php
Domain
api, 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.