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
  • #8888
Closed
Open
Issue created Mar 04, 2021 by Administrator@rootContributor

[BUG][GO] Generator throws a NullPointerException when using a required property that is a reference to a oneOf

Created by: jagobagascon

Description

I'm trying to generate a simple model that references an external 'oneOf' property but the generator is throwing the following exception:

Exception in thread "main" java.lang.RuntimeException: Could not generate api file for 'Default'
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:675)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:879)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:432)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException
        at org.openapitools.codegen.languages.GoClientCodegen.constructExampleCode(GoClientCodegen.java:591)
        at org.openapitools.codegen.languages.GoClientCodegen.constructExampleCode(GoClientCodegen.java:607)
        at org.openapitools.codegen.languages.GoClientCodegen.constructExampleCode(GoClientCodegen.java:572)
        at org.openapitools.codegen.languages.GoClientCodegen.constructExampleCode(GoClientCodegen.java:615)
        at org.openapitools.codegen.languages.GoClientCodegen.constructExampleCode(GoClientCodegen.java:509)
        at org.openapitools.codegen.languages.GoClientCodegen.postProcessOperationsWithModels(GoClientCodegen.java:446)
        at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1195)
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:580)
        ... 4 more

The error only happens when the oneOf only contains primitive types or empty object types. If I uncomment the code in this example the error just dissapears.

schemas:
    pet:
      title: Pet
      properties:
        pet_type:
          $ref: "#/components/schemas/pet_type"
      required:
        - pet_type
    pet_type:
      oneOf:
        - type: string
        - type: integer
#         adding this removes the error
#        - type: object
#            properties:
#              name:
#                type: string
openapi-generator version

5.0.1

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Petstore
paths:
  /pets:
    post:
      requestBody:
        content:
            application/json:
              schema:
                $ref: "#/components/schemas/pet"
      responses:
        200:
          description: pet response
components:
  schemas:
    pet:
      title: Pet
      properties:
        pet_type:
          $ref: "#/components/schemas/pet_type"
      required:
        - pet_type
    pet_type:
      oneOf:
        - type: string
        - type: integer
Steps to reproduce

Just try to generate the previous yaml using the go generator:

openapi-generator-cli generate -i spec.yaml -g go -o out
Related Issues

I think this error is related to #8769

Assignee
Assign to
Time tracking