openapi-processor / openapi-processor-maven

maven plugin to run any openapi-processor
https://docs.openapiprocessor.io/maven
Apache License 2.0
7 stars 2 forks source link

Error in openapi-processor-maven-plugin #4

Closed adzubla closed 1 year ago

adzubla commented 1 year ago

I’m running the following configuration:

pom.xml:

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

mapping.yaml:

openapi-processor-mapping: v4

options:
  package-name: com.example.spec
  #model-name-suffix: Resource
  model-type: default
  bean-validation: jakarta
  javadoc: true
  generated-date: true
  #one-of-interface: true

map:
  # java type mappings

Logs:

[INFO] --- openapi-processor:2021.1:process (spring) @ petstore-oas-api ---
[INFO] Changes detected - generating target files!
[INFO] using (deprecated) OPENAPI4J parser
[ERROR] failed to validate mapping!
io.openapiprocessor.jsonschema.schema.DocumentLoaderException: failed to download 'http://json-schema.org/draft-07/schema'.
    at io.openapiprocessor.jsonschema.schema.DocumentLoader.loadDocument (DocumentLoader.java:30)
    at io.openapiprocessor.jsonschema.schema.ResolverContext.addDocument (ResolverContext.java:100)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.addDocument (ResolverRef.java:201)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.walkRef (ResolverRef.java:92)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.lambda$walkBucket$0 (ResolverRef.java:42)
    at java.util.LinkedHashMap.forEach (LinkedHashMap.java:721)
    at io.openapiprocessor.jsonschema.schema.Bucket.forEach (Bucket.java:354)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.walkBucket (ResolverRef.java:34)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.resolve (ResolverRef.java:24)
    at io.openapiprocessor.jsonschema.schema.Resolver.resolve (Resolver.java:102)
    at io.openapiprocessor.jsonschema.schema.SchemaStore.getSchema (SchemaStore.java:178)
    at io.openapiprocessor.jsonschema.schema.SchemaStore.getSchema (SchemaStore.java:153)
    at io.openapiprocessor.core.processor.MappingValidator.validate (MappingValidator.kt:36)
    at io.openapiprocessor.core.processor.MappingReader.validate (MappingReader.kt:77)
    at io.openapiprocessor.core.processor.MappingReader.read (MappingReader.kt:62)
    at io.openapiprocessor.core.converter.OptionsConverter.readMapping (OptionsConverter.kt:45)
    at io.openapiprocessor.core.converter.OptionsConverter.convertOptions (OptionsConverter.kt:35)
    at io.openapiprocessor.spring.processor.SpringProcessor.convertOptions (SpringProcessor.kt:122)
    at io.openapiprocessor.spring.processor.SpringProcessor.run (SpringProcessor.kt:39)
    at io.openapiprocessor.spring.processor.SpringService.run (SpringService.kt:30)
    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:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.net.ConnectException: Connection timed out: connect
    at sun.nio.ch.Net.connect0 (Native Method)
    at sun.nio.ch.Net.connect (Net.java:579)
    at sun.nio.ch.Net.connect (Net.java:568)
    at sun.nio.ch.NioSocketImpl.connect (NioSocketImpl.java:588)
    at java.net.Socket.connect (Socket.java:633)
    at java.net.Socket.connect (Socket.java:583)
    at sun.net.NetworkClient.doConnect (NetworkClient.java:183)
    at sun.net.www.http.HttpClient.openServer (HttpClient.java:531)
    at sun.net.www.http.HttpClient.openServer (HttpClient.java:636)
    at sun.net.www.http.HttpClient.<init> (HttpClient.java:279)
    at sun.net.www.http.HttpClient.New (HttpClient.java:384)
    at sun.net.www.http.HttpClient.New (HttpClient.java:406)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient (HttpURLConnection.java:1309)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0 (HttpURLConnection.java:1242)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect (HttpURLConnection.java:1128)
    at sun.net.www.protocol.http.HttpURLConnection.connect (HttpURLConnection.java:1057)
    at io.openapiprocessor.jsonschema.reader.UriReader.read (UriReader.java:34)
    at io.openapiprocessor.jsonschema.schema.DocumentLoader.loadDocument (DocumentLoader.java:28)
    at io.openapiprocessor.jsonschema.schema.ResolverContext.addDocument (ResolverContext.java:100)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.addDocument (ResolverRef.java:201)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.walkRef (ResolverRef.java:92)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.lambda$walkBucket$0 (ResolverRef.java:42)
    at java.util.LinkedHashMap.forEach (LinkedHashMap.java:721)
    at io.openapiprocessor.jsonschema.schema.Bucket.forEach (Bucket.java:354)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.walkBucket (ResolverRef.java:34)
    at io.openapiprocessor.jsonschema.schema.ResolverRef.resolve (ResolverRef.java:24)
    at io.openapiprocessor.jsonschema.schema.Resolver.resolve (Resolver.java:102)
    at io.openapiprocessor.jsonschema.schema.SchemaStore.getSchema (SchemaStore.java:178)
    at io.openapiprocessor.jsonschema.schema.SchemaStore.getSchema (SchemaStore.java:153)
    at io.openapiprocessor.core.processor.MappingValidator.validate (MappingValidator.kt:36)
    at io.openapiprocessor.core.processor.MappingReader.validate (MappingReader.kt:77)
    at io.openapiprocessor.core.processor.MappingReader.read (MappingReader.kt:62)
    at io.openapiprocessor.core.converter.OptionsConverter.readMapping (OptionsConverter.kt:45)
    at io.openapiprocessor.core.converter.OptionsConverter.convertOptions (OptionsConverter.kt:35)
    at io.openapiprocessor.spring.processor.SpringProcessor.convertOptions (SpringProcessor.kt:122)
    at io.openapiprocessor.spring.processor.SpringProcessor.run (SpringProcessor.kt:39)
    at io.openapiprocessor.spring.processor.SpringService.run (SpringService.kt:30)
    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:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
[WARNING] mapping is not valid!

Despite this error message, the output files are being generated.

Questions:

1 - There is an alternative to the deprecated OPENAPI4J parser? I could not find any in the documentation. 2 - Why is it trying to access 'http://json-schema.org/draft-07/schema' ? Can it be disabled? Will it happen at runtime? 3 - Why the warning about mapping not valid?

Thanks,

Eduardo.

hauner commented 1 year ago
  1. You can also use SWAGGER (using swagger OpenAPI parser) or INTERNAL (for my own OpenAPI parser). With SWAGGER you can (currently) only use OpenAPI 3.0, no validation. With INTERNAL you can use OpenAPI 3.0 with validation or 3.1 without validation (working on validation for 3.1)

    This information is "hidden" in the gradle docs, https://openapiprocessor.io/spring/2022.5/gradle.html. I will add this to maven docs.

  2. it tries to validate the mapping.yaml with its json schema (using draft 7) to warn about basic errors in the mapping.

    It can't be disabled. It will not happen at runtime. At runtime there is only the generated code.

    It should not try to connect json-schema.org. This looks like a missconfiguration of the json schema validator. I will check it.

  3. here it is probably only invalid because of the json-schema.org error. Normally it will give more details where the error is.

adzubla commented 1 year ago

I just copied from the example configuration and was not aware of the default implementation...

Removing <parser> from the plugin configuration solved the issue!

Thanks for your quick answer.

beeondev commented 1 year ago

Hello, Same as adzubla; the simpler is indeed to remove <parser> as sayed above, but sometime i can trigger the same bug even without; so i dig.

And i found that that code has been fixed with this commit, but it is not in 2023.3. we have to wait 2023.4. https://github.com/openapi-processor/openapi-processor-base/commit/974197c672e69205c7d4b8d00e47b2225c2f2778

For those like me that need a quick working version i just add a patch as a single jar containing only the fixed classe : "io\openapiprocessor\core\processor\MappingValidator.class" .

and then we can keep <parser> if we add an overrided patch in the openapi-processor-maven-plugin dependencies.

io.openapiprocessor openapi-processor-maven-plugin 2021.1 io.openapiprocessor openapi-processor-core-patch 2023.4 system ${project.basedir}/lib/io.openapiprocessor/openapi-processor-core-patch/2023.4/openapi-processor-core-patch-2023.4.jar io.openapiprocessor openapi-processor-spring 2023.3

Hope it help. patch.ZIP

hauner commented 1 year ago

the next release is on its way, probably next week.

hauner commented 1 year ago

fixed by openapi-processor-spring 2023.4