如何在 openAPI 中设置安全标头,以便使用 swagger 编辑器将其包含在所有请求中

问题描述

我想在 openapi.json 文件中设置一个认的安全标头,如“apiKey”。目的是让从 swagger-editor 调用的所有请求都具有“apiKey”。以下是我的 openapi.json 文件。我在 swagger-editor 中测试了这个文件。我没有在请求中得到“apiKey”。请帮忙。

我不想在我的服务(端点)定义范围内添加“header”参数。

{
  "components": {
    "schemas": {
      "connection": {
        "properties": {
          "connid": {
            "example": "Lims1_107c5a8c1799d4cf8bb5ce295ab38954","type": "string"
          }
        },"type": "object","required": [
          "connid"
        ]
      }
    },"securitySchemes": {
      "api_key": {
        "type": "apiKey","name": "api_key","in": "header"
      }
    }
  },"externalDocs": {
    "description": "Find out more about Test API","url": "http://www.Test.com/API"
  },"info": {
    "contact": {
      "email": "apiteam@Test.com"
    },"description": "Test Lims RESTful and CRUD API","license": {
      "name": "Apache 2.0","url": "http://www.Test.com/licenses/LICENSE-2.0.html"
    },"termsOfService": "http://www.Test.com/terms/","title": "Test Lims API - OpenAPI 3.0.2","version": "1.0.0"
  },"openapi": "3.0.2","paths": {
    "/rest/authenticate": {
      "description": "authenticate and get a token","summary": "authenticate and get a connection token","get": {
        "tags": [
          "connection"
        ],"operationId": "authenticate","parameters": [
          {
            "required": true,"schema": {
              "description": "TEST datasource to connect to","type": "string"
            },"in": "query","name": "username"
          },{
            "required": true,"schema": {
              "description": "password of the user","name": "password"
          },"name": "datasource"
          },"schema": {
              "description": "TEST Service to connect to","name": "service"
          },{
            "required": false,"schema": {
              "description": "User role","name": "role"
          }
        ],"responses": {
          "200": {
            "description": "Successful Connection","content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      }
    },"/rest/close": {
      "description": "authenticate and get a token","operationId": "close","schema": {
              "description": "id of the connection to close","name": "connectionid"
          }
        ],"/rest/function/ABS": {
      "description": "Answer the absolute value of the number\r\nx = ABS(number)","get": {
        "tags": [
          "REST API"
        ],"schema": {
              "type": "string"
            },"name": "number"
          }
        ],"responses": {
          "200": {
            "description": "Successful Operation","content": {
              "application/xml": {
                "schema": {
                  "format": "string","type": "string","title": "x"
                }
              },"application/json": {
                "schema": {
                  "format": "string","title": "x"
                }
              }
            }
          },"400": {
            "description": "Invalid funnction provided"
          },"405": {
            "description": "Validation Exception"
          }
        }
      }
    }
  },"security": [
    {
      "api_key": []
    }
  ],"servers": [
    {
      "url": "http://localhost:8080/Lims-REST/api/","description": "description"
    }
  ],"tags": [
    {
      "name": "connection","description": "Connection management API ","externalDocs": {
        "description": "Connection management API","url": "http://www.Test.com"
      }
    },{
      "name": "REST API","description": "Test's non-crud APIs","externalDocs": {
        "description": "Test's non-crud APIs",{
      "name": "objects","description": "Test CRUD Operations on selected table","externalDocs": {
        "description": "CRUD API Test Lims. Can be done on selected tables","url": "http://www.Test.com"
      }
    }
  ]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...