Skip to content

More descriptive exceptions need to be thrown #133

Closed

Description

@SENIAN

Im unable to debug my openapi.yaml file properly if this validation error is thrown.
I've got another validator for my openapi spec and this reports that my openapi spec has no validation errors.

Plugin settings:

           <groupId>io.openapiprocessor</groupId>
           <artifactId>openapi-processor-maven-plugin</artifactId>
           <version>2021.1</version>
           <configuration>
               <id>openapi-generation</id>
               <apiPath>${project.basedir}/openapi.yaml</apiPath>
           </configuration>
           <executions>
               <execution>
                   <id>openapi-generation</id>
                   <phase>generate-sources</phase>
                   <goals>
                       <goal>process</goal>
                   </goals>
                   <configuration>
                       <id>spring</id>
                       <options>
                           <values>
                               <targetDir>${project.basedir}/target/generated-sources</targetDir>
                               <mapping>${project.basedir}/openapi-mapping.yaml</mapping>
                               <parser>OPENAPI4J</parser>
                               <showWarnings>true</showWarnings>
                               <bean-validation>true</bean-validation>
                           </values>
                       </options>
                   </configuration>
               </execution>
           </executions>
           <dependencies>
               <dependency>
                   <groupId>io.openapiprocessor</groupId>
                   <artifactId>openapi-processor-core</artifactId>
                   <version>2021.4.2</version>
               </dependency>
               <dependency>
                   <groupId>io.openapiprocessor</groupId>
                   <artifactId>openapi-processor-spring</artifactId>
                   <version>2021.4</version>
               </dependency>
           </dependencies>
       </plugin>

OpenAPI SPEC:

openapi: 3.0.3
info:
  title: An API
  version: '1.0'
paths:
  /manager/epa:
    patch:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ResponseMessage'
      responses:
        '200':
          description: Successfully executed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResponseMessage'
        '400':
          description: Bad Request
          $ref: '#/components/responses/404'
        '404':
          $ref: '#/components/responses/404'
        '500':
          description: Internal error
          content:
            application/json:
              schema:
                type: string
    get:
      parameters:
        - in: query
          name: id
          schema:
            type: string
          required: true
          description: Retrieve an instance
      responses:
        '200':
          description: Successfully executed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResponseMessage'
        '400':
          $ref: '#/components/schemas/ResponseMessage'
        '404':
          $ref: '#/components/responses/404'
        '500':
          description: Internal error
          content:
            application/json:
              schema:
                type: string
components:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
  schemas:
    ResponseMessage:
      type: object
      properties:
        correlationId:
          type: string
        resultCode:
          type: integer
        resultDetails:
          $ref: '#/components/schemas/MessageDetails'

    MessageDetails:
      type: object
      properties:
        exitCode:
          type: integer
        exitMessage:
          type: string
        res1:
          type: string
        res2:
          type: string
        stacktrace:
          type: string
  responses:
    '200':
      description: Successfully processed your request.
      content:
        text/plain:
          schema:
            $ref: '#/components/schemas/ResponseMessage'
    '204':
      description: Successfully updated
      content:
        text/plain:
          schema:
             $ref: '#/components/schemas/ResponseMessage'
    '400':
      description:  The request was invalid
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ResponseMessage'
    '404':
      description: Resource cannot be found or does not exist.
    '500':
      description:
        Internal error
      content:
        application/json:
          schema:
             $ref: '#/components/schemas/ResponseMessage'
security:
  - basicAuth: []


Error thrown:

[ERROR] Failed to execute goal io.openapiprocessor:openapi-processor-maven-plugin:2021.1:process (openapi-generation) on project servicemanager-cc: openapi-processor-spring execution failed!: OpenApi3 validation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal io.openapiprocessor:openapi-processor-maven-plugin:2021.1:process (openapi-generation) on project servicemanager-cc: openapi-processor-spring execution failed!
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    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 jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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: org.apache.maven.plugin.MojoExecutionException: openapi-processor-spring execution failed!
    at io.openapiprocessor.maven.ProcessMojo.execute (ProcessMojo.java:67)
    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 jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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: org.openapi4j.core.validation.ValidationException: OpenApi3 validation failure
    at org.openapi4j.parser.validation.v3.OpenApi3Validator.validate (OpenApi3Validator.java:28)
    at org.openapi4j.parser.OpenApi3Parser.parse (OpenApi3Parser.java:41)
    at org.openapi4j.parser.OpenApi3Parser.parse (OpenApi3Parser.java:17)
    at org.openapi4j.parser.OpenApiParser.parse (OpenApiParser.java:53)
    at io.openapiprocessor.core.parser.openapi4j.Parser.parse (Parser.kt:33)
    at io.openapiprocessor.core.parser.Parser.parse (Parser.kt:29)
    at io.openapiprocessor.spring.processor.SpringProcessor.run (SpringProcessor.kt:39)
    at io.openapiprocessor.maven.ProcessorRunner.run (ProcessorRunner.java:31)
    at io.openapiprocessor.maven.ProcessMojo.execute (ProcessMojo.java:60)
    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 jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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)

Activity

  1. SENIAN commented on Aug 10, 2021

    @SENIAN
    Author

    After some through debugging i've found out that i was copying from the yaml formatter to my IDE and losing the format. Resolved by copying without formatting from IDE pov. However maybe a proper yaml validator/openapi3 can be added?

  2. hauner commented on Aug 11, 2021

    @hauner
    Member

    the processor does currently depend on the parser to provide validation info. Sometimes the parser output helps sometimes not :-( Having more specific validation would be nice.

    Have to do some research :-)

  3. hauner commented on Aug 17, 2021

    @hauner
    Member

    closing this one, the feature request moved to openapi-processor/openapi-processor-core#77

  4. hauner commented on Aug 26, 2021

    @hauner
    Member

    since validation with the schema will probably not work I will take another look at the parser validation.

  5. reopened this on Aug 26, 2021
  6. hauner commented on Aug 27, 2021

    @hauner
    Member

    ok, getting the following error when running via gradle but not when running via maven. So its is the maven plugin that does not print the validation messages.

    OpenApi3 validation failure
    Validation error(s) :
    paths./manager/epa.get.responses.400.description: Required field is missing 'description'. (code: 105)
    From: paths./manager/epa.get.responses.400.description
    paths./manager/epa.get.responses.400.extensions.type: Invalid key 'type' in map 'x-.+'. (code: 107)
    From: paths./manager/epa.get.responses.400.extensions.type
    paths./manager/epa.get.responses.400.extensions.properties: Invalid key 'properties' in map 'x-.+'. (code: 107)
    From: paths./manager/epa.get.responses.400.extensions.properties
  7. added this to the core: 2021.5.2 milestone on Aug 28, 2021
  8. SENIAN commented on Oct 8, 2021

    @SENIAN
    Author

    Thanks Hauner!

  9. modified the milestones: core: 2021.5.2, 2021.6 on Oct 10, 2021
  10. hauner commented on Oct 10, 2021

    @hauner
    Member

    improved in 2021.6

  11. juliocauan commented on Feb 24, 2022

    @juliocauan

    So I've got the same error over here and I can't figure what's wrong with it

    Plugin Settings:

                <groupId>io.openapiprocessor</groupId>
                <artifactId>openapi-processor-maven-plugin</artifactId>
                <version>2021.1</version>
    
                <configuration>
                    <id>openapi-generation</id>
                    <apiPath>${project.basedir}/src/main/resources/swagger/sboot-api-atom-global.yaml</apiPath>
                </configuration>
                
                <executions>
                    <execution>
                        <id>openapi-generation</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <id>spring</id>
                            <options>
                                <values>
                                    <targetDir>${project.basedir}/target/generated-sources</targetDir>
                                    <mapping>${project.basedir}/src/main/resources/swagger/mapping.yaml</mapping>
                                    <parser>OPENAPI4J</parser>
                                    <showWarnings>true</showWarnings>
                                    <bean-validation>true</bean-validation>
                                </values>
                            </options>
                        </configuration>
                    </execution>
                </executions>
    
                <dependencies>
                    <dependency>
                        <groupId>io.openapiprocessor</groupId>
                        <artifactId>openapi-processor-spring</artifactId>
                        <version>2022.1</version>
                    </dependency>
                </dependencies>
            </plugin>
    

    Error thrown:

    [ERROR] Failed to execute goal io.openapiprocessor:openapi-processor-maven-plugin:2021.1:process (default-cli) on project sboot-api-atom-global: openapi-processor-openapi-generation execution failed!: NullPointerException -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal io.openapiprocessor:openapi-processor-maven-plugin:2021.1:process (default-cli) on project sboot-api-atom-global: openapi-processor-openapi-generation execution failed!
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    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:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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: org.apache.maven.plugin.MojoExecutionException: openapi-processor-openapi-generation execution failed!
    at io.openapiprocessor.maven.ProcessMojo.execute (ProcessMojo.java:67)
    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:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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 java.io.File. (File.java:278)
    at io.openapiprocessor.maven.ProcessMojo.execute (ProcessMojo.java:51)
    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:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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)

  12. hauner commented on Feb 25, 2022

    @hauner
    Member

    The interesting lines in the error are:

    Caused by: java.lang.NullPointerException
    at java.io.File. (File.java:278)
    at io.openapiprocessor.maven.ProcessMojo.execute (ProcessMojo.java:51)
    

    The plugin creates a File object from the targetDir path. But targetDir is null. It looks like the options/values map is empty.

    This is strange because I tried a sample with your configuration and it doesn't fail. So the configuration itself is ok.

    Is it possible for you to provide a minimal project that shows the error?

    I will add a few validations to the plugin that will check & report problem with the options. It should help to understand why the options are empty.

  13. juliocauan commented on Feb 25, 2022

    @juliocauan

    sboot-api-atom-global.yaml:

    openapi: 3.0.3
    info:
      title: API Test
      description: 'Any API'
      termsOfService: http://swagger.io/terms/
      license:
        name: Apache 2.0
        url: http://www.apache.org/licenses/LICENSE-2.0.html
      version: 0.1.0
    externalDocs:
      description: Find out more about Swagger
      url: http://swagger.io
    servers:
      - url: https://sboot-api-global
      - url: http://sboot-api-global
    tags:
      - name: city
        description: Cities
    
    paths:
      /city:
        get:
          tags:
            - city
          summary: Find all existing Cities or by parameters
          operationId: findCities
          parameters:
            - name: number
              in: query
              description: Find by equals Number
              required: false
              style: form
              explode: true
              schema:
                type: string
            - name: nameContains
              in: query
              description: Find by contains Name
              required: false
              style: form
              explode: true
              schema:
                type: string
            - name: name
              in: query
              description: Find by equals Name
              required: false
              style: form
              explode: true
              schema:
                type: string        
            - name: nameStart
              in: query
              description: Find by Name starts with
              required: false
              style: form
              explode: true
              schema:
                type: string
            - name: nameFinish
              in: query
              description: Find by Name ends with
              required: false
              style: form
              explode: true
              schema:
                type: string
            - name: pageable
              in: query
              required: false
              schema:
                $ref: "#/components/schemas/Pageable"
          responses:
            405:
              description: Validation exception
            200:
              description: All found Cities
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/CityPage"
        post:
          tags:
            - city
          summary: Add a new City
          operationId: addCity
          requestBody:
            description: New City to add
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/CityAdd'
            required: true
          responses:
            201:
              description: City object successfully created
              content:
                application/json:
                  schema:
                    $ref: '#/components/schemas/CityResp'
            405:
              description: Invalid input
    
      /city/{cityId}:
        get:
          tags:
            - city
          summary: Find City by Id
          operationId: findCityById
          parameters:
            - name: cityId
              in: path
              description: City's Id to be found
              required: true
              schema:
                type: integer
                format: int32
          responses:
            200:
              description: City object successfully found
              content:
                application/json:
                  schema:
                    $ref: "#/components/schemas/CityResp"
            405:
              description: Validation exception
        delete:
          tags:
            - city
          summary: Delete a City
          operationId: deleteCity
          parameters:
            - name: cityId
              in: path
              description: City's Id to be deleted
              required: true
              schema:
                type: integer
                format: int32
          responses:
            204:
              description: City object successfully deleted
            400:
              description: Invalid ID supplied
            404:
              description: City not found
        put:
          tags:
            - city
          summary: Update an existent City
          operationId: updateCity
          parameters:
            - name: cityId
              in: path
              description: City's Id to be updated
              required: true
              schema:
                type: integer
                format: int32
          requestBody:
            description: City object to be updated
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/CityAdd'
            required: true
          responses:
            204:
              description: City object successfully updated
            405:
              description: Invalid input
    
    components:
      schemas:
        Pageable:
          description: minimal Pageable query parameters
          type: object
          properties:
            page:
              type: integer
            size:
              type: integer
        Page:
          description: minimal Page response without content property
          type: object
          properties:
            number:
              type: integer
            size:
              type: integer
        CityPage:
          description: typed Page
          type: object
          allOf:
            - $ref: "#/components/schemas/Page"
            - $ref: "#/components/schemas/CityResp"
    
        CityAdd:
          type: object
          required:
            - stateId
            - name
            - number
          properties:
            stateId:
              type: integer
              format: int32
              example: 1
            name:
              type: string
            number:
              type: integer
              format: int32
              example: 2903201
              maxLength: 7
              minLength: 7
        CityResp:
          type: object
          properties:
            id:
              type: integer
              format: int32
              example: 1
            stateId:
              type: integer
              format: int32
              example: 1
            name:
              type: string
            number:
              type: integer
              format: int32
              example: 2903201
              maxLength: 7
              minLength: 7
    

    Mapping.yaml:

    
    openapi-processor-mapping: v2
    
    options:
      package-name: br.cauan.test.rest
      model-name-suffix: DTO
      bean-validation: true
      javadoc: true
    
    map:
      types:
        - type: Pageable => org.springframework.data.domain.Pageable
        - type: Page => org.springframework.data.domain.Page
        - type: CityPage => org.springframework.data.domain.Page<{package-name}.model.CityResp>
        
    

    Is there anything else I should provide?

  14. hauner commented on Feb 26, 2022

    @hauner
    Member

    Hmm, how do you run it?

    I just noticed that when I run openapiprocessor:process directly it fails. It fails with same error you see. When I run it via lifecycle compile it works.

    No idea yet, what I'm doing wrong in the plugin. Looking into it.

  15. hauner commented on Feb 26, 2022

    @hauner
    Member

    Found something,

    looks like the <options> should be configured on <plugin> level and not at the <execution> level.

    I don't fully understand at the moment what the difference is. My maven know-how is a bit limited. ;-)

    Here is an example with the moved options:

    <plugin>
        <groupId>io.openapiprocessor</groupId>
        <artifactId>openapi-processor-maven-plugin</artifactId>
        <version>2021.1</version>
    
        <configuration>
            <id>openapi-generation</id>
            <apiPath>${project.basedir}/src/main/resources/swagger/openapi.yaml</apiPath>
    
            <!-- added options here -->
    
            <options>
                <values>
                    <targetDir>${project.basedir}/target/generated-sources</targetDir>
                    <mapping>${project.basedir}/src/main/resources/swagger/mapping.yaml</mapping>
                    <parser>OPENAPI4J</parser>
                    <showWarnings>true</showWarnings>
                </values>
            </options>
        </configuration>
    
        <executions>
            <execution>
                <id>openapi-generation</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>process</goal>
                </goals>
    
               <!-- removed configuration -->
    
            </execution>
        </executions>
    
        <dependencies>
            <dependency>
                <groupId>io.openapiprocessor</groupId>
                <artifactId>openapi-processor-spring</artifactId>
                <version>2022.1</version>
            </dependency>
        </dependencies>
    <plugin>
  16. hauner commented on Feb 26, 2022

    @hauner
    Member

    I learned a few things about maven today and I found a "simpler" solution.

    just change you original configuration

    before:

    <executions>
        <execution>
            <id>openapi-generation</id>
            <phase>generate-sources</phase>
        </execution>
    </executions>

    to

    after:

    <executions>
        <execution>
            <id>default-cli</id>
            <phase>generate-sources</phase>
        </execution>
    </executions>

    The <id> is different. If the id is default-cli maven will use the execution when running the goal directly with something like ./mvnw openapi-processor:process and it will also use it when the given phase is active.

  17. juliocauan commented on Feb 27, 2022

    @juliocauan

    Thanks Hauner!! This really solved my problem!

  18. hauner commented on Feb 28, 2022

    @hauner
    Member

    Thanks for reporting and for confirming that it helped. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions