Closed SENIAN closed 3 years ago
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?
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 :-)
closing this one, the feature request moved to https://github.com/openapi-processor/openapi-processor-core/issues/77
since validation with the schema will probably not work I will take another look at the parser validation.
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
Thanks Hauner!
improved in 2021.6
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.
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.
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?
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.
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>
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.
Thanks Hauner!! This really solved my problem!
Thanks for reporting and for confirming that it helped. :-)
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:
OpenAPI SPEC: