简体   繁体   English

合并模式 swagger UI Micronaut

[英]Merging Schemas swagger UI Micronaut

I am trying to merge the additional files schema in micronaut swagger UI.我正在尝试在 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在 application.yml 配置中,我设置了以下配置

micronaut:
  openapi:
    additional:
      files= src/main/resources/swagger/swaggerSecuritySchemes.yml

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在构建swagger yml文件中,这些配置不存在,我认为在构建过程中没有选择文件,我们如何设置附加文件的路径

From the micronaut documentation来自 micronaut 文档

micronaut.openapi.additional.files={project.home}/src/test/resources/swagger

what is project.home ?什么是project.home

I tried the below code in the build.gradle file, but it didn't merge anything from the other file我在 build.gradle 文件中尝试了以下代码,但它没有合并其他文件中的任何内容

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更新 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?包括上面的定义合并了配置,但是在最终文档中clientIdclientSecretusePkceWithAuthorizationCodeGrant没有合并,为什么?

As the documentation states, in order:正如文档所述,按顺序:

To configure the path for additional swagger files you need to set System property micronaut.openapi.additional.files要配置其他 swagger 文件的路径,您需要设置系统属性 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. micronaut.openapi.additional.files应该作为系统属性添加到您的构建中,因为OpenAPI文档是在构建/编译时而不是在运行时生成的,因此将此属性添加到application.yml (运行时)配置将无效.

Gradle: Gradle:

If you are using gradle , you can add this micronaut.openapi.additional.files property either:如果您使用的是gradle ,则可以添加此micronaut.openapi.additional.files属性:

  • 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:到您的项目gradle.properties从而避免在每次构建时添加System 属性

     systemProp.micronaut.openapi.additional.files=src/main/resources/swagger

Maven: Maven:

If you are using maven , you can add the micronaut.openapi.additional.files property either:如果您使用的是maven ,则可以添加micronaut.openapi.additional.files属性:

  • 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:到您的项目描述符pom.xml作为项目属性,从而避免在每次构建时添加System 属性

     <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.请注意,在两个构建工具配置中, micronaut.openapi.additional.files属性指向目录路径( src/main/resources/swagger )而不是文件路径,因为文档没有提到此属性采用目录而不是显式文件作为它的价值。

As far as I know, the additional files does not support the securitySchemes declaration and will only merge paths documentation.据我所知,附加文件不支持securitySchemes声明,只会合并paths文档。 But I may have missed some details and otherwise feel free to fire up an issue in the micronaut-openapi repository.但我可能错过了一些细节,否则可以随意在micronaut-openapi存储库中引发问题

This worked for me try this:这对我有用,试试这个:

step 1: Create a folder with name openapi in the root directory.第一步:在根目录下创建一个名为openapi的文件夹。

step 2: Then manually create your yml in the openapi folder it self and mention your schemas in file as per the (OpenAPI specification) .第2步:然后在自己的openapi文件夹中手动创建您的yml,并根据(OpenAPI specification)在文件中提及您的schemas

step 3: Now to merge both the files with the generated OpenAPI definition .第 3 步:现在将这两个文件与generated OpenAPI definition合并。 You need to point Micronaut to look for additional OpenAPI yaml files in the openapi folder.您需要指向 Micronaut 以在 openapi 文件夹中查找其他OpenAPI yaml 文件。 So, you need to set the property micronaut.openapi.additional.files因此,您需要设置属性 micronaut.openapi.additional.files

To point micronaut to the openapi folder:将 micronaut 指向 openapi 文件夹:

step 1: Look for the openapi.properties file in the root directory.第 1 步:在根目录中查找openapi.properties文件。 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第 2 步:一旦我们将文件粘贴到文件中 -> micronaut.openapi.additional.files=openapi

Confirmation: To confirm that the micronaut is actually merging the file or not after this process.确认:在此过程之后确认 micronaut 是否实际上正在合并文件。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打开 swagger UI 会得到 404 with Micronaut - Opening swagger UI gives 404 with Micronaut 无法使用 micronaut 多模块项目 gradle build 访问 swagger ui - swagger ui not accessible with micronaut multi-module project gradle build Swagger UI - OAuth 2.0 配置,Micronaut 2.5.1 客户端 ID 和客户端密码在单独的配置中 - Swagger UI - OAuth 2.0 configuration with Micronaut 2.5.1 client ID and client secret in seperate configuration Swagger忽略引用模式的Schema属性 - Swagger ignores Schema properties for referenced schemas 将 Yaml 配置映射到 Micronaut swagger 开放 API 安全配置 - Mapped the Yaml configuration to Micronaut swagger open API security configuration Micronaut(Gradle 和 Java)- Swagger 启用安全性后无法访问集成视图 - Micronaut (Gradle & Java) - Swagger Integration Views not accessible with security enabled Swagger 打开 API 定义不适用于 Micronaut JWT 安全 Micronaut 版本 2.2.1 - Swagger open API definition not working with Micronaut JWT security Micronaut version 2.2.1 如何从 curl 或 postman 或 swagger Micronaut 传递值 @Body MultipartBody - How to pass the value @Body MultipartBody from curl or postman or swagger Micronaut Swagger UI 与 Play 框架 - Swagger UI with Play Framework Swagger UI 未在浏览器上呈现 - Swagger UI is not rendering on the browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM