OpenAPI Specification
符合OpenAPI规范 接口变更时,我们只需要更改对应的OpenAPI描述文件 让我们能专注于业务代码的开发
基础的OpenAPI描述文件
- openapi version
- info description
- paths restfull
paths endpoint(interface)
- Path Item Object (sub path route)
- Operation Object (medthod)
- Responses Object (status description content)
#### Responses Content
* The Content Field (application/json text/html)
* The Schema Object (Field: type)
#### 示例
openapi: 3.1.0
info:
title: Tic Tac Toe
description: |
This API allows writing down marks on a Tic Tac Toe board
and requesting the state of the board or of individual squares.
version: 1.0.0
paths:
# Whole board operations
/board:
get:
summary: Get the whole board
description: Retrieves the current state of the board and the winner.
responses:
"200":
description: "OK"
content:
application/json: # 响应体格式
schema:
type: object # 响应体是个object
properties: # 它的属性有:
winner: # winner,类型为string
type: string
enum: [".", "X", "O"] # winner的值只能为. X 或 O中的一个
description: |
Winner of the game. .
means nobody has won yet.
board: # board属性
type: array # 类型为数组
maxItems: 3 # 最大3个元素
minItems: 3 # 最小3个元素
items:
type: array # 数组的元素依然是数组
maxItems: 3 # 最大三个元素
minItems: 3 # 最小三个元素
items:
type: string # 这个数组的元素为string
enum: [".", "X", "O"] # 值只能为. X或O
description: |
Possible values for a board square.
.
means empty square.
...
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/16504862.html