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.36k stars 6.46k forks source link

[BUG][Java][Client][Native] Java 11 native client generator doesn't support security and securitySchemes #6742

Open joschi opened 4 years ago

joschi commented 4 years ago

Bug Report Checklist

Description

The Java 11 Native HTTP client generator (native) doesn't support security and securitySchemes as described in https://swagger.io/docs/specification/authentication/ and https://swagger.io/specification/#security-scheme-object.

openapi-generator version

openapi-generator-cli 4.3.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Title
  version: 1.0.0
  description: Description
paths:
  /something:
    get:
      # Operation-specific security:
      security:
        - ApiKeyAuth: []
      responses:
        '200':
          description: OK (successfully authenticated)
# https://swagger.io/docs/specification/authentication/api-keys/
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY
security:
  - ApiKeyAuth: []
Command line used for generation
# wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/4.3.1/openapi-generator-cli-4.3.1.jar -O openapi-generator-cli.jar
# java -jar openapi-generator-cli.jar generate -i openapi.yaml -g java -o pkg/instana/openapi --skip-validate-spec -p dateLibrary=java8 --library native
Steps to reproduce

Use the OpenAPI spec from above and the command line mentioned above to generate the client.

No ApiKeyAuth class or any class related to authentication at all is being generated.

joschi commented 4 years ago

Users could create a custom request interceptor right now to emulate the functionality:

String myToken = "...";
ApiClient apiClient = new ApiClient();
apiClient.setRequestInterceptor(builder -> builder.header("Authorization", "apiToken " + myToken));

In my opinion this doesn't fulfill the expectation of the clients "just working", though.