Mark the method anonymous: swagger version 3.0.2

I use Swagger-ui version 3.0.2 , I placed it locally and provided it with my Json file and an API that opens document fine and lists the whole method in the json file, after I included basic authentication in it, I made changes to the file .JSON, but there are some methods that I want to note anonymous.

{
    "swagger": "2.0",
    "info": {
        "description": "description",
        "version": "1.0",
        "title": "API"
    },
    "host": "localhost",
    "schemes": [
        "http"
    ],
    "securityDefinitions": {
        "anonymous_auth": {
            "type": ""
        },
        "basic_auth": {
            "type": "basic",
            "name": "basic_auth",
            "description": "Basic Authentication"
        },
        "token": {
            "type": "apiKey",
            "description": "API Token Authentication",
            "name": "apikey",
            "in": "header"
        }
    },
    "security": [
        {
            "basic_auth": [ ]
        },
        {
            "token": [ ]
        }
    ],
    "paths": {
        //somthing
    },
    "definitions": {  
        //something    
    }
}

Using the security attribute in this way, it will protect the complete file, but I have some methods that should be anonymous.

+4
source share
1 answer

To remove the global security, add an empty array securityto the operation:

"paths": {
  "/something:": {
    "get": {
      "security": [],
      ...
    }
  }
}


, :

  • anonymous_auth.

  • name basic_auth - name apiKey, , API.

+2

Source: https://habr.com/ru/post/1672992/


All Articles