Skip to content

[BUG] Java clients generated via inputSpecRootDirectory ignore securitySchemas in YAML #21130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 of 6 tasks
vhbcm opened this issue Apr 23, 2025 · 0 comments
Open
3 of 6 tasks

Comments

@vhbcm
Copy link

vhbcm commented Apr 23, 2025

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue? Here: https://github.com/wilx/inputSpecRootDirectory-issue
  • Have you validated the input using an OpenAPI validator (example)? ­— It is trivial and I can't access the site from here.
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs? — Yes and I did not find anything relevant.
  • What's the actual output vs expected output? — See the reproducer project at and its README.md
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

See the diff in the reproducer project at https://github.com/wilx/inputSpecRootDirectory-issue#. The issue manifests as missing authentication schemas in the ApiClient.java when the Maven plugin is using inputSpecRootDirectory. The difference is this:

--- ./using-inputSpec/target/generated-sources/openapi/src/main/java/com/example/ApiClient.java	2025-04-23 11:07:03.367877854 +0200
+++ ./using-inputSpecRootDirectory/target/generated-sources/openapi/src/main/java/com/example/ApiClient.java	2025-04-23 11:07:04.889861008 +0200
@@ -1,6 +1,6 @@
 /*
- * Minimal Bearer Auth API
- * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
+ * merged spec
+ * merged spec
  *
  * The version of the OpenAPI document: 1.0.0
  * 
@@ -58,16 +58,7 @@ public class ApiClient {
   public ApiClient(String[] authNames) {
     this();
     for(String authName : authNames) {
-      Interceptor auth = null;
-      if ("bearerAuth".equals(authName)) {
-
-        auth = new HttpBearerAuth("bearer");
-      } else {
-        throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
-      }
-      if (auth != null) {
-        addAuthorization(authName, auth);
-      }
+      throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
     }
   }
 
@@ -103,7 +94,7 @@ public class ApiClient {
   public void createDefaultAdapter() {
     json = new JSON();
 
-    String baseUrl = "https://api.example.com/v1";
+    String baseUrl = "http://localhost:8080";
     if (!baseUrl.endsWith("/"))
       baseUrl = baseUrl + "/";
openapi-generator version

7.12.0

OpenAPI declaration file content or url

The same file that is in the reproducer project. The issue is not the YAML itself.

openapi: 3.0.3
info:
  title: Minimal Bearer Auth API
  version: 1.0.0

servers:
  - url: https://api.example.com/v1

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

security:
  - bearerAuth: []

paths:
  /user/profile:
    get:
      summary: Get user profile
      description: Retrieve profile information for the authenticated user.
      responses:
        '204':
          description: Successful response
Generation Details

Just run mvn clean install in the reproducer project root.

Steps to reproduce

See above. The difference is in the inputSpecRootDirectory vs inputSpec.

Related issues/PRs

🙅🏿

Suggest a fix

🤷‍♂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant