openapi Перечисляет нулевые значения

#java #maven #openapi #swagger-2.0 #openapi-generator

Вопрос:

В настоящее время я пытаюсь получить нулевые значения для перечисления, в соответствии со спецификациями OpenAPI, это возможно. Я пытаюсь следовать инструкциям, приведенным здесь

https://swagger.io/docs/specification/data-models/enums/

моя реализация yaml

 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:
    Item:
      title: Order Item
      type: object
      description: 'The order item.'
      required:
        - type
      properties:
        name:
          type: string
        type:
          $ref: '#/components/schemas/ItemType'

    ItemType:
      description: 'The Type of the Item'
      type: string
      nullable: true
      enum:
        - "PHYSICAL"
        - "DIGITAL"
        - null      
 

когда я создаю и запускаю mvn clean install с изменениями
nullable:true и enum: со значением null, как показано выше, я получаю следующее исключение

 [DEBUG] debugging from property return: CodegenProperty{baseName='type', openApiType='ItemType', complexType='ItemType', getter='getType', setter='setType', description='null', datatype='ItemType', datatypeWithEnum='ItemType', dataFormat='null', name='type', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.type;', baseType='ItemType', containerType='null', title='null', unescapedDescription='null', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{
  "$ref" : "#/components/schemas/ItemType"
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, hasMore=false, required=false, secondaryParam=false, hasMoreNonReadOnly=false, isPrimitiveType=false, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isLong=false, isNumber=false, isFloat=false, isDouble=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isFreeFormObject=false, isListContainer=false, isMapContainer=false, isEnum=false, isReadOnly=false, isWriteOnly=false, isNullable=true, isSelfReference=false, _enum=null, allowableValues={values=[PHYSICAL, DIGITAL, null]}, items=null, mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='Type', enumName='null', maxItems=null, minItems=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false}
[ERROR]  unexpected error in Open-API generation
java.lang.RuntimeException: Could not process model 'Item'.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.updateCodegenPropertyEnum (DefaultCodegen.java:4304)
    at org.openapitools.codegen.DefaultCodegen.postProcessModelsEnum (DefaultCodegen.java:385)
    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 'Item'.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.updateCodegenPropertyEnum (DefaultCodegen.java:4304)
    at org.openapitools.codegen.DefaultCodegen.postProcessModelsEnum (DefaultCodegen.java:385)
    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)
 

есть какие-либо мысли о том, что может быть причиной этого исключения, и какие шаги я должен предпринять, чтобы решить/устранить эту проблему?

Комментарии:

1. Не совсем уверен. Но предположение: Определение типа элемента имеет и то nullable: true , и другое, и нулевое значение в списке перечислений. Выглядит лишним. Попробуйте удалить null значение из списка перечислений и проверьте.

2. если вы посмотрите сюда swagger.io/docs/specification/data-models/enums и то, и другое требуется в соответствии со спецификациями. Я попытался удалить null и nullable: true независимо, но безуспешно.

3. Проблема, по-видимому, сохраняется в модели схемы «Элемент». Это было объявлено компанией never used. Если вы используете какие-либо зависимости, связанные с swagger, можете ли вы проверить, поддерживают ли эти версии nullable перечисление? Если нет, попробуйте обновить их и проверьте.