2

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

enter image description here

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?

San Jaisy
  • 15,327
  • 34
  • 171
  • 290

2 Answers2

0

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.

Gradle:

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
    

Maven:

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>
    

Side Note

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.

tmarwen
  • 15,750
  • 5
  • 43
  • 62
  • Thanks for the info I tired the options.forkOptions.jvmArgs << '-Dmicronaut.openapi.additional.files=src/main/resources/swagger' in the build.gradle but nothing happens – San Jaisy Jan 15 '21 at 13:05
  • Here is the repository https://github.com/anandjaisy/micronuatswaggermerging – San Jaisy Jan 15 '21 at 14:33
  • Hey @SanJaisy, would you please update your thread to mention the EDIT post answer to allow for incremental information update. Would you add you compilation output as well please? – tmarwen Jan 15 '21 at 14:38
  • Have you taken my note on * securitySchemes* as well? As far as I can tell, the answer should be acceptable since the issue is with you yaml file content. – tmarwen Jan 15 '21 at 14:40
  • Well, I was referring to https://editor.swagger.io/. I need to merge the security schema, can you please guide me on how can I do that. – San Jaisy Jan 15 '21 at 15:01
  • maybe not the author's case but a warning to others - using a ".yaml" file instead of ".yml" will not work (not sure if this is a bug or some undocumented feature) – CodeFactory.DEV Jan 19 '21 at 09:05
  • @tmarwen can you please check my Update 1 text, the document is merged now, but some fields are not merged any idea ? – San Jaisy Jan 21 '21 at 04:11
0

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