OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.91k stars 6.58k forks source link

[BUG] openapi-generator-maven-plugin v7.7.0 ignores auth configuration parameter #19308

Open dschumka1999 opened 3 months ago

dschumka1999 commented 3 months ago

Bug Report Checklist

Description

openapi-generator-maven-plugin v7.7.0 ignores auth configuration parameter.

openapi-generator version

v7.7.0

Maven execution configuration
<configuration>
    <inputSpec>https://myhost.com/spec.yaml</inputSpec>
    <auth>Authorization: token</auth>
Steps to reproduce

Configure maven-plugin with an URL as inputSpec and an auth parameter. v7.6.0 and below work fine. Only v7.7.0 is affected.

Suggest a fix

org.openapitools.codegen.plugin.CodeGenMojo#createCollapsedSpec() org.openapitools.codegen.plugin.CodeGenMojo#calculateInputSpecHash() should respect and use the parameter auth for reading the inputSpec

This commit changed the correct behaviour for calculateInputSpecHash() and removed the evaluation of auth parameter: https://github.com/OpenAPITools/openapi-generator/pull/18849/commits/719c3bac30819e0bad58886321b46c70d7ace89c

szprutamich commented 3 months ago

affects v7.8.0 as well

mduggen commented 2 months ago

Hello,

does this bug result in following exceptions when executing the maven-plugin?

I'am asking cause we're using auth with an api key and it stops working with version 7.7.0 too. Otherwise I'll create another bug here.

jeremyspb commented 1 month ago

@mduggen Hello, I confirmed that the issue is reproduced in v 7.8.0 The root cause here: readLocation

In this file, CodeGenMojo does not parse and use auth parameter and passes always null instead. Meanwhile org.openapitools.codegen.config.CodegenConfigurator parses it and passes it correctly. As the result, generation is finished correctly, but hash calculation for future generation, that will check if specification is changed or not, cannot be finished.

In general it looks strange that the module tries to download it twice. It would be better to download it in local storage and reuse to calculate hash.

java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.OpenAPI.toString()" because the return value of "io.swagger.v3.parser.core.models.SwaggerParseResult.getOpenAPI()" is null
    at org.openapitools.codegen.plugin.CodeGenMojo.calculateInputSpecHash (CodeGenMojo.java:1007)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:979)
    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)

As the result of

java.io.FileNotFoundException: <string with url to gitlab link which requires authorization>
    at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance (DirectConstructorHandleAccessor.java:62)
    at java.lang.reflect.Constructor.newInstanceWithCaller (Constructor.java:502)
    at java.lang.reflect.Constructor.newInstance (Constructor.java:486)
    at sun.net.www.protocol.http.HttpURLConnection$10.run (HttpURLConnection.java:2055)
    at sun.net.www.protocol.http.HttpURLConnection$10.run (HttpURLConnection.java:2050)
    at java.security.AccessController.doPrivileged (AccessController.java:571)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException (HttpURLConnection.java:2049)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0 (HttpURLConnection.java:1619)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream (HttpURLConnection.java:1599)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream (HttpsURLConnectionImpl.java:223)
    at io.swagger.v3.parser.util.RemoteUrl.urlToString (RemoteUrl.java:155)
    at io.swagger.v3.parser.OpenAPIV3Parser.readContentFromLocation (OpenAPIV3Parser.java:290)
    at io.swagger.v3.parser.OpenAPIV3Parser.readLocation (OpenAPIV3Parser.java:95)
    at io.swagger.parser.OpenAPIParser.readLocation (OpenAPIParser.java:16)
    at org.openapitools.codegen.plugin.CodeGenMojo.calculateInputSpecHash (CodeGenMojo.java:1006)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:979)
fherling commented 1 month ago

Problem still exists in 7.9.0

wing328 commented 1 month ago

@Philzen can you please take a look at the issue when you've time as it's related to https://github.com/OpenAPITools/openapi-generator/commit/719c3bac30819e0bad58886321b46c70d7ace89c ?

SimoneDalka commented 1 week ago

Hi all,

is there a milestone for fixing this regression?

Thanks