Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify an endpoint's authorization is optional in openapi v3?

Tags:

openapi

I'm trying to document an existing API that contains various endpoints whose authentication is optional. That is, more data is returned if the user is authorized than if they were not authorized.

Could not find that explicitly in the OAspec v3. Is there a coding trick to define this situation?

My present work-around is to code for authorization, yet in a description of the endpoint write that authorization is optional. This works and seems adequate. Yet the purist in me wonders if there is another way.

like image 219
Mike Avatar asked Dec 05 '17 17:12

Mike


1 Answers

To make security optional, add an empty requirement {} to the security array:

security:
  - {}   # <----
  - api_key: []

This means the endpoint can be called with or without security.

Source: this comment in the OpenAPI Spec repository.

like image 177
Helen Avatar answered Sep 25 '22 00:09

Helen