Skip to content

Commit

Permalink
feat: enhance OpenAPI specification to exclude sensitive fields from …
Browse files Browse the repository at this point in the history
…generated schemas
  • Loading branch information
BramSuurdje committed Dec 17, 2024
1 parent 02b4bd9 commit 18f5023
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/app/api/v1/openapi/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,22 @@ async function generateOpenAPISpec(): Promise<OpenAPIObject> {
required: true,
content: {
'application/json': {
schema: { $ref: `#/components/schemas/${modelName}` },
schema: {
type: 'object',
properties: {
...Object.fromEntries(
Object.entries(
spec.components!.schemas![modelName].properties,
).filter(
([key]) => !['id', 'createdAt', 'updatedAt'].includes(key),
),
),
},
required: spec.components!.schemas![modelName].required?.filter(
(field: string) =>
!['id', 'createdAt', 'updatedAt'].includes(field),
),
},
},
},
},
Expand Down Expand Up @@ -409,7 +424,23 @@ async function generateOpenAPISpec(): Promise<OpenAPIObject> {
required: true,
content: {
'application/json': {
schema: { $ref: `#/components/schemas/${modelName}` },
schema: {
type: 'object',
properties: {
...Object.fromEntries(
Object.entries(
spec.components!.schemas![modelName].properties,
).filter(
([key]) =>
!['id', 'createdAt', 'updatedAt'].includes(key),
),
),
},
required: spec.components!.schemas![modelName].required?.filter(
(field: string) =>
!['id', 'createdAt', 'updatedAt'].includes(field),
),
},
},
},
},
Expand Down

0 comments on commit 18f5023

Please sign in to comment.