标签: openapi

如何使用 Swagger 在 API 网关上全局设置 API 密钥安全性

我正在尝试将 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)

amazon-web-services swagger aws-api-gateway openapi

5
推荐指数
1
解决办法
733
查看次数

Swagger 中带有逗号分隔字符串的查询参数返回结构错误

我试图在 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)

swagger swagger-ui swagger-2.0 openapi

5
推荐指数
1
解决办法
1963
查看次数

有没有办法覆盖 OAS3 中的属性描述和示例?

我一直在寻找有关 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)

我的问题是

  • 我正在查看的覆盖功能是否可用/支持?

  • 如果是这样,正确的做法是什么?

我知道我可以使用组合来解决这个问题,但我会重复很多定义。

openapi

5
推荐指数
1
解决办法
1855
查看次数

带有外部引用验证的 OpenApi

来自 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)

swagger openapi openapi-generator

5
推荐指数
1
解决办法
436
查看次数

Swagger/OpenAPI 路径和 AWS API 中的正则表达式

我在 openapi 路径中遇到正则表达式问题。API中有必需的路径参数,必须是proxy+。问题是当我尝试使用proxy+参数将 openapi 文件导入 AWS API 时,由于正则表达式(路径参数不能有“+”符号)返回错误。

(在发布这个问题之前,我搜索了 StackOverflow 并且当前的帖子没有回答我的问题。我知道路径参数受正则表达式的限制,我正在寻找“代理”-“代理+”和swagger编辑器中错误差异的解决方案和 AWS)

这就是它的样子。

  1. 这段代码在 swagger 编辑器中没有返回错误,但不想在 AWS API 中导入,因为正则表达式:
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._$-]+$]

  1. 我试图从代理参数中删除“+”,但以这种方式将其保留在路径中:
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 …

swagger aws-api-gateway openapi

5
推荐指数
0
解决办法
1226
查看次数

在 OpenAPI 3 中将参数传递给 `$ref`

假设我有以下模式稍后使用$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引用时。如何做到这一点?有没有其他替代解决方案?

swagger openapi swagger-3.0

5
推荐指数
1
解决办法
334
查看次数

如何使用 OpenAPI-3.0 表达 JSON-API 稀疏字段集

我正在为我的 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 但我不想为每个资源和字段拼出每个选项。

json-api openapi

5
推荐指数
1
解决办法
677
查看次数

如何在 drf_yasg 中将方案从 HTTP 更改为 HTTPS?

我正在使用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)

我希望能够不显式设置 …

python django django-rest-framework openapi drf-yasg

5
推荐指数
2
解决办法
2347
查看次数

如何在 JHipster 中更新 Swagger UI 文档?

在我的 JHipster 应用程序中,我按照API 优先开发的官方说明手动更新了 OpenAPI 规范文件 (api.yml) 。

但是,文档(通过 Springfox 生成)不会更新,并且仍然列出了 api.yml 的原始(默认)内容中描述的端点。

根据Springfox 的文档,

所有内容都来自 webjar 约定,相对 url 采用以下形式:webjars/springfox-swagger-ui/2.9.2/swagger-ui.html

但是没有关于如何更新的消息。欢迎任何想法/线索。

谢谢!

jhipster springfox openapi

5
推荐指数
0
解决办法
750
查看次数

如何在 ASP.NET Core 3 和 Swashbuckle 5 中为问题详细信息编写 ISchemaFilter?

我将 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)

swagger swashbuckle asp.net-core openapi openapi.net

5
推荐指数
1
解决办法
1641
查看次数