Skip to content

Commit

Permalink
Merge pull request #518 from AlexBroadbent/security-handlers-async-in…
Browse files Browse the repository at this point in the history
…itialize

Make initialize on Security Handlers async
  • Loading branch information
seriousme authored Oct 4, 2023
2 parents 61b3105 + f83b65b commit fce827b
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/securityHandlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The [OpenApi](https://www.openapis.org/) `Operation` object allows for security requirements that specify which security scheme(s) should be applied to this operation. OpenApi also allows for global security requirements via the `/components/security` property (v3) or the `/security` property (v2).

You can specify your own securityHandlers with the `securityHandlers` option.
If the provided object has an `initialize` function then fastify-openapi-glue will call this function with the `/components/securitySchemes` property (v3) or the `/securityDefinitions` property (v2) of the specification provided.
If the provided object has an async `initialize` function then fastify-openapi-glue will call this function with the `/components/securitySchemes` property (v3) or the `/securityDefinitions` property (v2) of the specification provided.

### Example

Expand Down
2 changes: 1 addition & 1 deletion examples/generated-javascript-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@seriousme/openapi-schema-validator": "^2.1.1",
"js-yaml": "^4.1.0",
"minimist": "^1.2.8",
"fastify-openapi-glue": "^4.3.2"
"fastify-openapi-glue": "^4.3.3"
},
"devDependencies": {
"fastify": "^4.23.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/generated-javascript-project/security.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// implementation of the security schemes in the openapi specification

export class Security {
initialize(schemes) {
async initialize(schemes) {
// schemes will contain securitySchemes as found in the openapi specification
console.log("Initialize:", JSON.stringify(schemes));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/generated-standaloneJS-project/security.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// implementation of the security schemes in the openapi specification

export class Security {
initialize(schemes) {
async initialize(schemes) {
// schemes will contain securitySchemes as found in the openapi specification
console.log("Initialize:", JSON.stringify(schemes));
}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function getSecurity(instance, securityHandlers, config) {
checkObject(securityHandlers, "securityHandlers");
const security = new SecurityHandlers(securityHandlers);
if ("initialize" in securityHandlers) {
securityHandlers.initialize(config.securitySchemes);
await securityHandlers.initialize(config.securitySchemes);
}
createSecurityHandlers(instance, security, config);
return security;
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/js/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (data) => {
return `// implementation of the security schemes in the openapi specification
export class Security {
initialize(schemes) {
async initialize(schemes) {
// schemes will contain securitySchemes as found in the openapi specification
console.log("Initialize:", JSON.stringify(schemes));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/standaloneJS/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (data) => {
return `// implementation of the security schemes in the openapi specification
export class Security {
initialize(schemes) {
async initialize(schemes) {
// schemes will contain securitySchemes as found in the openapi specification
console.log("Initialize:", JSON.stringify(schemes));
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-securityHandlers.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ test("initalization of securityHandlers succeeds", (t) => {
specification: testSpec,
serviceHandlers,
securityHandlers: {
initialize: (securitySchemes) => {
initialize: async (securitySchemes) => {
const securitySchemeFromSpec = JSON.stringify(
testSpec.securityDefinitions,
);
Expand Down
2 changes: 1 addition & 1 deletion test/test-securityHandlers.v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ test("initalization of securityHandlers succeeds", (t) => {
specification: testSpec,
serviceHandlers,
securityHandlers: {
initialize: (securitySchemes) => {
initialize: async (securitySchemes) => {
const securitySchemeFromSpec = JSON.stringify(
testSpec.components.securitySchemes,
);
Expand Down
2 changes: 1 addition & 1 deletion test/test-swagger-noBasePath.v2.javascript.checksums.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"security": {
"fileName": "security.js",
"checksum": "6830b20e7a63ea9baa95575e901927e29944d6c51a4306e182a2ed3a599c1d80"
"checksum": "e75dac6f2199a27e5517fac04d677ee7711a6c7d99374fef9cd84269e493b4db"
},
"plugin": {
"fileName": "index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"security": {
"fileName": "security.js",
"checksum": "6830b20e7a63ea9baa95575e901927e29944d6c51a4306e182a2ed3a599c1d80"
"checksum": "e75dac6f2199a27e5517fac04d677ee7711a6c7d99374fef9cd84269e493b4db"
},
"plugin": {
"fileName": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion test/test-swagger.v2.javascript.checksums.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"security": {
"fileName": "security.js",
"checksum": "daf2a6d2e22dcaccbe41629835b1aff054cbff578b470927713c3ca175c0b354"
"checksum": "78442cf521da3a908d4ec2b3842938972a0220d82bf078fd6eb57ade2cdb330d"
},
"plugin": {
"fileName": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion test/test-swagger.v2.standaloneJS.checksums.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"security": {
"fileName": "security.js",
"checksum": "daf2a6d2e22dcaccbe41629835b1aff054cbff578b470927713c3ca175c0b354"
"checksum": "78442cf521da3a908d4ec2b3842938972a0220d82bf078fd6eb57ade2cdb330d"
},
"plugin": {
"fileName": "index.js",
Expand Down
Empty file modified test/update-checksums.js
100644 → 100755
Empty file.

0 comments on commit fce827b

Please sign in to comment.