5

来自 Soap、XSD、WSDL 世界,我试图找到一种方法来重用在使用 OpenApi v3 时定义的一些模式。

目录结构:

在此处输入图像描述

地址.yaml

openapi: 3.0.1
info:
  title: An include file to define an address
  version: 1.0.0
paths: {}
components:
  schemas:
    Address:
      type: object
      properties:
        id:
          type: integer
          format: int64
        streetName:
          type: string
        streetNumber:
          type: integer
          format: int32
        city:
          type: string
        postalCode:
          type: string
          format: date-time
        country:
          type: string
          description: Allowed countries (just on purpose 3 to have an enum)
          enum:
            - Romania
            - Belgium
            - Hungary  

客户.yaml

   openapi: 3.0.1
info:
  title: An include file to define an customer
  version: 1.0.0
paths: {}
components:
  schemas:
    Customer:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        address: $ref: './Address.yaml/#/components/schemas/Address'
    Customers:
        type: array
        items: $ref: '#/components/schemas/Customer'

客户API.yaml

   openapi: 3.0.1
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
servers:
  - url: 'https://api.example.com'
paths:
  /customers:
    get:
      summary: Returns a list of customers.
      description: will return all customers
      responses:
        '200':
          description: A list of customers.
          content:
            application/json:
              schema:
                $ref: '../models/Customer.yaml/#/components/schemas/Customers'

如何使用此结构与现有工具来验证和生成客户 API 的 Java 代码?

谢谢

4

1 回答 1

0

验证工具:

  1. https://github.com/IBM/openapi-validator
npm install -g @apidevtools/swagger-cli
swagger-cli validate CustomerApi.yaml
  1. https://github.com/APIDevTools/swagger-cli
npm install -g ibm-openapi-validator
lint-openapi CustomerApi.yaml

他们进行验证,包括参考。一旦 OpenAPI 有效,您将能够使用其他工具生成代码

于 2021-07-27T12:02:40.593 回答