【问题标题】:Swagger: disabling security on one particular pathSwagger:在一个特定路径上禁用安全性
【发布时间】:2015-03-12 21:30:19
【问题描述】:

我有一个以以下开头的 Swagger 文件

{
    "swagger": "2.0",
    "basePath": "/api",
    "schemes": [
        "https"
    ],
    "securityDefinitions": {
        "internalApiKey": {
            "type": "apiKey",
            "name": "AAuthorization",
            "in": "header"
        }
    },
    "security" : [
        { "internalApiKey": [ ] }
    ],

此序言将安全设置应用于文件中的每个路径。例如。

"paths": {
    "/foo": {
        "get": {  

有没有什么方法可以只禁用一个特定路径或方法的安全性?

【问题讨论】:

    标签: rest swagger


    【解决方案1】:

    当然。只需将"security" 属性添加到以空数组[] 作为值的操作。

    类似

    {
      "tags": [
        "pet"
      ],
      "summary": "Updates a pet in the store with form data",
      "description": "",
      "operationId": "updatePetWithForm",
      "consumes": [
        "application/x-www-form-urlencoded"
      ],
      "produces": [
        "application/json",
        "application/xml"
      ],
      "parameters": [
        {
          "name": "petId",
          "in": "path",
          "description": "ID of pet that needs to be updated",
          "required": true,
          "type": "string"
        }
      ],
      "responses": {
        "200": {
          "description": "Pet updated."
        }
      },
      "security": [
    
      ]
    }
    

    将取消此操作的安全性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-16
      • 2016-06-29
      • 2021-07-22
      • 1970-01-01
      • 2018-11-11
      • 2018-09-13
      • 2021-12-22
      • 2017-12-02
      相关资源
      最近更新 更多