最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swagger - All operations must include the 'Authorization' header in the request parameters, except for the &

programmeradmin1浏览0评论

I am trying to create a custom rule in swagger to validate all API endpoints must include a Authorization' and 'key' header present except '/health' endpoint.

{
  "rules": {
    "Require Authorization Header": {
      "description": "All operations must include the 'Authorization' header in the request parameters, except for the '/health' endpoint.",
      "message": "All operations must include the 'Authorization' header in the request parameters, except for the '/health' endpoint.",
      "severity": "error",
      "given": "$.paths[?(@ != '/health')][*].parameters",
      "then": {
        "field": "[?(@.name == 'Authorization' && @.in == 'header')]",
        "function": "truthy"
      }
    }
  }

{
    "extends": [],
    "overrides": [],
    "rules": [
      {
        "name": "Validate Subscription Key Header",
        "severity": "error",
        "given": "$.paths[*][*].parameters",
        "then": {
          "field": "[?(@.name == 'Ocp-Apim-Subscription-Key' && @.in == 'header')]",
          "function": "truthy"
        },
        "message": "The 'Ocp-Apim-Subscription-Key' header must be included and marked as required for all endpoints."
      }
    ]
}

But some how this is not working as expected, Is they any way that we can achieve this?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论