Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Valid OpenAPI When JWTSecurity is Used #1758

Merged
merged 1 commit into from
Jun 15, 2018
Merged

Generate Valid OpenAPI When JWTSecurity is Used #1758

merged 1 commit into from
Jun 15, 2018

Conversation

EtienneDufresne
Copy link
Contributor

@EtienneDufresne EtienneDufresne commented Jun 15, 2018

Adding the "In" and "Name" field to the JWTSecurity scheme expression so it generates a valid OpenAPI securityDefinitions section.

Before this change, a design with the following security scheme would generate an invalid OpenAPI securityDefinitions section.

Design:

var jwtSecurity = dsl.JWTSecurity("jwt", func() {
	dsl.Description(`Secures endpoint by requiring a valid JWT token.`)
})

Output OpenAPI without these changes:

securityDefinitions:
  jwt:
    type: apiKey
    description: |
      Secures endpoint by requiring a valid JWT token.
      **Security Scopes**:

When copy pasted to https://editor.swagger.io/, the OpenAPI causes:

Schema error at securityDefinitions['jwt']
should have required property 'flow'
missingProperty: flow

Schema error at securityDefinitions['jwt'].type
should be equal to one of the allowed values
allowedValues: basic, oauth2

This change populates the required in and name fields when specifying an apiKey securityDefinitions and gets rid of the https://editor.swagger.io/ errors.

Output OpenAPI with these changes:

securityDefinitions:
  jwt:
    type: apiKey
    description: |
      Secures endpoint by requiring a valid JWT token.
      **Security Scopes**:
    name: Authorization
    in: header

For more information please see:

@EtienneDufresne EtienneDufresne changed the title Generate Valid OpenAPI with JWTSecurity Generate Valid OpenAPI When JWTSecurity is Used Jun 15, 2018
@raphael
Copy link
Member

raphael commented Jun 15, 2018

Thank you for the PR and the the details!

@raphael raphael merged commit 143d995 into goadesign:v2 Jun 15, 2018
@EtienneDufresne EtienneDufresne deleted the openapi-compatible-jwt-security-definition branch June 16, 2018 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants