我有以下YAML片段:
description: |
"API for bean consuming applications.
Examples: painted pony, lima bean"
Run Code Online (Sandbox Code Playgroud)
:尽管有引号,但Swagger编辑器将冒号()解释为特殊字符.
根据这个问题的公认答案,结肠不应该被视为特殊性质.
这是Swagger的错误还是在引用的文本文字中使用冒号所需的转义序列?
我尝试使用YAML规范找到它但放弃了.
我如何阅读该规范来回答这个问题?
YAML中的单引号(')和双引号(")之间有区别吗?
pipe(|)或大于(>)结构是否仅影响换行处理或特殊字符的处理?
我创建了一个使用个人帐户安全的asp.net webapi应用程序,以便默认启用Bearer令牌.它工作正常,所以我能够在Postman中测试它们没有问题.
当我尝试通过Swashbuckle集成Swagger UI时,问题就出现了.我通过以下方式安装了Swashbuckle:
Install-Package Swashbuckle
然后更改SwaggerConfig.cs:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.ApiKey("Token")
.Description("Filling bearer token here")
.Name("Authorization")
.In("header");
}
.EnableSwaggerUi(c =>
{
c.EnableApiKeySupport("Authorization", "header");
};
Run Code Online (Sandbox Code Playgroud)
启动我的应用程序并填写Bearer令牌:
但是当我运行需要授权的api请求时,它不起作用.这是截图:
承载令牌被添加到标头中的Authorization.但我仍然得到错误401.我想知道是否因为令牌被编码(SPACE被%20取代)?任何的想法?谢谢.
顺便说一句,我想知道如何在我的Swagger文档中添加/ token,以便我可以在Swagger UI中获取令牌.
我在Swagger中有一系列参数
"parameters": [
{
"name": "username",
"description": "Fetch username by username/email",
"required": false,
"type": "string",
"paramType": "query"
},
{
"name": "site",
"description": "Fetch username by site",
"required": false,
"type": "string",
"paramType": "query"
},
{
"name": "survey",
"description": "Fetch username by survey",
"required": false,
"type": "string",
"paramType": "query"
}
],
Run Code Online (Sandbox Code Playgroud)
必须填写一个参数但是哪个参数无关紧要,其他参数可以留空.有没有办法在Swagger中表现出来?
我正在尝试使用Swagger来描述我正在构建的web-api.问题是我无法理解如何描述复杂的json对象?
例如,如何描述这个对象:
{
name: "Jhon",
address: [
{
type: "home",
line1: "1st street"
},
{
type: "office",
line1: "2nd street"
}
]
}
Run Code Online (Sandbox Code Playgroud) 我有一个API,要么成功返回以下响应:
{
"result": "success",
"filename": "my-filename.txt"
}
Run Code Online (Sandbox Code Playgroud)
失败后如下:
{
"result": "error",
"message": "You must specify the xxx parameter."
}
Run Code Online (Sandbox Code Playgroud)
仅当请求成功时才指定filename属性,但如果出现错误则提供消息.这意味着消息和文件名属性是"可选的",但结果属性是必需的.
我尝试在定义中定义此响应对象,如下所示:
"my_response_object": {
"type": "object",
"properties": {
"result": {
"type": "string",
"description": "value of 'success' or 'error', indicated whether was successful",
"required": true
},
"message": {
"type": "string",
"description": "an error message if there was an issue",
"required": false
},
"filename": {
"type": "string",
"description": "the filename to return if the request was successful",
"required": false
}
}
}
Run Code Online (Sandbox Code Playgroud)
但似乎swagger不喜欢"required"属性,并将显示以下错误消息: …
所以我理解,如果我们想要身体参数,我们必须有一个模式,我这样做.问题是无论我如何尝试定义我的架构,它都不允许我有多个body参数.这是我尝试过的方法之一的示例.任何帮助都会很棒!
swagger: '2.0'
# This is your document metadata
info:
version: "0.0.1"
title: Todo App
schema: {
}
host: localhost:3000
schemes:
- http
- https
consumes:
- application/json
produces:
- application/x-www-form-urlencoded
basePath: /
paths:
# This is a path endpoint. Change it.
/tasks:
post:
description: |
Add 'Task' object.
parameters:
# An example parameter that is in query and is required
-
name: name
in: query
description: unique object task name
required: true
schema:
type: string
- name: description
in: …Run Code Online (Sandbox Code Playgroud) 我正在设计一个 API,我想定义一个枚举严重性,其值可以为低、中或高。在内部,严重性存储为整数,因此我想将它们分别映射到 2,1 和 0。有没有办法在 OpenAPI 定义中做到这一点?这就是我目前的严重性:
severity:
type: string
enum:
- HIGH
- MEDIUM
- LOW
Run Code Online (Sandbox Code Playgroud) 我有JSON模式文件,其中一个属性被定义为string或null:
"type":["string", "null"]
Run Code Online (Sandbox Code Playgroud)
转换为YAML(与OpenAPI/Swagger一起使用)时,它变为:
type:
- 'null'
- string
Run Code Online (Sandbox Code Playgroud)
但Swagger编辑器显示错误:
架构"类型"键必须是字符串
在OpenAPI中定义可空属性的正确方法是什么?
我尝试将Swagger与Microsoft WebAPI 2 一起使用.
目前,我在一个方法中进行了以下调用.
appBuilder
.ConfigureOAuth()
.UseWebApi(configuration)
.UseWelcomePage();
Run Code Online (Sandbox Code Playgroud)
如果我想使用Swagger,我必须使用这个URL" https:// localhost:44300/swagger "哪一个非常好用.
我希望我的主页重定向到我的招摇的网址,也许如下,但这个示例不起作用.
appBuilder
...
.UseWelcomePage("/swagger");
Run Code Online (Sandbox Code Playgroud)
任何的想法 ?
Spring REST Docs最近发布,文档说:
这种方法使您免受Swagger等工具的限制
所以,我想问一下,当Spring REST Docs与Swagger比较时,以及它可以解除的限制.