I am trying to merge the additional files schema in micronaut swagger UI. I think the file is not picked up during the build time, quite not sure how to set the correct path for the additional file.
Inside resource the additional file is present
In the application.yml configuration I have set the below configuration
micronaut:
openapi:
additional:
files= src/main/resources/swagger/swaggerSecuritySchemes.yml
swaggerSecuritySchemes.yml
securitySchemes:
Open Id Connect:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://falconidentityserver.azurewebsites.net/connect/authorize
tokenUrl: https://falconidentityserver.azurewebsites.net/connect/token
refreshUrl: ""
scopes:
openid: Open Id scope
profile: Name scope
email: Email scope
usePkceWithAuthorizationCodeGrant: true
In the build swagger yml file, those configuration are not present, I think the file is not picked during the build process, how do we set the path for additional files
From the micronaut documentation
micronaut.openapi.additional.files={project.home}/src/test/resources/swagger
what is project.home
?
I tried the below code in the build.gradle file, but it didn't merge anything from the other file
tasks.withType(JavaCompile).all {
options.fork = true
options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=swagger-ui.enabled=true,swagger-ui.theme=MATERIAL'
options.forkOptions.jvmArgs << '-Dmicronaut.openapi.additional.files=src/main/resources/swagger'
options.compilerArgs += ['--enable-preview']
}
Update 1
components:
securitySchemes:
Open Id Connect:
type: oauth2
flows:
authorizationCode:
authorizationUrl: https://falconidentityserver.azurewebsites.net/connect/authorize
tokenUrl: https://falconidentityserver.azurewebsites.net/connect/token
refreshUrl: ""
clientId: xxxxxxxxxx
clientSecret: xxxxx-xxxxxxxxxxxxx
scopes:
openid: Open Id scope
profile: Name scope
email: Email scope
usePkceWithAuthorizationCodeGrant: true
Including the above definition merged the configuration, however on final document the clientId , clientSecret and usePkceWithAuthorizationCodeGrant are not merged, why?
As the documentation states, in order:
To configure the path for additional swagger files you need to set System property micronaut.openapi.additional.files
micronaut.openapi.additional.files
should be added as a System property for your build, as, OpenAPI documentation is generated at build / compile time and not at runtime, hence adding this property to application.yml
(runtime) configuration will have no effect.
If you are using gradle , you can add this micronaut.openapi.additional.files
property either:
to command-line System properties when launching your build:
$./gradlew build -Dmicronaut.openapi.additional.files=src/main/resources/swagger
to your project gradle.properties thus avoiding to add the System property at each build:
systemProp.micronaut.openapi.additional.files=src/main/resources/swagger
If you are using maven , you can add the micronaut.openapi.additional.files
property either:
to command-line System properties as well when launching your build:
$ mvn clean compile -Dmicronaut.openapi.additional.files=src/main/resources/swagger
to your project descriptor pom.xml as a project property thus avoiding to add the System property at each build:
<properties> <micronaut.openapi.additional.files>src/main/resources/swagger</micronaut.openapi.additional.files> </properties>
Note that in both build tools configuration the micronaut.openapi.additional.files
property was pointing toward a directory path ( src/main/resources/swagger ) and not a file path as the documentation lacks mentioning that this property takes directories and not explicit files as its value.
As far as I know, the additional files does not support the securitySchemes
declaration and will only merge paths
documentation. But I may have missed some details and otherwise feel free to fire up an issue in the micronaut-openapi repository.
This worked for me try this:
step 1: Create a folder with name openapi
in the root directory.
step 2: Then manually create your yml in the openapi folder it self and mention your schemas
in file as per the (OpenAPI specification)
.
step 3: Now to merge both the files with the generated OpenAPI definition
. You need to point Micronaut to look for additional OpenAPI
yaml files in the openapi folder. So, you need to set the property micronaut.openapi.additional.files
To point micronaut to the openapi folder:
step 1: Look for the openapi.properties
file in the root directory. If the file is not present create one.
step 2: Once we have the file paste this inside the file -> micronaut.openapi.additional.files=openapi
Confirmation: To confirm that the micronaut is actually merging the file or not after this process. Pay attention to the logs while server is getting started...
If the process is a success, you should be able to see these:-
Note: Merging Swagger OpenAPI YAML files from location: whateverDirectory/openapi
Note: Reading Swagger OpenAPI YAML file YourFileName.yml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.