openapi-generator
openapi-generator copied to clipboard
[BUG] Description Security not working with inputSpecRootDirectory on Java client generator Maven
Bug Report Checklist
- [X] Have you provided a full/minimal spec to reproduce the issue?
- [X] Have you validated the input using an OpenAPI validator (example)?
- [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
When using the configuration inputSpecDirectory, a _merged_spec.yaml file is created and used to generate the Java client. The securityschemas of the merged files are ignored at this point and the client will be generated without any security authorization which results in following:
public ApiClient() {
init();
initHttpClient();
// Setup authentications (key: authentication name, value: authentication).
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
expected would be:
public ApiClient() {
init();
initHttpClient();
// Setup authentications (key: authentication name, value: authentication).
authentications.put("basicAuth", new HttpBasicAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
openapi-generator version
7.8.0
OpenAPI declaration file content or url
If you post the code inline, please wrap it with
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: "http: //petstore.swagger.io/v1"
paths:
/pets/{petId}:
get:
security:
- basicAuth: [
]
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
maxItems: 100
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Generation Details
<inputSpecRootDirectory>
${project.basedir}/src/main/resources/api-definitions
</inputSpecRootDirectory>
<!-- <skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged> -->
<generatorName>java</generatorName>
<library>okhttp-gson</library>
<generateApis>true</generateApis>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateModels>true</generateModels>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<skipValidateSpec>true</skipValidateSpec>
<generateSupportingFiles>true</generateSupportingFiles>
<apiPackage>your.app.api</apiPackage>
<modelPackage>your.app.model</modelPackage>
<output>${project.build.directory}/generated-sources</output>
<configOptions>
<useJakartaEe>true</useJakartaEe>
<oas3>true</oas3>
<useSpringController>true</useSpringController>
<useSpringfox>false</useSpringfox>
<sourceFolder>main/java</sourceFolder>
<!-- Use modern java8 date/time api -->
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<!-- Do not include any validation with the client -->
<useBeanValidation>false</useBeanValidation>
<performBeanValidation>false</performBeanValidation>
<interfaceOnly>false</interfaceOnly>
<useOptional>false</useOptional>
<!-- Make the models serializable -->
<serializableModel>true</serializableModel>
</configOptions>
Steps to reproduce
- add openapi-generator-maven-plugin to the project
- add a folder with definition in it
- use inputSpecRootDirectory pointing to that directory
- generate client
Suggest a fix
merge the securitySchemes of the files together and add them to the _merged_spec.yaml
Tested it out by adding it manually to the _merged_spec.yaml and it worked:
components:
securitySchemes:
basicAuth:
type: http
scheme: basic