swagger-api / swagger-api/swagger-codegen

[JAVA] Global apiKey securityScheme requires OAuth dependency to compile

Open
#8,467 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I've configured a single securityScheme and applied it globally as per the 'Describing API Keys' example here: https://swagger.io/docs/specification/authentication/api-keys/

In the auth package OAuth classes are still generated and ApiClient references OAuth classes even though they cannot be used.

Swagger-codegen version
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>3.1.1</version>
Swagger declaration file content or url

https://api.openfigi.com/schema with modifications

@@ -25,6 +25,13 @@
         }
     }],
     "components": {
+        "securitySchemes": {
+            "ApiKeyAuth": {
+                "type": "apiKey",
+                "in": "header",
+                "name": "X-OPENFIGI-APIKEY"
+            }
+        },
         "schemas": {
             "MappingJob": {
                 "type": "object",
@@ -64,8 +71,7 @@
                             "type": "string"
                         }, {
                             "type": "integer"
-                        }],
-                        "default": "string"
+                        }]
                     },
                     "exchCode": {
                         "type": "string",
@@ -82,7 +88,7 @@
                     "marketSecDes": {
                         "type": "string",
                         "nullable": true
-                    },
+                    }
                 }
             },
             "BulkMappingJob": {
@@ -95,7 +101,7 @@
                 "type": "object",
                 "properties": {
                     "figi": {
-                        "type": "string",
+                        "type": "string"
                     },
                     "securityType": {
                         "type": "string",
@@ -169,7 +175,7 @@
             },
             "MappingJobResult": {
                 "oneOf": [{
-                    "$ref": "#/components/schemas/MappingJobResultFigiList",
+                    "$ref": "#/components/schemas/MappingJobResultFigiList"
                 }, {
                     "$ref": "#/components/schemas/MappingJobResultFigiNotFound"
                 }]
@@ -260,5 +266,8 @@
                 }
             }
         }
+    },
+    "security": {
+        "ApiKeyAuth": []
     }
 }
Suggest a fix/enhancement

I want to avoid adding a dependency on org.apache.oltu.oauth2 to my project

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce Java client generation with the modified OpenFIGI specification and inspect the generated auth package, ApiClient, and dependency configuration. The fix is complete when an apiKey-only security scheme generates a client that compiles without requiring org.apache.oltu.oauth2.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.