Forum Discussion

ahk's avatar
ahk
Occasional Visitor
4 years ago

Openapi enum null values

Hi Team,

 

Following the specifications here https://swagger.io/docs/specification/data-models/enums/. I want to have enums that can have null values thus based on the above doc I created an open API spec something like this 

 

openapi: 3.0.1

info:
  title: Test
  description: Test API
  contact:
    name: a
    url: http://www.google.com
    email: user@test.com
  version: '1.0'

paths:
  /v1/getItems:
    summary: 'get items'
    description: 'get items'
    post:
      summary: items get
      operationId: getItems
      x-grantTypeRequirement: 'client_credentials'
      tags:
        - items
     
      responses:
        200:
          description: Success
        
components:
  schemas:
    ItemType:
      description: 'The Type of the Item'
      type: string
      nullable: true
      enum:
        - "PHYSICAL"
        - "DIGITAL"
        - null

    Item:
      type: object
      properties:
       type:
         allOf:
          - $ref: '#/components/schemas/ItemType'
          - type: object
          
       

 

but when I build this with maven I get the following error 

 

[ERROR]  [0:0]: unexpected error in Open-API generation
java.lang.RuntimeException: Could not process model 'ItemType'.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.plugin.CodeGenMojo.execute (CodeGenMojo.java:727)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at com.soebes.maven.plugins.iterator.IteratorMojo.executeMojo (IteratorMojo.java:406)
    at com.soebes.maven.plugins.iterator.IteratorMojo.handlePluginExecution (IteratorMojo.java:305)
    at com.soebes.maven.plugins.iterator.IteratorMojo.execute (IteratorMojo.java:235)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.NullPointerException
    at org.openapitools.codegen.DefaultCodegen.postProcessModelsEnum (DefaultCodegen.java:365)
    at org.openapitools.codegen.languages.SpringCodegen.postProcessModelsEnum (SpringCodegen.java:815)
    at org.openapitools.codegen.languages.AbstractJavaCodegen.postProcessModels (AbstractJavaCodegen.java:999)
    at org.openapitools.codegen.DefaultGenerator.processModels (DefaultGenerator.java:1233)
    at org.openapitools.codegen.DefaultGenerator.generateModels (DefaultGenerator.java:467)
    at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:923)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:727)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at com.soebes.maven.plugins.iterator.IteratorMojo.executeMojo (IteratorMojo.java:406)
    at com.soebes.maven.plugins.iterator.IteratorMojo.handlePluginExecution (IteratorMojo.java:305)
    at com.soebes.maven.plugins.iterator.IteratorMojo.execute (IteratorMojo.java:235)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
java.lang.RuntimeException: Could not process model 'ItemType'.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.plugin.CodeGenMojo.execute (CodeGenMojo.java:727)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at com.soebes.maven.plugins.iterator.IteratorMojo.executeMojo (IteratorMojo.java:406)
    at com.soebes.maven.plugins.iterator.IteratorMojo.handlePluginExecution (IteratorMojo.java:305)
    at com.soebes.maven.plugins.iterator.IteratorMojo.execute (IteratorMojo.java:235)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.NullPointerException
    at org.openapitools.codegen.DefaultCodegen.postProcessModelsEnum (DefaultCodegen.java:365)
    at org.openapitools.codegen.languages.SpringCodegen.postProcessModelsEnum (SpringCodegen.java:815)
    at org.openapitools.codegen.languages.AbstractJavaCodegen.postProcessModels (AbstractJavaCodegen.java:999)
    at org.openapitools.codegen.DefaultGenerator.processModels (DefaultGenerator.java:1233)
    at org.openapitools.codegen.DefaultGenerator.generateModels (DefaultGenerator.java:467)
    at org.openapitools.codegen.DefaultGenerator.generate (DefaultGenerator.java:923)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:727)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at com.soebes.maven.plugins.iterator.IteratorMojo.executeMojo (IteratorMojo.java:406)
    at com.soebes.maven.plugins.iterator.IteratorMojo.handlePluginExecution (IteratorMojo.java:305)
    at com.soebes.maven.plugins.iterator.IteratorMojo.execute (IteratorMojo.java:235)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Replace

        Item:
          type: object
          properties:
           type:
             allOf:
              - $ref: '#/components/schemas/ItemType'
              - type: object

    with

        Item:
          type: object
          properties:
           type:
             $ref: '#/components/schemas/ItemType'

     

    If this does not help, open an issue with the openpapi-generator project:

    https://github.com/OpenAPITools/openapi-generator/issues