跳到导航

HTTP JSON 端点

使用 application/json 内容类型记录 HTTP JSON API

以 Markdown 格式查看

OpenAPI 中的端点定义在 paths 键下。以下是定义单个端点的示例:

openapi.yml
paths:
/pets:
post:
summary: Create a new pet
description: Creates a new pet with the provided information
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'200':
description: User created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'

示例

您可以通过使用 examples 键来提供请求和响应的示例。

openapi.yml
paths:
/pets:
post:
summary: Create a new pet
description: Creates a new pet with the provided information
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
examples:
PetExample:
summary: This is an example of a Pet
value:
name: Markley
id: 44
responses:
'200':
description: A Pet object
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
examples:
PetExample:
summary: This is an example of a Pet
value:
name: Markley
id: 44