我正在尝试将 openapi/swagger 文件导入 api 网关,但我无法按预期获得安全设置。我想要一个所有路径都需要的 api 密钥。
导入后在控制台中设置所需的 api 密钥有效,但这种解决方案是不可取的,同样有效的是单独设置每个路径中的安全字段,但我正在寻找一个全局解决方案。
当我尝试导入文件时,我收到以下警告:
Your API was not imported due to errors in the Swagger file.
Method 'GET' on resource '/' specified security,
but no custom authorizers were created and the extension
x-amazon-apigateway-auth was not set.
This method will be not be secured.
Run Code Online (Sandbox Code Playgroud)
如此看来,我要么需要一个 lambda 作为仅用于 api 密钥的自定义授权方(我不熟悉授权方,但如果我在设置所需的 api 密钥时不需要授权方,这似乎没有意义控制台);或者我需要对这个神秘的东西做一些x-amazon-apigateway-auth我找不到文档的事情(亚马逊在此处记录了所有其他 openapi 扩展)。
一个小例子如下:
openapi: 3.0.1
info:
title: test
version: 0
servers:
- url: "/"
security:
- ApiKey: …Run Code Online (Sandbox Code Playgroud) 我试图在 Swagger 中定义一个查询参数,其中包含来自预定义项目集的逗号分隔字符串,?fruits=Apples,Oranges,Bananas但我从 swagger 编辑器中收到以下错误
不应该有额外的属性 additionalProperty: 样式,爆炸
我在 Swagger 编辑器中尝试的是:
- in: query
name: fruits
style: form
explode: true
required: false
description: Filter by fruits
type: array
items:
type: string
enum:
- Apples
- Oranges
- Bananas
Run Code Online (Sandbox Code Playgroud) 我一直在寻找有关 OAS3 中继承的资源,但我得到的最接近的是https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md以上没有答案我是寻找。
这是工作示例
components:
schemas:
Pet:
properties:
no_legs:
description: "Number of legs"
type: number
example: 4
Duck:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
no_legs:
example: 2
properties:
no_legs:
description: 'Number of webbed feet'
Run Code Online (Sandbox Code Playgroud)
受规范启发的失败示例
Duck:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
no_legs:
description: 'Number of webbed feet'
example: 2
Run Code Online (Sandbox Code Playgroud)
我的问题是
我正在查看的覆盖功能是否可用/支持?
如果是这样,正确的做法是什么?
我知道我可以使用组合来解决这个问题,但我会重复很多定义。
来自 Soap、XSD、WSDL 领域,我试图找到一种方法来重用使用 OpenApi v3 时定义的一些模式。
目录结构:
地址.yaml
openapi: 3.0.1
info:
title: An include file to define an address
version: 1.0.0
paths: {}
components:
schemas:
Address:
type: object
properties:
id:
type: integer
format: int64
streetName:
type: string
streetNumber:
type: integer
format: int32
city:
type: string
postalCode:
type: string
format: date-time
country:
type: string
description: Allowed countries (just on purpose 3 to have an enum)
enum:
- Romania
- Belgium
- Hungary
Run Code Online (Sandbox Code Playgroud)
客户.yaml
openapi: 3.0.1
info:
title: An include file to …Run Code Online (Sandbox Code Playgroud) 我在 openapi 路径中遇到正则表达式问题。API中有必需的路径参数,必须是proxy+。问题是当我尝试使用proxy+参数将 openapi 文件导入 AWS API 时,由于正则表达式(路径参数不能有“+”符号)返回错误。
(在发布这个问题之前,我搜索了 StackOverflow 并且当前的帖子没有回答我的问题。我知道路径参数受正则表达式的限制,我正在寻找“代理”-“代理+”和swagger编辑器中错误差异的解决方案和 AWS)
这就是它的样子。
paths:
/test/{tablename}/{proxy+}:
options:
parameters:
- name: "tablename"
in: "path"
required: true
schema:
type: "string"
- name: "proxy+"
in: "path"
required: true
schema:
type: "string"
Run Code Online (Sandbox Code Playgroud)
来自 CLI 的 AWS 错误:
无法在路径“/test/{tablename}/{proxy+}”的资源上放置方法“OPTIONS”:指定的映射表达式无效:验证结果:警告:[],错误:[参数名称应与以下正则表达式匹配:^ [a-zA-Z0-9._$-]+$]
paths:
/test/{tablename}/{proxy+}:
options:
parameters:
- name: "tablename"
in: "path"
required: true
schema:
type: "string"
- name: "proxy"
in: "path"
required: true
schema:
type: "string"
Run Code Online (Sandbox Code Playgroud)
在这种情况下,AWS …
假设我有以下模式稍后使用$ref:
"schemas": {
"Order": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"petId": {
"type": "integer",
"format": "int64"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我有另一个与此类似的架构:
"schemas": {
"Order": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"itemId": {
"type": "integer",
"format": "int64"
}
}
}
Run Code Online (Sandbox Code Playgroud)
它们之间的唯一区别是itemIdand petId,我只想创建一个架构并传递itemId或petId引用时。如何做到这一点?有没有其他替代解决方案?
我正在为我的 API 实现 OpenAPI-3.0 规范,并且我计划使用稀疏字段集作为 GET 的参数。使用 style=deepObject 的参数示例有点稀疏,所以我不确定我是否完全正确。
- in: query
name: fields
style: deepObject
schema:
type: object
additionalProperties:
type: string
Run Code Online (Sandbox Code Playgroud)
我可以结合 deepObject 和 additionalProperties 选项吗?
我想支持这样的灵活查询参数输入:
GET /articles?include=author&fields[articles]=title,body&fields[people]=name
但我不想为每个资源和字段拼出每个选项。
我正在使用drf_yasgswagger 文档。当我在 AWS Application Load Balancer 后面发布我的 DRF 应用程序并将侦听器设置为侦听 443 HTTPS 并重定向到运行 DRF 的 EC2 时,swagger UI 试图将请求发送到端点http://example.com/status而不是例如https://example.com/status. 这会产生一个谷歌浏览器错误:
swagger-ui-bundle.js:71 Mixed Content: The page at 'https://example.com/swagger#/status/status_list' was loaded over HTTPS, but requested an insecure resource 'http://example.com/status'. This request has been blocked; the content must be served over HTTPS.
Run Code Online (Sandbox Code Playgroud)
所以我解决这个问题的解决方案是在drf_yasg.views.get_schema_view. 所以我的代码看起来像:
schema_view = get_schema_view(
openapi.Info(
title="Server Api Documentation",
default_version="v1",
description="",
url="http://example.com/status"
)
# noinspection PyUnresolvedReferences
swagger_patterns = [
path("", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui"),
Run Code Online (Sandbox Code Playgroud)
我希望能够不显式设置 …
我将 ASP.NET Core 3.0 与 Swashbuckle 5 一起使用。我正在尝试在 ASP.NET Core 3.0 中编写一个ISchemaFilterfor ProblemDetails。ProblemDetails返回许多不同的状态代码,例如 400、401、403、406、415、500 等。我想提供一个ProblemDetails取决于状态代码的不同示例。我怎样才能做到这一点?这是我为开始编写的一些代码,只需要填写空白:
public class ProblemDetailsSchemaFilter : ISchemaFilter
{
private static readonly OpenApiObject Status400ProblemDetails = new OpenApiObject()
{
["type"] = new OpenApiString("https://tools.ietf.org/html/rfc7231#section-6.5.1"),
["title"] = new OpenApiString("Bad Request"),
["status"] = new OpenApiInteger(StatusCodes.Status400BadRequest),
["traceId"] = new OpenApiString("00-982607166a542147b435be3a847ddd71-fc75498eb9f09d48-00"),
["errors"] = new OpenApiObject()
{
["property1"] = new OpenApiArray()
{
new OpenApiString("The property field is required"),
},
},
};
private static readonly OpenApiObject Status401ProblemDetails = new …Run Code Online (Sandbox Code Playgroud) openapi ×10
swagger ×6
asp.net-core ×1
django ×1
drf-yasg ×1
jhipster ×1
json-api ×1
openapi.net ×1
python ×1
springfox ×1
swagger-2.0 ×1
swagger-3.0 ×1
swagger-ui ×1
swashbuckle ×1