Skip to content

--header parameter is ignored #234

Closed

Description

@derjust

Hi!
I'd like to use openapi-diff, but the access to my OpenAPI JSONs is protected by a Authorization (Bearer) token.

--header seems to be a perfect fit:

docker run openapitools/openapi-diff --header "Authorization=Bearer ABCD" https://host1/v3/api-docs/app https://host2/v3/api-docs/app

Though i always end with stacktraces of

ERROR [io.swagger.parser.util.RemoteUrl] - unable to read
java.io.IOException: Server returned HTTP response code: 401 for URL: https://host1/v3/api-docs/app
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1950)
	at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1945)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1944)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1514)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268)
	at io.swagger.parser.util.RemoteUrl.urlToString(RemoteUrl.java:138)
	at io.swagger.parser.Swagger20Parser.readWithInfo(Swagger20Parser.java:44)
	at io.swagger.parser.SwaggerParser.readWithInfo(SwaggerParser.java:34)
	at io.swagger.v3.parser.converter.SwaggerConverter.readLocation(SwaggerConverter.java:89)
	at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
	at org.openapitools.openapidiff.core.OpenApiCompare.readLocation(OpenApiCompare.java:116)
	at org.openapitools.openapidiff.core.OpenApiCompare.fromLocations(OpenApiCompare.java:90)
	at org.openapitools.openapidiff.core.OpenApiCompare.fromLocations(OpenApiCompare.java:77)
	at org.openapitools.openapidiff.cli.Main.main(Main.java:156)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: https://host1/v3/api-docs/app
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1900)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
	at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:3061)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderField(HttpsURLConnectionImpl.java:305)
	at io.swagger.parser.util.RemoteUrl.urlToString(RemoteUrl.java:135)
	... 8 more

I tried various ways to pass in the --header but only the format above is accepted - which makes sense looking at the code: https://github.com/OpenAPITools/openapi-diff/blob/master/cli/src/main/java/org/openapitools/openapidiff/cli/Main.java#L65

Though also looking at the code it seems that the header information is never passed on:
https://github.com/OpenAPITools/openapi-diff/blob/master/cli/src/main/java/org/openapitools/openapidiff/cli/Main.java#L156

A fix seems simple enough & I'm happy to provide PR; but am I missing something obvious that is missing?

Activity

  1. added this to the Release 2.0.0 milestone on May 24, 2021
  2. changed the title [-]--header is parameter ignored[/-] [+]`--header` parameter is ignored[/+] on May 24, 2021
  3. joschi commented on May 24, 2021

    @joschi
    Contributor

    @derjust Thanks for reporting this!

    Would you like to contribute you approach to fixing this (derjust@8849ef3) as a pull request?

  4. derjust commented on May 25, 2021

    @derjust
    ContributorAuthor

    @joschi yes i will do and create a PR

  5. added a commit that references this issue on May 26, 2021
  6. added a commit that references this issue on May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions