OpenAPITools / OpenAPITools/openapi-generator

[BUG] [MAVEN-PLUGIN] openapi specification errors reported although the spec is validated both by openapi and swagger validation tools

Open
#14,253 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

An API specification file validated by the openapi online tool AND by the swagger-cli validate tool without any errors, generates "false" errors when used with the openapi-generator-maven-plugin in order to generate some code. The reported errors are :

org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 3, Warning count: 6
Errors: 
	-attribute components.schemas.execSdifModel.items is missing
	-attribute components.schemas.avatarAndValuesReturnModel.items is missing
	-paths.'/requests/{uuid}'. Declared path parameter uuid needs to be defined as a path parameter in path or operation level
openapi-generator version
  • 6.2.1
  • 6.3.0-SNAPSHOT (built by myself on 2022-12-13)
OpenAPI declaration file content or url

The same errors are raised independently of the format, yaml or json.

Generation Details

All the details with the stack trace :

[INFO] 
VERBOSE MODE: ON. Additional debug options are injected
 - [debugOpenAPI] prints the OpenAPI specification as interpreted by the codegen
 - [debugModels] prints models passed to the template engine
 - [debugOperations] prints operations passed to the template engine
 - [debugSupportingFiles] prints additional data passed to the template engine
[INFO] [deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated in the 5.x release. Composed schema name: null. Title: null
[WARNING] /home/rhzj7430/dev/thingin/thingin-one-poc/backend/src/main/resources/swagger-original.yaml [0:0]: unexpected error in Open-API generation
org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 3, Warning count: 6
Errors: 
	-attribute components.schemas.execSdifModel.items is missing
	-attribute components.schemas.avatarAndValuesReturnModel.items is missing
	-paths.'/requests/{uuid}'. Declared path parameter uuid needs to be defined as a path parameter in path or operation level
Warnings: 
	-attribute components.schemas.execSdifModel.items is missing
	-attribute components.schemas.avatarAndValuesReturnModel.items is missing
	-paths.'/requests/{uuid}'. Declared path parameter uuid needs to be defined as a path parameter in path or operation level

    at org.openapitools.codegen.config.CodegenConfigurator.toContext (CodegenConfigurator.java:604)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:631)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:798)
    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.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:578)
    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)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)

The plugin configuration is the following :

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>${openapi-generator-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <verbose>true</verbose>
                            <skipValidateSpec>false</skipValidateSpec>
                            <inputSpec>${project.basedir}/src/main/resources/swagger-original.yaml</inputSpec>
                            <generatorName>java-vertx-web</generatorName>
                            <output>${project.build.outputDirectory}/generated-sources/java/</output>
                            <apiPackage>com.orange.thingin.api</apiPackage>
                            <modelPackage>com.orange.thingin.api.model</modelPackage>
                            <invokerPackage>com.orange.thingin</invokerPackage>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

just try to run the maven plugin with the given specification file.

Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at CodegenConfigurator.toContext and CodeGenMojo.execute, then reproduce the Maven plugin run with the linked swagger-original.yaml or JSON specification. Compare the generator's validation output with the OpenAPI and swagger-cli results; done means the reported validation behavior is consistent with the supplied specification and the reproduction is covered by the relevant generator checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.