简体   繁体   English

如何将 Springdoc Swagger UI 指向我自己的 YAML 文件而不是自动生成的文件?

[英]How to point Springdoc Swagger UI to my own YAML file instead of the auto-generated one?

I have created a Spring Boot RESTFul microservice and for the documentation, I have created a swagger.yaml file but I don't know how to run that file.我创建了一个 Spring 引导 RESTFul 微服务和文档,我创建了一个 swagger.yaml 文件,但我不知道如何运行该文件。 To create the swagger.yaml file, I have used OpenAPI Specification.为了创建 swagger.yaml 文件,我使用了 OpenAPI 规范。 I know that we have a Swagger UI feature to work with but I want to run my own created swagger.yaml file just because to get rid off lots of annotations.我知道我们有一个 Swagger UI 功能可以使用,但我想运行我自己创建的 swagger.yaml 文件只是为了摆脱大量注释。

openapi: 3.0.1

info:
title: Static Data Manager
description: This is Static data Manager Swagger
version: 1.0.0

servers:
- url: http://localhost:8184/
  description: Generated server url

tags:
- name: LookupController
  description: API of Lookups
- name: LookupDataController
  description: API of Lookups Data
- name: LookupLangController
  description: API of Lookups Lang
- name: TranslationController
  description: API of Translations

paths:
/translation:
get:
  tags:
    - TranslationController
  operationId: fetchAll
  summary: Get All Translations
  parameters:
    - name: text
      in: query
      required: false
      schema:
        type: string
    - name: code
      in: query
      required: false
      schema:
        type: string
    - name: lang
      in: query
      required: false
      schema:
        type: string
    - name: pageable
      in: query
      required: true
      schema:
        $ref: '#/components/schemas/Pageable'
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PageTranslationModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
put:
  tags:
    - TranslationController
  operationId: update
  summary: Update a Translation
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/TranslationModel'
    required: true
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/TranslationModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
post:
  tags:
    - TranslationController
  operationId: save
  summary: Save a Translations
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/TranslationModel'
    required: true
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/TranslationModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
/translation/{transId}:
get:
  tags:
    - TranslationController
  operationId: fetch
  summary: Fetch a Translation
  parameters:
    - name: transId
      in: path
      required: true
      schema:
        type: integer
        format: int64
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/TranslationModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
delete:
  tags:
    - TranslationController
  operationId: delete
  summary: Delete a Translation
  parameters:
    - name: transId
      in: path
      required: true
      schema:
        type: integer
        format: int64
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            type: object
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input

/lookupsLang:
get:
  tags:
    - LookupLangController
  operationId: fetchAll_1
  summary: Get All Lookup Langs
  parameters:
    - name: text
      in: query
      required: false
      schema:
        type: string
    - name: lang
      in: query
      required: false
      schema:
        type: string
    - name: sorting
      in: query
      required: false
      schema:
        type: string
    - name: pageable
      in: query
      required: true
      schema:
        $ref: '#/components/schemas/Pageable'
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PageLookupLangModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
put:
  tags:
    - LookupLangController
  operationId: update_1
  summary: Update a Lookup Lang
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/LookupLangModel'
    required: true
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupLangModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
post:
  tags:
    - LookupLangController
  operationId: save_1
  summary: Save a Lookup Lang
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/LookupLangModel'
    required: true
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupLangModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
/lookupsLang/{lookupId}:
get:
  tags:
    - LookupLangController
  operationId: fetch_1
  summary: Fetch a Lookup Lang
  parameters:
    - name: lookupId
      in: path
      required: true
      schema:
        type: integer
        format: int64
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupLangModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
delete:
  tags:
    - LookupLangController
  operationId: delete_1
  summary: Delete a Lookup Lang
  parameters:
    - name: lookupId
      in: path
      required: true
      schema:
        type: integer
        format: int64
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            type: object
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input

/lookupsData:
get:
  tags:
    - LookupDataController
  operationId: fetchAll_2
  summary: Get All Lookups Data
  parameters:
    - name: text
      in: query
      required: false
      schema:
        type: string
    - name: code
      in: query
      required: false
      schema:
        type: string
    - name: pageable
      in: query
      required: true
      schema:
        $ref: '#/components/schemas/Pageable'
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PageLookupDataModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
put:
  tags:
    - LookupDataController
  operationId: update_2
  summary: Update a Lookup Data
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/LookupDataModel'
    required: true
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupDataModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
post:
  tags:
    - LookupDataController
  operationId: save_2
  summary: Save a Lookup Data
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/LookupDataModel'
    required: true
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupDataModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
/lookupsData/{lookupId}:
get:
  tags:
    - LookupDataController
  operationId: fetch_2
  summary: Fetch a Lookup Data
  parameters:
    - name: lookupId
      in: path
      required: true
      schema:
        type: integer
        format: int64
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupDataModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
delete:
  tags:
    - LookupDataController
  operationId: delete_2
  summary: Delete a Lookup Data
  parameters:
    - name: lookupId
      in: path
      required: true
      schema:
        type: integer
        format: int64
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            type: object
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input

/lookups:
get:
  tags:
    - LookupController
  operationId: fetchAll_3
  summary: Get All Lookups
  parameters:
    - name: lookupName
      in: query
      required: false
      schema:
        type: string
    - name: text
      in: query
      required: false
      schema:
        type: string
    - name: code
      in: query
      required: false
      schema:
        type: string
    - name: pageable
      in: query
      required: true
      schema:
        $ref: '#/components/schemas/Pageable'
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PageLookupModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
put:
  tags:
    - LookupController
  operationId: update_3
  summary: Update a Lookup
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/LookupModel'
    required: true
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
post:
  tags:
    - LookupController
  operationId: save_3
  summary: Save a Lookup
  requestBody:
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/LookupModel'
    required: true
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
/lookups/{lookupId}:
get:
  tags:
    - LookupController
  operationId: fetch_3
  summary: Fetch a Lookup
  parameters:
    - name: lookupId
      in: path
      required: true
      schema:
        type: integer
        format: int64
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LookupModel'
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input
delete:
  tags:
    - LookupController
  operationId: delete_3
  summary: Delete a Lookup
  parameters:
    - name: lookupId
      in: path
      required: true
      schema:
        type: integer
        format: int64
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            type: object
    '401':
      description: Unauthorised
    '403':
      description: Forbidden
    '404':
      description: Invalid input

 components:
  schemas:
  TranslationModel:
    type: object
    properties:
      webId:
        type: integer
        format: int64
      clientId:
        type: integer
        format: int64
      text:
        type: string
      code:
        type: string
      lang:
        type: string
  LookupLangModel:
  type: object
  properties:
    webId:
      type: integer
      format: int64
    lookupDataId:
      type: integer
      format: int64
    clientId:
      type: integer
      format: int64
    text:
      type: string
    lang:
      type: string
    sorting:
      type: integer
      format: int32
LookupDataModel:
  type: object
  properties:
    webId:
      type: integer
      format: int64
    clientId:
      type: integer
      format: int64
    lookupId:
      type: integer
      format: int64
    startDate:
      type: string
      format: date-time
    endDate:
      type: string
      format: date-time
    description:
      type: string
    text:
      type: string
    code:
      type: string
    lookupName:
      type: string
    sorting:
      type: integer
      format: int32
    strAttribute1:
      type: string
    strAttribute2:
      type: string
    strAttribute3:
      type: string
    intAttribute1:
      type: integer
      format: int32
    intAttribute2:
      type: integer
      format: int32
    intAttribute3:
      type: integer
      format: int32
    status:
      type: integer
      format: int32
    lookupLangModels:
      type: array
      items:
        $ref: '#/components/schemas/LookupLangModel'
LookupModel:
  type: object
  properties:
    webId:
      type: integer
      format: int64
    clientId:
      type: integer
      format: int64
    startDate:
      type: string
      format: date-time
    endDate:
      type: string
      format: date-time
    lookupName:
      type: string
    status:
      type: integer
      format: int32
    lookupDataModels:
      type: array
      items:
        $ref: '#/components/schemas/LookupDataModel'
Pageable:
  type: object
  properties:
    offset:
      type: integer
      format: int64
    sort:
      $ref: '#/components/schemas/Sort'
    unpaged:
      type: boolean
    paged:
      type: boolean
    pageSize:
      type: integer
      format: int32
    pageNumber:
      type: integer
      format: int32
Sort:
  type: object
  properties:
    unsorted:
      type: boolean
    sorted:
      type: boolean
    empty:
      type: boolean
PageTranslationModel:
  type: object
  properties:
    totalPages:
      type: integer
      format: int32
    totalElements:
      type: integer
      format: int64
    size:
      type: integer
      format: int32
    content:
      type: array
      items:
        $ref: '#/components/schemas/TranslationModel'
    number:
      type: integer
      format: int32
    sort:
      $ref: '#/components/schemas/Sort'
    numberOfElements:
      type: integer
      format: int32
    first:
      type: boolean
    last:
      type: boolean
    pageable:
      $ref: '#/components/schemas/Pageable'
    empty:
      type: boolean
PageLookupLangModel:
  type: object
  properties:
    totalPages:
      type: integer
      format: int32
    totalElements:
      type: integer
      format: int64
    size:
      type: integer
      format: int32
    content:
      type: array
      items:
        $ref: '#/components/schemas/LookupLangModel'
    number:
      type: integer
      format: int32
    sort:
      $ref: '#/components/schemas/Sort'
    numberOfElements:
      type: integer
      format: int32
    first:
      type: boolean
    last:
      type: boolean
    pageable:
      $ref: '#/components/schemas/Pageable'
    empty:
      type: boolean
PageLookupDataModel:
  type: object
  properties:
    totalPages:
      type: integer
      format: int32
    totalElements:
      type: integer
      format: int64
    size:
      type: integer
      format: int32
    content:
      type: array
      items:
        $ref: '#/components/schemas/LookupDataModel'
    number:
      type: integer
      format: int32
    sort:
      $ref: '#/components/schemas/Sort'
    numberOfElements:
      type: integer
      format: int32
    first:
      type: boolean
    last:
      type: boolean
    pageable:
      $ref: '#/components/schemas/Pageable'
    empty:
      type: boolean
PageLookupModel:
  type: object
  properties:
    totalPages:
      type: integer
      format: int32
    totalElements:
      type: integer
      format: int64
    size:
      type: integer
      format: int32
    content:
      type: array
      items:
        $ref: '#/components/schemas/LookupModel'
    number:
      type: integer
      format: int32
    sort:
      $ref: '#/components/schemas/Sort'
    numberOfElements:
      type: integer
      format: int32
    first:
      type: boolean
    last:
      type: boolean
    pageable:
      $ref: '#/components/schemas/Pageable'
    empty:
      type: boolean

Make sure your custom yaml/json file is saved under resources/static folder.确保您的自定义 yaml/json 文件保存在 resources/static 文件夹下。 Then set springdoc.swagger-ui.url property to your file name.然后将springdoc.swagger-ui.url属性设置为您的文件名。

example例子

structure: resources -> static -> swagger-config.yaml结构:资源-> static-> swagger-config.yaml

property: springdoc.swagger-ui.url=/swagger-config.yaml属性: springdoc.swagger-ui.url=/swagger-config.yaml

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

相关问题 springdoc-openapi-ui生成的swagger-ui中如何更改请求header中授权key的名称 - How to change the name of the authorization key in the request header in the swagger-ui generated by springdoc-openapi-ui Spring Roo-在MySQL数据库中使用自己的ID而不是自动生成的密钥 - spring roo - using own id instead of auto-generated key in mysql database 无法确定如何访问由 swagger 自动生成的 jaxrs 服务器中的请求标头 - Cannot figure how to access request headers in a jaxrs server that is auto-generated by swagger 如何在PreparedStatement中使用自动生成的@Id? - How to use auto-generated @Id in PreparedStatement? 如何挂钩到自动生成的Java方法? - How to hook into an auto-generated Java method? 带有 springdoc-openapi-ui 的 Swagger UI 不显示生成的“@Controller”类中的 API - Swagger UI with springdoc-openapi-ui doesn't show the APIs in the generated "@Controller" class 如果我的所有文档 ID 都是自动生成的,如何在 Firestore 中查询用户信息? - How do I query a user's info in Firestore if all my document IDs are auto-generated? 如何将自动生成的 Java 类放在 Single.java 文件中? - How Do I Place Auto-generated Java Classes in a Single .java File? springdoc-openapi、swagger UI 中的 XML 示例 - XML examples in springdoc-openapi, swagger UI JAXB:如何使用Spring自动生成的类? - JAXB: How to use auto-generated classes from Spring?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM