Skip to content

Commit 3cea447

Browse files
authored
Merge pull request #249 from sakiv/bugfix-248
Fixed bug to support x-amazon-* in security schemes. [BUG] #248
2 parents 989b3e9 + 861bb25 commit 3cea447

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/definitionGenerator.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,12 @@ class DefinitionGenerator {
920920
break;
921921
}
922922

923+
const extendedSpec = this.extendSpecification(securityScheme);
924+
925+
if (Object.keys(extendedSpec).length) {
926+
Object.assign(schema, extendedSpec);
927+
}
928+
923929
this.addToComponents(this.componentTypes.securitySchemes, schema, scheme);
924930
}
925931
}

test/unit/definitionGenerator.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,42 @@ describe("DefinitionGenerator", () => {
886886
).to.have.property("api_key");
887887
});
888888
});
889+
890+
describe("x-amazon-* extensions", () => {
891+
it("should add an x-amazon-* security scheme to components", function () {
892+
mockServerless.service.custom.documentation.securitySchemes = {
893+
x_amazon_api_key: {
894+
type: "apiKey",
895+
name: "x-amz-security-token",
896+
in: "header",
897+
"x-amazon-apigateway-authtype": "awsSigv4",
898+
},
899+
};
900+
901+
const definitionGenerator = new DefinitionGenerator(
902+
mockServerless,
903+
logger
904+
);
905+
definitionGenerator.createSecuritySchemes(
906+
mockServerless.service.custom.documentation.securitySchemes
907+
);
908+
909+
expect(definitionGenerator.openAPI).to.be.an("object");
910+
expect(definitionGenerator.openAPI.components).to.be.an("object");
911+
expect(definitionGenerator.openAPI.components).to.have.property(
912+
"securitySchemes"
913+
);
914+
expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an(
915+
"object"
916+
);
917+
expect(
918+
definitionGenerator.openAPI.components.securitySchemes
919+
).to.have.property("x_amazon_api_key");
920+
expect(
921+
definitionGenerator.openAPI.components.securitySchemes.x_amazon_api_key
922+
).to.have.property("x-amazon-apigateway-authtype");
923+
});
924+
});
889925
});
890926

891927
describe("createTags", () => {

0 commit comments

Comments
 (0)