mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-27 11:02:16 +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:
parent
c44601b33c
commit
fb94138c5c
@ -9,7 +9,9 @@ export const createRequestSchema = (
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
$ref: `#/components/schemas/${schemaName}`,
|
||||
$ref: schemaName.startsWith('#')
|
||||
? schemaName
|
||||
: `#/components/schemas/${schemaName}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -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}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user