cancel
Showing results for 
Search instead for 
Did you mean: 

Reference to a SecurityScheme

New Contributor

Reference to a SecurityScheme

Is there a way to reference the component securityScheme from a common swagger definitions so I do not need to duplicate it in each of my swagger definitions?  Like $ref http://somurl.com/component/securityScheme/oauthSample.  If so what is the syntax to add this globally and per path?

 

security:
- oauthSample:
- read
- write

 

security:
- oAuthSample: [write]

4 REPLIES 4
Moderator

Re: Reference to a SecurityScheme

You need to "import" the external security scheme definition into the "components/securitySchemes" section of the current file. Then you can define the global and path-level security requirements in the usual way.

components:
  securitySchemes:
    oauthSample:
      $ref: 'http://somurl.com/component/securityScheme/oauthSample'

security:
  - oauthSample:
      - read
      - write

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Contributor

Re: Reference to a SecurityScheme

Thanks for your response.  Swagger is giving me an error saying it can not resolve the reference.  I triple checked the path.  I even tried adding a reference from the same file as the securitySchemes that I am using and that is not resolving for the securitySchemes.  

 

Any other tips?

Moderator

Re: Reference to a SecurityScheme

Which Swagger tool do you mean - Swagger Editor, Swagger UI, Swagger Codegen, ...?


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Contributor

Re: Reference to a SecurityScheme

I am not sure.  It is an editor on https://app.swaggerhub.com/ where I am creating the API Yaml definitions.

New Here?
Join us and watch the welcome video:
Announcements