Skip to content

Commit

Permalink
OpenApi spec securitySchema keys fix (#3811)
Browse files Browse the repository at this point in the history
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz>
Co-authored-by: Tim <hello@timsmart.co>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 1eb2c30 commit 02d413e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-spoons-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": patch
---

A bug related to the format of the security schema keys has been fixed. According to the OpenAPI specification, it must match the regular expression` ^[a-zA-Z0-9.-_]+$`
10 changes: 5 additions & 5 deletions packages/platform-node/test/fixtures/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"security": [
{
"Authorization/cookie": []
"cookie": []
}
],
"responses": {
Expand Down Expand Up @@ -96,7 +96,7 @@
],
"security": [
{
"Authorization/cookie": []
"cookie": []
}
],
"responses": {
Expand Down Expand Up @@ -153,7 +153,7 @@
"parameters": [],
"security": [
{
"Authorization/cookie": []
"cookie": []
}
],
"responses": {
Expand Down Expand Up @@ -242,7 +242,7 @@
],
"security": [
{
"Authorization/cookie": []
"cookie": []
}
],
"responses": {
Expand Down Expand Up @@ -538,7 +538,7 @@
}
},
"securitySchemes": {
"Authorization/cookie": {
"cookie": {
"type": "apiKey",
"name": "token",
"in": "cookie"
Expand Down
23 changes: 8 additions & 15 deletions packages/platform/src/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,14 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
})
}
function registerSecurity(
tag: HttpApiMiddleware.TagClassSecurityAny,
name: string,
security: HttpApiSecurity
): string {
const id = `${tag.key}/${name}`
if (spec.components!.securitySchemes![id]) {
return id
) {
if (spec.components!.securitySchemes![name]) {
return
}
const scheme = makeSecurityScheme(security)
spec.components!.securitySchemes![id] = scheme
return id
spec.components!.securitySchemes![name] = scheme
}
Option.map(Context.getOption(api.annotations, Description), (description) => {
spec.info.description = description
Expand All @@ -181,10 +178,8 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
return
}
for (const [name, security] of Object.entries(middleware.security)) {
const id = registerSecurity(middleware, name, security)
spec.security!.push({
[id]: []
})
registerSecurity(name, security)
spec.security!.push({ [name]: [] })
}
})
HttpApi.reflect(api as any, {
Expand Down Expand Up @@ -228,10 +223,8 @@ export const fromApi = <A extends HttpApi.HttpApi.Any>(self: A): OpenAPISpec =>
return
}
for (const [name, security] of Object.entries(middleware.security)) {
const id = registerSecurity(middleware, name, security)
op.security!.push({
[id]: []
})
registerSecurity(name, security)
op.security!.push({ [name]: [] })
}
})
endpoint.payloadSchema.pipe(
Expand Down

0 comments on commit 02d413e

Please sign in to comment.