mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-04 01:18:20 +02:00
OpenAPI: remaining schema updates (#4354)
This fixes the last few exceptions to our meta schema validation
This commit is contained in:
parent
df59b10fb6
commit
4ab8accf5c
@ -129,7 +129,8 @@ import {
|
|||||||
updateFeatureStrategySchema,
|
updateFeatureStrategySchema,
|
||||||
updateTagTypeSchema,
|
updateTagTypeSchema,
|
||||||
updateUserSchema,
|
updateUserSchema,
|
||||||
upsertContextFieldSchema,
|
createContextFieldSchema,
|
||||||
|
updateContextFieldSchema,
|
||||||
upsertSegmentSchema,
|
upsertSegmentSchema,
|
||||||
createStrategySchema,
|
createStrategySchema,
|
||||||
updateStrategySchema,
|
updateStrategySchema,
|
||||||
@ -335,7 +336,8 @@ export const schemas: UnleashSchemas = {
|
|||||||
updateTagTypeSchema,
|
updateTagTypeSchema,
|
||||||
updateUserSchema,
|
updateUserSchema,
|
||||||
updateTagsSchema,
|
updateTagsSchema,
|
||||||
upsertContextFieldSchema,
|
createContextFieldSchema,
|
||||||
|
updateContextFieldSchema,
|
||||||
upsertSegmentSchema,
|
upsertSegmentSchema,
|
||||||
createStrategySchema,
|
createStrategySchema,
|
||||||
updateStrategySchema,
|
updateStrategySchema,
|
||||||
|
@ -89,10 +89,7 @@ const metaRules: Rule[] = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
knownExceptions: [
|
knownExceptions: [],
|
||||||
'patchSchema',
|
|
||||||
'upsertContextFieldSchema', // must be split. Name can't be updated
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'should have a description',
|
name: 'should have a description',
|
||||||
@ -103,7 +100,7 @@ const metaRules: Rule[] = [
|
|||||||
},
|
},
|
||||||
required: ['description'],
|
required: ['description'],
|
||||||
},
|
},
|
||||||
knownExceptions: ['patchSchema'],
|
knownExceptions: [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
21
src/lib/openapi/spec/create-context-field-schema.ts
Normal file
21
src/lib/openapi/spec/create-context-field-schema.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { FromSchema } from 'json-schema-to-ts';
|
||||||
|
import { updateContextFieldSchema } from './update-context-field-schema';
|
||||||
|
|
||||||
|
export const createContextFieldSchema = {
|
||||||
|
...updateContextFieldSchema,
|
||||||
|
$id: '#/components/schemas/createContextFieldSchema',
|
||||||
|
description: 'Data used to create a context field configuration.',
|
||||||
|
required: ['name'],
|
||||||
|
properties: {
|
||||||
|
...updateContextFieldSchema.properties,
|
||||||
|
name: {
|
||||||
|
description: 'The name of the context field.',
|
||||||
|
type: 'string',
|
||||||
|
example: 'subscriptionTier',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type CreateContextFieldSchema = FromSchema<
|
||||||
|
typeof createContextFieldSchema
|
||||||
|
>;
|
@ -115,7 +115,8 @@ export * from './public-signup-token-schema';
|
|||||||
export * from './environments-project-schema';
|
export * from './environments-project-schema';
|
||||||
export * from './instance-admin-stats-schema';
|
export * from './instance-admin-stats-schema';
|
||||||
export * from './public-signup-tokens-schema';
|
export * from './public-signup-tokens-schema';
|
||||||
export * from './upsert-context-field-schema';
|
export * from './update-context-field-schema';
|
||||||
|
export * from './create-context-field-schema';
|
||||||
export * from './validated-edge-tokens-schema';
|
export * from './validated-edge-tokens-schema';
|
||||||
export * from './client-features-query-schema';
|
export * from './client-features-query-schema';
|
||||||
export * from './admin-features-query-schema';
|
export * from './admin-features-query-schema';
|
||||||
|
@ -4,18 +4,32 @@ export const patchSchema = {
|
|||||||
$id: '#/components/schemas/patchSchema',
|
$id: '#/components/schemas/patchSchema',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['path', 'op'],
|
required: ['path', 'op'],
|
||||||
|
description:
|
||||||
|
'A [JSON patch](https://www.rfc-editor.org/rfc/rfc6902) operation description',
|
||||||
properties: {
|
properties: {
|
||||||
path: {
|
path: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
description: 'The path to the property to operate on',
|
||||||
|
example: '/type',
|
||||||
},
|
},
|
||||||
op: {
|
op: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: ['add', 'remove', 'replace', 'copy', 'move'],
|
enum: ['add', 'remove', 'replace', 'copy', 'move'],
|
||||||
|
description: 'The kind of operation to perform',
|
||||||
|
example: 'replace',
|
||||||
},
|
},
|
||||||
from: {
|
from: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
description:
|
||||||
|
'The target to move or copy from, if performing one of those operations',
|
||||||
|
example: '/type',
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
description:
|
||||||
|
'The value to add or replace, if performing one of those operations',
|
||||||
|
example: 'kill-switch',
|
||||||
|
nullable: true,
|
||||||
},
|
},
|
||||||
value: {},
|
|
||||||
},
|
},
|
||||||
components: {},
|
components: {},
|
||||||
} as const;
|
} as const;
|
||||||
|
48
src/lib/openapi/spec/update-context-field-schema.ts
Normal file
48
src/lib/openapi/spec/update-context-field-schema.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { FromSchema } from 'json-schema-to-ts';
|
||||||
|
import { legalValueSchema } from './legal-value-schema';
|
||||||
|
|
||||||
|
export const updateContextFieldSchema = {
|
||||||
|
$id: '#/components/schemas/updateContextFieldSchema',
|
||||||
|
type: 'object',
|
||||||
|
description: 'Data to update an existing context field configuration.',
|
||||||
|
properties: {
|
||||||
|
description: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'A description of the context field',
|
||||||
|
example: "The user's subscription tier",
|
||||||
|
},
|
||||||
|
stickiness: {
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'`true` if this field should be available for use with [custom stickiness](https://docs.getunleash.io/reference/stickiness#custom-stickiness), otherwise `false`',
|
||||||
|
example: false,
|
||||||
|
},
|
||||||
|
sortOrder: {
|
||||||
|
type: 'integer',
|
||||||
|
description:
|
||||||
|
'How this context field should be sorted if no other sort order is selected',
|
||||||
|
example: 2,
|
||||||
|
},
|
||||||
|
legalValues: {
|
||||||
|
type: 'array',
|
||||||
|
description: 'A list of allowed values for this context field',
|
||||||
|
example: [
|
||||||
|
{ value: 'gold' },
|
||||||
|
{ value: 'silver' },
|
||||||
|
{ value: 'crystal' },
|
||||||
|
],
|
||||||
|
items: {
|
||||||
|
$ref: '#/components/schemas/legalValueSchema',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
schemas: {
|
||||||
|
legalValueSchema,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type UpdateContextFieldSchema = FromSchema<
|
||||||
|
typeof updateContextFieldSchema
|
||||||
|
>;
|
@ -1,39 +0,0 @@
|
|||||||
import { FromSchema } from 'json-schema-to-ts';
|
|
||||||
import { legalValueSchema } from './legal-value-schema';
|
|
||||||
|
|
||||||
export const upsertContextFieldSchema = {
|
|
||||||
$id: '#/components/schemas/upsertContextFieldSchema',
|
|
||||||
type: 'object',
|
|
||||||
description: 'Data to create or update a context field configuration.',
|
|
||||||
required: ['name'],
|
|
||||||
properties: {
|
|
||||||
name: {
|
|
||||||
description: 'The name of the context field.',
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
stickiness: {
|
|
||||||
type: 'boolean',
|
|
||||||
},
|
|
||||||
sortOrder: {
|
|
||||||
type: 'number',
|
|
||||||
},
|
|
||||||
legalValues: {
|
|
||||||
type: 'array',
|
|
||||||
items: {
|
|
||||||
$ref: '#/components/schemas/legalValueSchema',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
components: {
|
|
||||||
schemas: {
|
|
||||||
legalValueSchema,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export type UpsertContextFieldSchema = FromSchema<
|
|
||||||
typeof upsertContextFieldSchema
|
|
||||||
>;
|
|
@ -22,7 +22,6 @@ import {
|
|||||||
ContextFieldSchema,
|
ContextFieldSchema,
|
||||||
} from '../../openapi/spec/context-field-schema';
|
} from '../../openapi/spec/context-field-schema';
|
||||||
import { ContextFieldsSchema } from '../../openapi/spec/context-fields-schema';
|
import { ContextFieldsSchema } from '../../openapi/spec/context-fields-schema';
|
||||||
import { UpsertContextFieldSchema } from '../../openapi/spec/upsert-context-field-schema';
|
|
||||||
import { createRequestSchema } from '../../openapi/util/create-request-schema';
|
import { createRequestSchema } from '../../openapi/util/create-request-schema';
|
||||||
import {
|
import {
|
||||||
createResponseSchema,
|
createResponseSchema,
|
||||||
@ -39,6 +38,8 @@ import {
|
|||||||
ContextFieldStrategiesSchema,
|
ContextFieldStrategiesSchema,
|
||||||
contextFieldStrategiesSchema,
|
contextFieldStrategiesSchema,
|
||||||
} from '../../openapi/spec/context-field-strategies-schema';
|
} from '../../openapi/spec/context-field-strategies-schema';
|
||||||
|
import { UpdateContextFieldSchema } from 'lib/openapi/spec/update-context-field-schema';
|
||||||
|
import { CreateContextFieldSchema } from 'lib/openapi/spec/create-context-field-schema';
|
||||||
|
|
||||||
interface ContextParam {
|
interface ContextParam {
|
||||||
contextField: string;
|
contextField: string;
|
||||||
@ -136,7 +137,7 @@ export class ContextController extends Controller {
|
|||||||
description:
|
description:
|
||||||
'Endpoint that allows creation of [custom context fields](https://docs.getunleash.io/reference/unleash-context#custom-context-fields)',
|
'Endpoint that allows creation of [custom context fields](https://docs.getunleash.io/reference/unleash-context#custom-context-fields)',
|
||||||
requestBody: createRequestSchema(
|
requestBody: createRequestSchema(
|
||||||
'upsertContextFieldSchema',
|
'createContextFieldSchema',
|
||||||
),
|
),
|
||||||
responses: {
|
responses: {
|
||||||
201: resourceCreatedResponseSchema(
|
201: resourceCreatedResponseSchema(
|
||||||
@ -159,7 +160,7 @@ export class ContextController extends Controller {
|
|||||||
description: `Endpoint that allows updating a custom context field. Used to toggle stickiness and add/remove legal values for this context field`,
|
description: `Endpoint that allows updating a custom context field. Used to toggle stickiness and add/remove legal values for this context field`,
|
||||||
operationId: 'updateContextField',
|
operationId: 'updateContextField',
|
||||||
requestBody: createRequestSchema(
|
requestBody: createRequestSchema(
|
||||||
'upsertContextFieldSchema',
|
'updateContextFieldSchema',
|
||||||
),
|
),
|
||||||
responses: {
|
responses: {
|
||||||
200: emptyResponse,
|
200: emptyResponse,
|
||||||
@ -239,7 +240,7 @@ export class ContextController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createContextField(
|
async createContextField(
|
||||||
req: IAuthRequest<void, void, UpsertContextFieldSchema>,
|
req: IAuthRequest<void, void, CreateContextFieldSchema>,
|
||||||
res: Response<ContextFieldSchema>,
|
res: Response<ContextFieldSchema>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const value = req.body;
|
const value = req.body;
|
||||||
@ -260,16 +261,17 @@ export class ContextController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateContextField(
|
async updateContextField(
|
||||||
req: IAuthRequest<ContextParam, void, UpsertContextFieldSchema>,
|
req: IAuthRequest<ContextParam, void, UpdateContextFieldSchema>,
|
||||||
res: Response,
|
res: Response,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const name = req.params.contextField;
|
const name = req.params.contextField;
|
||||||
const userName = extractUsername(req);
|
const userName = extractUsername(req);
|
||||||
const contextField = req.body;
|
const contextField = req.body;
|
||||||
|
|
||||||
contextField.name = name;
|
await this.contextService.updateContextField(
|
||||||
|
{ ...contextField, name },
|
||||||
await this.contextService.updateContextField(contextField, userName);
|
userName,
|
||||||
|
);
|
||||||
res.status(200).end();
|
res.status(200).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user