openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open dschumka1999 opened this issue 1 year ago • 5 comments

Bug Report Checklist

  • [X] Have you provided a full/minimal spec to reproduce the issue?
  • [X] Have you tested with the latest master to confirm the issue still exists?
  • [X] Have you searched for related issues/PRs?
  • [X] What's the actual output vs expected output?
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

dschumka1999 avatar Aug 06 '24 14:08 dschumka1999

affects v7.8.0 as well

szprutamich avatar Aug 21 '24 15:08 szprutamich

Hello,

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

  • java.io.FileNotFoundException [inputSpecUrl] and
  • 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]

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.

mduggen avatar Sep 13 '24 11:09 mduggen

@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)

jeremyspb avatar Sep 24 '24 14:09 jeremyspb

Problem still exists in 7.9.0

fherling avatar Oct 12 '24 07:10 fherling

@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 ?

wing328 avatar Oct 12 '24 08:10 wing328

Hi all,

is there a milestone for fixing this regression?

Thanks

SimoneDalka avatar Nov 11 '24 15:11 SimoneDalka

The problem still exists in 7.10.0

szprutamich avatar Nov 26 '24 18:11 szprutamich

Hi, any news?

fherling avatar Jan 14 '25 00:01 fherling

@Philzen could you look at this?

szprutamich avatar Jan 20 '25 16:01 szprutamich