1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

chore: support full path schemas (#5723)

This backwards compatible change allows us to specify a schema `id`
(full path) which to me feels a bit better than specifying the schema
name as a string, since a literal string is prone to typos.

### Before

```ts
requestBody: createRequestSchema(
    'createResourceSchema',
),
responses: {
    ...getStandardResponses(400, 401, 403, 415),
    201: resourceCreatedResponseSchema(
        'resourceSchema',
    ),
},
```

### After

```ts
requestBody: createRequestSchema(
    createResourceSchema.$id,
),
responses: {
    ...getStandardResponses(400, 401, 403, 415),
    201: resourceCreatedResponseSchema(
        resourceSchema.$id,
    ),
},
```
This commit is contained in:
Nuno Góis 2023-12-22 08:17:23 +00:00 committed by GitHub
parent c44601b33c
commit fb94138c5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -9,7 +9,9 @@ export const createRequestSchema = (
content: {
'application/json': {
schema: {
$ref: `#/components/schemas/${schemaName}`,
$ref: schemaName.startsWith('#')
? schemaName
: `#/components/schemas/${schemaName}`,
},
},
},

View File

@ -13,7 +13,9 @@ export const createResponseSchemas = (
export const schemaNamed = (schemaName: string): OpenAPIV3.MediaTypeObject => {
return {
schema: {
$ref: `#/components/schemas/${schemaName}`,
$ref: schemaName.startsWith('#')
? schemaName
: `#/components/schemas/${schemaName}`,
},
};
};
@ -62,7 +64,9 @@ export const resourceCreatedResponseSchema = (
content: {
'application/json': {
schema: {
$ref: `#/components/schemas/${schemaName}`,
$ref: schemaName.startsWith('#')
? schemaName
: `#/components/schemas/${schemaName}`,
},
},
},