I have Spring 3 and Webflux application working in “Contract First” in swagger file, then i generante classes and doc with openapigenerator maven plugin.
In my Swagger i defined security and security Schemes based on this documentation
Key authentication documentation
on Swagger edirotr/ i can see the authorization button
we can also see the fields and on validation the CURL with headers executed
But on Local Swagger api documentation the authorization is not present, only if i had programatic i can see someting but not working well.
Any idea how i should do ?
here the local swagger generated
pom file
<code> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.21</version>
</dependency>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-boot</library>
<apiPackage>com.telr.tokenization.api</apiPackage>
<modelPackage>com.telr.tokenization.core.entities</modelPackage>
<supportingFilesToGenerate>false</supportingFilesToGenerate>
<configOptions>
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
<additionalModelTypeAnnotations>@lombok.Builder @lombok.AllArgsConstructor
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)
</additionalModelTypeAnnotations>
<hateoas>false</hateoas>
<reactive>true</reactive>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<useSpringBoot3>true</useSpringBoot3>
<useJakartaEe>true</useJakartaEe>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</code>
<code> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.21</version>
</dependency>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-boot</library>
<apiPackage>com.telr.tokenization.api</apiPackage>
<modelPackage>com.telr.tokenization.core.entities</modelPackage>
<supportingFilesToGenerate>false</supportingFilesToGenerate>
<configOptions>
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
<additionalModelTypeAnnotations>@lombok.Builder @lombok.AllArgsConstructor
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)
</additionalModelTypeAnnotations>
<hateoas>false</hateoas>
<reactive>true</reactive>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<useSpringBoot3>true</useSpringBoot3>
<useJakartaEe>true</useJakartaEe>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</code>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.21</version>
</dependency>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-boot</library>
<apiPackage>com.telr.tokenization.api</apiPackage>
<modelPackage>com.telr.tokenization.core.entities</modelPackage>
<supportingFilesToGenerate>false</supportingFilesToGenerate>
<configOptions>
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
<additionalModelTypeAnnotations>@lombok.Builder @lombok.AllArgsConstructor
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)
</additionalModelTypeAnnotations>
<hateoas>false</hateoas>
<reactive>true</reactive>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<useSpringBoot3>true</useSpringBoot3>
<useJakartaEe>true</useJakartaEe>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
and my yaml
<code>openapi: '3.1.0'
info:
version: 1.0.0
title: open api generator
termsOfService: http://swagger.io/terms/
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
contact:
name: Support
email: [email protected]
servers:
- url: http://localhost:8081
description: local
security:
- apiKey: []
apiSecret: []
paths:
/test:
post:
tags:
- test
summary: Create test
description: Create test
operationId: createTest
requestBody:
description: test object
content:
application/json:
schema:
$ref: '#/components/schemas/TestRequest'
required: true
responses:
'201':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/test/{id}:
get:
tags:
- "test"
summary: "get object"
description: "Returns object"
operationId: "getObject"
parameters:
- name: id
in: path
description: Gateway token generated in the network tokenization process
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Token not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
components:
schemas:
TestResponse:
type: object
properties:
id:
type: string
value:
type: string
TestRequest:
type: object
properties:
number:
type: string
description: The card number ex:1234 1234 1234 1243
ErrorResponse:
type: object
properties:
status:
type: integer
format: int32
description: Request status
type:
type: string
description: Error type
code:
type: string
description: Error code
errors:
type: array
items:
type: string
description: List of error messages
securitySchemes:
apiKey:
type: apiKey
name: X-API-KEY
in: header
apiSecret:
type: apiKey
name: X-API-SECRET
in: header
</code>
<code>openapi: '3.1.0'
info:
version: 1.0.0
title: open api generator
termsOfService: http://swagger.io/terms/
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
contact:
name: Support
email: [email protected]
servers:
- url: http://localhost:8081
description: local
security:
- apiKey: []
apiSecret: []
paths:
/test:
post:
tags:
- test
summary: Create test
description: Create test
operationId: createTest
requestBody:
description: test object
content:
application/json:
schema:
$ref: '#/components/schemas/TestRequest'
required: true
responses:
'201':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/test/{id}:
get:
tags:
- "test"
summary: "get object"
description: "Returns object"
operationId: "getObject"
parameters:
- name: id
in: path
description: Gateway token generated in the network tokenization process
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Token not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
components:
schemas:
TestResponse:
type: object
properties:
id:
type: string
value:
type: string
TestRequest:
type: object
properties:
number:
type: string
description: The card number ex:1234 1234 1234 1243
ErrorResponse:
type: object
properties:
status:
type: integer
format: int32
description: Request status
type:
type: string
description: Error type
code:
type: string
description: Error code
errors:
type: array
items:
type: string
description: List of error messages
securitySchemes:
apiKey:
type: apiKey
name: X-API-KEY
in: header
apiSecret:
type: apiKey
name: X-API-SECRET
in: header
</code>
openapi: '3.1.0'
info:
version: 1.0.0
title: open api generator
termsOfService: http://swagger.io/terms/
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
contact:
name: Support
email: [email protected]
servers:
- url: http://localhost:8081
description: local
security:
- apiKey: []
apiSecret: []
paths:
/test:
post:
tags:
- test
summary: Create test
description: Create test
operationId: createTest
requestBody:
description: test object
content:
application/json:
schema:
$ref: '#/components/schemas/TestRequest'
required: true
responses:
'201':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/test/{id}:
get:
tags:
- "test"
summary: "get object"
description: "Returns object"
operationId: "getObject"
parameters:
- name: id
in: path
description: Gateway token generated in the network tokenization process
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestResponse'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'404':
description: Token not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
components:
schemas:
TestResponse:
type: object
properties:
id:
type: string
value:
type: string
TestRequest:
type: object
properties:
number:
type: string
description: The card number ex:1234 1234 1234 1243
ErrorResponse:
type: object
properties:
status:
type: integer
format: int32
description: Request status
type:
type: string
description: Error type
code:
type: string
description: Error code
errors:
type: array
items:
type: string
description: List of error messages
securitySchemes:
apiKey:
type: apiKey
name: X-API-KEY
in: header
apiSecret:
type: apiKey
name: X-API-SECRET
in: header