Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2610
Closed
Open
Issue created Apr 05, 2019 by Administrator@rootContributor4 of 5 checklist items completed4/5 checklist items

[BUG][All languages] NullPointerException on nested ComposedSchema

Created by: DonDi94

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

I tried to generate code from a yaml with the latest commit of the generator, but I got the following exception:

Exception in thread "main" java.lang.RuntimeException: Could not process model 'ComplexData'.Please make sure that your schema is correct! at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:458) at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:899) at org.openapitools.codegen.cmd.Generate.run(Generate.java:368) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60) Caused by: java.lang.NullPointerException at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:1831) at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1737) at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1137) at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:453) ... 3 more

I tried to get into the source and it seems to be a problem with ComposedSchema handling. At line 1831 in addProperties the allOf is processed so that all of the properties defined in it are added to required and properties (lines 1852 and 1855). There is a check for the input variable schema to be an instance of ComposedSchema, but that is true for oneOf, anyOf and allOf, not just allOf. If we have a allOf all of its properties will be processed by the for loop recursively, if one of its properties is a oneOf it will be passed recursively to addProperties, the condition schema instanceOf ComposedSchema will be true and the procedure will continue to the for loop. As we are handling a oneOf, schema.getAllOf() will return null and create a NullPointerException.

openapi-generator version

4.0.0, commit b5ede4b3

OpenAPI declaration file content or url
openapi: '3.0.0'
info:
  version: 1.0.0
  title: ComplexTest
  description: A sample API that uses a complex schema
paths: 
  /test:    
    post:
      operationId: ComplexTest
      requestBody:
        content:
          'multipart/form-data+json':
            schema:
              $ref: '#/components/schemas/ComplexData'
      responses:
        default:
          $ref: '#/components/responses/DefaultResponse'
components:
  schemas:
    ComplexData:
      type: object
      properties:
        username:
          type: string
        email:
          type: string
      allOf:
        - oneOf:
          - required: [ username ]
          - required: [ email ]
  responses:
    DefaultResponse:
      description: unexpected error
      content:       
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
Command line used for generation

java -jar openapi-generator-cli.jar generate -i complexdata.yaml -g erlang-client -o client/

java -jar openapi-generator-cli.jar generate -i complexdata.yaml -g erlang-server -o client/

Steps to reproduce
  • Create a file complexdata.yaml with the given yaml specifications
  • Generate the code in any language
Related issues/PRs

I haven't found related issues other than old oneOf issues.

Assignee
Assign to
Time tracking