Skip to content

Commit

Permalink
Update path transform to make the security key optional (#179)
Browse files Browse the repository at this point in the history
* Update path transform to make the security key optional

If the security key is present in a path swagger will take that definition over the global security one. By always adding this key we are disabling security globally. Modified the transform for a path to only set the key when values are found.

* fix(linting): error not related to my change ???? forced by commit hook
feat(security): Added the ability to disable security

By adding an empty @security tag to the jsdoc block for a path

* fix(test): test failed after making an unrelated change

These tests broke. I'm not sure why only making a change in
transforms/paths/index.js under the parsePath response
triggers the failures.

* fix(test): fixed tests and added a couple

Co-authored-by: Kevin Julián Martínez Escobar <kevinccbsg@gmail.com>
  • Loading branch information
gandazgul and kevinccbsg committed Sep 1, 2021
1 parent b5fdcca commit 62de8aa
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 65 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion test/e2e/configuration/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ const options = {
},
},
],
security: {
BearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
filesPattern: './main.js',
baseDir: __dirname,
};
Expand Down Expand Up @@ -82,11 +89,22 @@ test('should parse basic info', async () => {
},
},
],
security: undefined,
security: [
{
BearerAuth: [],
},
],
paths: {},
tags: [],
components: {
schemas: {},
securitySchemes: {
BearerAuth: {
bearerFormat: 'JWT',
scheme: 'bearer',
type: 'http',
},
},
},
};
const result = await processSwagger(options);
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/parameters/parameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ test('should parse parameters from jsdoc-example', async () => {
},
},
],
security: [],
tags: [],
},
},
Expand Down Expand Up @@ -110,7 +109,6 @@ test('should parse parameters from jsdoc-example', async () => {
},
},
],
security: [],
tags: [],
},
},
Expand Down
2 changes: 0 additions & 2 deletions test/transforms/paths/combineSchemas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ test('should parse jsdoc path response with oneOf keyword', () => {
summary: 'This is the summary of the endpoint',
parameters: [],
tags: [],
security: [],
responses: {
200: {
description: 'success response',
Expand Down Expand Up @@ -130,7 +129,6 @@ test('should parse jsdoc path reference params with allOf keyword', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [{
deprecated: false,
description: 'name param description',
Expand Down
5 changes: 0 additions & 5 deletions test/transforms/paths/formParameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('form requestBody tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
content: {
Expand Down Expand Up @@ -66,7 +65,6 @@ describe('form requestBody tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [
{
deprecated: false,
Expand Down Expand Up @@ -126,7 +124,6 @@ describe('form requestBody tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'name body description',
Expand Down Expand Up @@ -177,7 +174,6 @@ describe('form requestBody tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [
{
deprecated: false,
Expand Down Expand Up @@ -247,7 +243,6 @@ describe('form requestBody tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [
{
deprecated: false,
Expand Down
6 changes: 0 additions & 6 deletions test/transforms/paths/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('setPaths method', () => {
description: 'This is the description of the endpoint',
parameters: [],
tags: [],
security: [],
responses: {
200: {
description: 'success response',
Expand Down Expand Up @@ -79,7 +78,6 @@ describe('setPaths method', () => {
summary: 'This is the summary of the endpoint',
parameters: [],
tags: [],
security: [],
responses: {
200: {
description: 'success response',
Expand Down Expand Up @@ -125,7 +123,6 @@ describe('setPaths method', () => {
summary: 'This is the summary of the endpoint',
parameters: [],
tags: [],
security: [],
responses: {
200: {
description: 'success response',
Expand All @@ -147,7 +144,6 @@ describe('setPaths method', () => {
summary: 'This is the summary of the endpoint',
parameters: [],
tags: [],
security: [],
responses: {
200: {
description: 'success response',
Expand Down Expand Up @@ -193,7 +189,6 @@ describe('setPaths method', () => {
summary: 'This is the summary of the endpoint',
parameters: [],
tags: [],
security: [],
responses: {
200: {
description: 'success response',
Expand All @@ -213,7 +208,6 @@ describe('setPaths method', () => {
summary: 'This is the summary of the endpoint',
parameters: [],
tags: [],
security: [],
responses: {
200: {
description: 'success response',
Expand Down
8 changes: 0 additions & 8 deletions test/transforms/paths/parameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('params tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
operationId: 'getInfo',
parameters: [{
deprecated: false,
Expand Down Expand Up @@ -56,7 +55,6 @@ describe('params tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
},
},
Expand All @@ -83,7 +81,6 @@ describe('params tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [{
deprecated: true,
description: 'name param description',
Expand Down Expand Up @@ -123,7 +120,6 @@ describe('params tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [{
deprecated: true,
description: 'name param description',
Expand Down Expand Up @@ -171,7 +167,6 @@ describe('params tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [{
deprecated: false,
description: 'name param description',
Expand Down Expand Up @@ -207,7 +202,6 @@ describe('params tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [{
deprecated: true,
description: 'name param description',
Expand Down Expand Up @@ -246,7 +240,6 @@ describe('params tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [{
deprecated: false,
description: 'name param description',
Expand Down Expand Up @@ -286,7 +279,6 @@ describe('params tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [{
deprecated: false,
description: 'name param description',
Expand Down
10 changes: 0 additions & 10 deletions test/transforms/paths/requestBody.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
},
},
Expand All @@ -44,7 +43,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'name body description',
Expand Down Expand Up @@ -83,7 +81,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: '',
Expand Down Expand Up @@ -124,7 +121,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'name body description',
Expand Down Expand Up @@ -166,7 +162,6 @@ describe('request body tests', () => {
summary: 'Delete messages listed under the specified tags',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'Tags of the messages to delete',
Expand Down Expand Up @@ -208,7 +203,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'name body description',
Expand Down Expand Up @@ -249,7 +243,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'name body description',
Expand Down Expand Up @@ -287,7 +280,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'name body description',
Expand Down Expand Up @@ -330,7 +322,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'name body description',
Expand Down Expand Up @@ -383,7 +374,6 @@ describe('request body tests', () => {
summary: '',
responses: {},
tags: [],
security: [],
parameters: [],
requestBody: {
description: 'name body description',
Expand Down

0 comments on commit 62de8aa

Please sign in to comment.