Swagger url 生成的 json 缺少“securityschemes”组件

如何解决Swagger url 生成的 json 缺少“securityschemes”组件

生成的 swagger.json 缺少 securityscheme 组件。当我复制 url json 并将其粘贴到 swagger 编辑器中时,我得到 - enter image description here

生成的 swagger.json 文件中的 yaml 如下 -

openapi: 3.0.3
info:
  title: Test YAML
  version: 1.0.0
servers:
  - url: 'localhost'
    description: Inferred Url
tags:
  - name: device-controller
    description: the device API
  - name: api-controller
    description: API
paths:
  /api/device:
    get:
      tags:
        - ABCD
      summary: Device SUMMARY.
      description: Device DESCRIPTION.
      operationId: getDevice
      parameters:
        - name: X-Request-ID
          in: header
          description: 'request Id,will return in the response headers,and appear in logs'
          required: false
          schema:
            type: string
      responses:
        '200':
          description: list of commands set
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CommandSet'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: The specified resource was not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - BasicAuth: []
components:
  schemas:
    CommandSet:
      title: CommandSet
      required:
        - name
      type: object
      properties:
        id:
          type: string
          format: uuid
          example: 07da6fd8-5abc-4dc4-bcec-df309d123d17
        name:
          type: string
          example: Deny
    Error:
      title: Error
      type: object
      properties:
        code:
          type: string
          example: '400'
        message:
          type: string
          example: Bad Request

它不见了

components:
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic

我在资源文件夹下定义了以下yaml文件

openapi: 3.0.2
info:
  title: Policy APIs
  description: 'Policy APIs for manage Policy Sets,authorization policies,authentication policies,and policy elements.'
  version: 1.0.0
  license:
    name: Apache 2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
  contact:
    email: abc@gmail.com
servers:
  - url: 'https://{server}/v1/policy'
    variables:
      server:
        default: localhost
        description: The host where the API is rooted
security:
  - BasicAuth: []
paths:
  /device-admin/command-sets:
    parameters:
      - $ref: '#/components/parameters/XRequestIdHeader'
    get:
      summary: Device Admin - Return list of command sets.
      description: Device Admin - Return list of command sets.
      operationId: getDeviceAdminCommandSets
      tags:
        - Device Administration - Command Set
      responses:
        '200':
          description: list of commands set
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CommandSet'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
  parameters:
    XRequestIdHeader:
      in: header
      name: X-Request-ID
      description: 'request Id,and appear in logs'
      schema:
        type: string
      required: false
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: The specified resource was not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example: '{code: 404,message: The specified resource was not found}'
  schemas:
    CommandSet:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          example: DenyAllCommands
          description: Command used in Device Admin authorization policies
        id:
          type: string
          format: uuid
          example: 07da6fd8-5abc-4dc4-bcec-df309dbf4d17
    Error:
      type: object
      properties:
        code:
          type: string
          example: 400
        message:
          type: string
          example: Bad Request

如何在swagger url定义中获取securityscheme组件。 我正在使用 oas 3.x 和 openapi 生成器工具来生成 java 代码

解决方法

在 OpenAPI 3.0 中,您可以使用服务器数组为您的 API 指定一个或多个基本 URL。 server 替换了 OpenAPI 2.0 中使用的 host、basePath 和 scheme 关键字。每个服务器都有一个 url 和一个可选的 Markdown 格式的描述。

https://swagger.io/docs/specification/api-host-and-base-path/

Add server array in swagger spec

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?