Swagger 显示 'string' 而不是正文示例
Swagger shows 'string' instead of body example
我正在尝试为以下端点设置默认 json 正文:
const loginJsonSchema = {
'type': 'object',
'properties': {
'username': {
'type': 'string',
'example': 'my_user' // this property is ignored
},
'password': {
'type': 'string',
'example': 'my_password' // this property is ignored
},
},
'required': ['username', 'password'],
}
const paths = {
"/auth/login": {
"post": {
"tags": [
"auth"
],
"summary": "Login",
"description": "",
"operationId": "auth-login",
"consumes": [
"application/json"
],
"parameters": [
{
"name": "Credentials",
"in": "body",
"description": "Your credentials",
"required": true,
"schema": {
loginJsonSchema
}
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": loginSuccessResponseSchema,
},
},
}
},
代替示例值,我将默认正文设为 'string':
我期望以下默认正文:
{
"username": "my_user",
"password": "my_password"
}
您需要像这样从架构中删除额外的 { }:
const paths = {
"/auth/login": {
"post": {
"tags": [
"auth"
],
"summary": "Login",
"description": "",
"operationId": "auth-login",
"consumes": [
"application/json"
],
"parameters": [
{
"name": "Credentials",
"in": "body",
"description": "Your credentials",
"required": true,
"schema": loginJsonSchema
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": loginSuccessResponseSchema,
},
},
}
},
我正在尝试为以下端点设置默认 json 正文:
const loginJsonSchema = {
'type': 'object',
'properties': {
'username': {
'type': 'string',
'example': 'my_user' // this property is ignored
},
'password': {
'type': 'string',
'example': 'my_password' // this property is ignored
},
},
'required': ['username', 'password'],
}
const paths = {
"/auth/login": {
"post": {
"tags": [
"auth"
],
"summary": "Login",
"description": "",
"operationId": "auth-login",
"consumes": [
"application/json"
],
"parameters": [
{
"name": "Credentials",
"in": "body",
"description": "Your credentials",
"required": true,
"schema": {
loginJsonSchema
}
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": loginSuccessResponseSchema,
},
},
}
},
代替示例值,我将默认正文设为 'string':
我期望以下默认正文:
{
"username": "my_user",
"password": "my_password"
}
您需要像这样从架构中删除额外的 { }:
const paths = {
"/auth/login": {
"post": {
"tags": [
"auth"
],
"summary": "Login",
"description": "",
"operationId": "auth-login",
"consumes": [
"application/json"
],
"parameters": [
{
"name": "Credentials",
"in": "body",
"description": "Your credentials",
"required": true,
"schema": loginJsonSchema
}
],
"responses": {
"200": {
"description": "successful operation",
"schema": loginSuccessResponseSchema,
},
},
}
},