swagger 从流浪汉到 Postman [副本]

58wvjzkj  于 2023-03-18  发布在  Postman
关注(0)|答案(1)|浏览(160)

此问题在此处已有答案

How do I combine multiple OpenAPI 3 specification files together?(5个答案)
2天前关闭。
我们有一个用Django rest框架编写的后端系统,我们使用了swagger docs,将每个部分的YAML文件编写在单独的文件中,知道我们正在迁移到postman,由于YAML文件是单独的,我无法将它们导入到postman。

swagger: "2.0"
info:
  description: "this is the swagger documentation for Petemoon project's APIs"
  version: "1.0.0"
  title: "Petemoon API"
host: "api.petemoon.com"
basePath: "/"
schemes:
  - "http"
  - "https"
  
paths:
  /accounts/otp:
    $ref: "./accounts/send_otp.yaml"
  /accounts/otp/verify:
    $ref: "./accounts/verify_otp.yaml"
  /accounts/refresh:
    $ref: "./accounts/refresh.yaml"
  /accounts/register:
    $ref: "./accounts/register.yaml"
  /accounts/register/petshop:
    $ref: "./accounts/register_petshop.yaml"
  /accounts/logout:
    $ref: "./accounts/logout.yaml"

我们有一个这样的模式文件,而API在文件中是这样的

post:
  tags:
    - "accounts"
  summary: "Send OTP to user's phone number"
  description: ""
  operationId: "send_otp"
  consumes:
    - "application/json"
  produces:
    - "application/json"
  parameters:
    - in: "body"
      name: "body"
      description: "Phone number to send OTP to"
      required: true
      schema:
        $ref: "#/definitions/Request"
  responses:
    200:
      description: "OTP sent successfully"
      schema:
        $ref: "#/definitions/Success"
    400:
      description: "Invalid phone number"
      schema:
        $ref: "#/definitions/InvalidPhoneNumber"
oxf4rvwz

oxf4rvwz1#

我找到了一个有效的解决办法

npm install speccy -g

speccy resolve schema.yaml -o spec-output.yaml

相关问题