OpenAPI 一些未知值
OpenAPI some unkown values
我正在读这个:OpenAPI 3.0 Tutorial
如果我正在看其中一个例子,有些事情我无法理解
openapi: 3.0.0
info:
version: 1.0.0
title: Simple API
description: A simple API to illustrate OpenAPI concepts
servers:
- url: https://example.io/v1
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
security:
- BasicAuth: []
paths:
/artists:
get:
description: Returns a list of artists
parameters:
- name: limit
in: query
description: Limits the number of items on a page
schema:
type: integer
- name: offset
in: query
description: Specifies the page number of the artists to be displayed
schema:
type: integer
responses:
'200':
description: Successfully returned a list of artists
content:
application/json:
schema:
type: array
items:
type: object
required:
- username
properties:
artist_name:
type: string
artist_genre:
type: string
albums_recorded:
type: integer
username:
type: string
'400':
description: Invalid request
content:
application/json:
schema:
type: object
properties:
message:
type: string
# ----- Added lines ----------------------------------------
post:
description: Lets a user post a new artist
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- username
properties:
artist_name:
type: string
artist_genre:
type: string
albums_recorded:
type: integer
username:
type: string
responses:
'200':
description: Successfully created a new artist
'400':
description: Invalid request
content:
application/json:
schema:
type: object
properties:
message:
type: string
# ---- /Added lines ----------------------------------------
为什么 /get
的响应包含:required: username
?这是什么意思 ?
如果我不需要基本身份验证,我可以删除此行吗?
为什么post
下面的requestBody
要写required: true
? post
包含 body 不是基本的 ?
您的问题的答案是:
为什么/get的响应包含:required: username?这是什么意思?如果我不需要基本身份验证,我可以删除此行吗?
Ans: 用户名是必需的意味着它是强制性的,即响应必须包含这个字段,其中有一些值。它与基本身份验证无关。所以,是的,如果应用程序未使用该行,您可以将其删除。
为什么post下面的requestBody需要写required: true? post 包含 body 不是基本的?
Ans: Required: true
这里不是强制写的。这是一个可选字段,post 必须有一个请求正文。是的,你是对的。 posts 必须包含请求正文,这是一个基本的东西。
如果您还有任何困惑,请告诉我。谢谢
我正在读这个:OpenAPI 3.0 Tutorial
如果我正在看其中一个例子,有些事情我无法理解
openapi: 3.0.0
info:
version: 1.0.0
title: Simple API
description: A simple API to illustrate OpenAPI concepts
servers:
- url: https://example.io/v1
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
security:
- BasicAuth: []
paths:
/artists:
get:
description: Returns a list of artists
parameters:
- name: limit
in: query
description: Limits the number of items on a page
schema:
type: integer
- name: offset
in: query
description: Specifies the page number of the artists to be displayed
schema:
type: integer
responses:
'200':
description: Successfully returned a list of artists
content:
application/json:
schema:
type: array
items:
type: object
required:
- username
properties:
artist_name:
type: string
artist_genre:
type: string
albums_recorded:
type: integer
username:
type: string
'400':
description: Invalid request
content:
application/json:
schema:
type: object
properties:
message:
type: string
# ----- Added lines ----------------------------------------
post:
description: Lets a user post a new artist
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- username
properties:
artist_name:
type: string
artist_genre:
type: string
albums_recorded:
type: integer
username:
type: string
responses:
'200':
description: Successfully created a new artist
'400':
description: Invalid request
content:
application/json:
schema:
type: object
properties:
message:
type: string
# ---- /Added lines ----------------------------------------
为什么
/get
的响应包含:required: username
?这是什么意思 ? 如果我不需要基本身份验证,我可以删除此行吗?为什么
post
下面的requestBody
要写required: true
?post
包含 body 不是基本的 ?
您的问题的答案是:
为什么/get的响应包含:required: username?这是什么意思?如果我不需要基本身份验证,我可以删除此行吗?
Ans: 用户名是必需的意味着它是强制性的,即响应必须包含这个字段,其中有一些值。它与基本身份验证无关。所以,是的,如果应用程序未使用该行,您可以将其删除。为什么post下面的requestBody需要写required: true? post 包含 body 不是基本的?
Ans:Required: true
这里不是强制写的。这是一个可选字段,post 必须有一个请求正文。是的,你是对的。 posts 必须包含请求正文,这是一个基本的东西。
如果您还有任何困惑,请告诉我。谢谢