1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-09 13:47:13 +02:00

OpenAPI: more schema cleanup (#4353)

This PR fixes additional schemas that hadn't been described properly
This commit is contained in:
Thomas Heartman 2023-07-28 08:59:05 +02:00 committed by GitHub
parent 12209ae21c
commit df59b10fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 96 additions and 38 deletions

View File

@ -90,21 +90,8 @@ const metaRules: Rule[] = [
}, },
}, },
knownExceptions: [ knownExceptions: [
'featureStrategySegmentSchema',
'maintenanceSchema',
'toggleMaintenanceSchema',
'patchSchema', 'patchSchema',
'projectSchema', 'upsertContextFieldSchema', // must be split. Name can't be updated
'projectsSchema',
'pushVariantsSchema',
'resetPasswordSchema',
'sdkContextSchema',
'stateSchema',
'upsertContextFieldSchema',
'upsertStrategySchema',
'usersGroupsBaseSchema',
'validateEdgeTokensSchema',
'projectOverviewSchema',
], ],
}, },
{ {
@ -116,23 +103,7 @@ const metaRules: Rule[] = [
}, },
required: ['description'], required: ['description'],
}, },
knownExceptions: [ knownExceptions: ['patchSchema'],
'featureStrategySegmentSchema',
'maintenanceSchema',
'toggleMaintenanceSchema',
'patchSchema',
'playgroundSegmentSchema',
'playgroundStrategySchema',
'pushVariantsSchema',
'resetPasswordSchema',
'sortOrderSchema',
'upsertContextFieldSchema',
'upsertStrategySchema',
'usersGroupsBaseSchema',
'usersSearchSchema',
'validateEdgeTokensSchema',
'variantsSchema',
],
}, },
]; ];

View File

@ -6,9 +6,9 @@ exports[`sortOrderSchema invalid value type 1`] = `
{ {
"instancePath": "/a", "instancePath": "/a",
"keyword": "type", "keyword": "type",
"message": "must be number", "message": "must be integer",
"params": { "params": {
"type": "number", "type": "integer",
}, },
"schemaPath": "#/additionalProperties/type", "schemaPath": "#/additionalProperties/type",
}, },

View File

@ -3,14 +3,20 @@ import { FromSchema } from 'json-schema-to-ts';
export const featureStrategySegmentSchema = { export const featureStrategySegmentSchema = {
$id: '#/components/schemas/featureStrategySegmentSchema', $id: '#/components/schemas/featureStrategySegmentSchema',
type: 'object', type: 'object',
description:
'An object containing a segment identifier and a strategy identifier.',
additionalProperties: false, additionalProperties: false,
required: ['segmentId', 'featureStrategyId'], required: ['segmentId', 'featureStrategyId'],
properties: { properties: {
segmentId: { segmentId: {
type: 'integer', type: 'integer',
description: 'The ID of the segment',
example: 2,
}, },
featureStrategyId: { featureStrategyId: {
type: 'string', type: 'string',
description: 'The ID of the strategy',
example: 'e2caa08f-30c4-4aa3-b955-54ca9e93dc13',
}, },
}, },
components: {}, components: {},

View File

@ -69,6 +69,12 @@ export const groupSchema = {
}, },
example: ['default', 'my-project'], example: ['default', 'my-project'],
}, },
userCount: {
description: 'The number of users that belong to this group',
example: 1,
type: 'integer',
minimum: 0,
},
}, },
components: { components: {
schemas: { schemas: {

View File

@ -4,9 +4,11 @@ export const maintenanceSchema = {
$id: '#/components/schemas/maintenanceSchema', $id: '#/components/schemas/maintenanceSchema',
type: 'object', type: 'object',
additionalProperties: false, additionalProperties: false,
description: "The current state of Unleash's maintenance mode feature.",
required: ['enabled'], required: ['enabled'],
properties: { properties: {
enabled: { enabled: {
description: 'Whether maintenance mode is enabled or not.',
type: 'boolean', type: 'boolean',
example: true, example: true,
}, },

View File

@ -5,6 +5,7 @@ export const playgroundSegmentSchema = {
$id: '#/components/schemas/playgroundSegmentSchema', $id: '#/components/schemas/playgroundSegmentSchema',
type: 'object', type: 'object',
additionalProperties: false, additionalProperties: false,
description: 'The evaluated result of a segment as used by the Playground.',
required: ['name', 'id', 'constraints', 'result'], required: ['name', 'id', 'constraints', 'result'],
properties: { properties: {
id: { id: {

View File

@ -110,6 +110,8 @@ export const strategyEvaluationResults = {
export const playgroundStrategySchema = { export const playgroundStrategySchema = {
$id: '#/components/schemas/playgroundStrategySchema', $id: '#/components/schemas/playgroundStrategySchema',
type: 'object', type: 'object',
description:
'An evaluated feature toggle strategy as used by the Playground',
additionalProperties: false, additionalProperties: false,
required: [ required: [
'id', 'id',

View File

@ -26,8 +26,10 @@ export const projectOverviewSchema = {
description: 'Project statistics', description: 'Project statistics',
}, },
version: { version: {
type: 'number', type: 'integer',
example: 1, example: 1,
description:
'The schema version used to describe the project overview',
}, },
name: { name: {
type: 'string', type: 'string',
@ -106,12 +108,14 @@ export const projectOverviewSchema = {
format: 'date-time', format: 'date-time',
nullable: true, nullable: true,
example: '2023-02-10T08:36:35.262Z', example: '2023-02-10T08:36:35.262Z',
description: 'When the project was last updated.',
}, },
createdAt: { createdAt: {
type: 'string', type: 'string',
format: 'date-time', format: 'date-time',
nullable: true, nullable: true,
example: '2023-02-10T08:36:35.262Z', example: '2023-02-10T08:36:35.262Z',
description: 'When the project was created.',
}, },
favorite: { favorite: {
type: 'boolean', type: 'boolean',

View File

@ -42,12 +42,16 @@ export const projectSchema = {
}, },
createdAt: { createdAt: {
type: 'string', type: 'string',
description: 'When this project was created.',
example: '2023-07-27T12:12:28Z',
format: 'date-time', format: 'date-time',
}, },
updatedAt: { updatedAt: {
type: 'string', type: 'string',
format: 'date-time', format: 'date-time',
nullable: true, nullable: true,
description: 'When this project was last updated.',
example: '2023-07-28T12:12:28Z',
}, },
favorite: { favorite: {
type: 'boolean', type: 'boolean',

View File

@ -10,6 +10,9 @@ export const projectsSchema = {
properties: { properties: {
version: { version: {
type: 'integer', type: 'integer',
description:
'The schema version used to represent the project data.',
example: 1,
}, },
projects: { projects: {
type: 'array', type: 'array',

View File

@ -5,15 +5,18 @@ import { overrideSchema } from './override-schema';
export const pushVariantsSchema = { export const pushVariantsSchema = {
$id: '#/components/schemas/pushVariantsSchema', $id: '#/components/schemas/pushVariantsSchema',
type: 'object', type: 'object',
description: 'Data used when copying variants into a new environment.',
properties: { properties: {
variants: { variants: {
type: 'array', type: 'array',
description: 'The variants to write to the provided environments',
items: { items: {
$ref: '#/components/schemas/variantSchema', $ref: '#/components/schemas/variantSchema',
}, },
}, },
environments: { environments: {
type: 'array', type: 'array',
description: 'The enviromnents to write the provided variants to',
items: { items: {
type: 'string', type: 'string',
}, },

View File

@ -3,11 +3,16 @@ import { FromSchema } from 'json-schema-to-ts';
export const resetPasswordSchema = { export const resetPasswordSchema = {
$id: '#/components/schemas/resetPasswordSchema', $id: '#/components/schemas/resetPasswordSchema',
type: 'object', type: 'object',
description: 'Data used to provide users a way to reset their passwords.',
additionalProperties: false, additionalProperties: false,
required: ['resetPasswordUrl'], required: ['resetPasswordUrl'],
properties: { properties: {
resetPasswordUrl: { resetPasswordUrl: {
description:
'A URL pointing to a location where the user can reset their password',
type: 'string', type: 'string',
format: 'uri',
example: 'https://reset.password.com',
}, },
}, },
components: {}, components: {},

View File

@ -28,6 +28,7 @@ export const sdkContextSchema = {
properties: { properties: {
type: 'object', type: 'object',
additionalProperties: { type: 'string' }, additionalProperties: { type: 'string' },
description: 'Additional Unleash context properties',
example: { example: {
customContextField: 'this is one!', customContextField: 'this is one!',
otherCustomField: '3', otherCustomField: '3',

View File

@ -3,8 +3,12 @@ import { FromSchema } from 'json-schema-to-ts';
export const sortOrderSchema = { export const sortOrderSchema = {
$id: '#/components/schemas/sortOrderSchema', $id: '#/components/schemas/sortOrderSchema',
type: 'object', type: 'object',
description: 'A map of object IDs and their corresponding sort orders.',
additionalProperties: { additionalProperties: {
type: 'number', type: 'integer',
description:
'Sort order for the object whose ID is the key used for this property.',
example: 6,
}, },
components: {}, components: {},
} as const; } as const;

View File

@ -18,74 +18,87 @@ export const stateSchema = {
additionalProperties: true, additionalProperties: true,
deprecated: true, deprecated: true,
description: description:
'The state of the application used by export/import APIs which are deprecated in favor of the more fine grained /api/admin/export and /api/admin/import APIs', 'The application state as used by the deprecated export/import APIs.',
required: ['version'], required: ['version'],
properties: { properties: {
version: { version: {
type: 'integer', type: 'integer',
description: 'The version of the schema used to describe the state',
example: 1,
}, },
features: { features: {
type: 'array', type: 'array',
description: 'A list of features',
items: { items: {
$ref: '#/components/schemas/featureSchema', $ref: '#/components/schemas/featureSchema',
}, },
}, },
strategies: { strategies: {
type: 'array', type: 'array',
description: 'A list of strategies',
items: { items: {
$ref: '#/components/schemas/strategySchema', $ref: '#/components/schemas/strategySchema',
}, },
}, },
tags: { tags: {
type: 'array', type: 'array',
description: 'A list of tags',
items: { items: {
$ref: '#/components/schemas/tagSchema', $ref: '#/components/schemas/tagSchema',
}, },
}, },
tagTypes: { tagTypes: {
type: 'array', type: 'array',
description: 'A list of tag types',
items: { items: {
$ref: '#/components/schemas/tagTypeSchema', $ref: '#/components/schemas/tagTypeSchema',
}, },
}, },
featureTags: { featureTags: {
type: 'array', type: 'array',
description: 'A list of tags applied to features',
items: { items: {
$ref: '#/components/schemas/featureTagSchema', $ref: '#/components/schemas/featureTagSchema',
}, },
}, },
projects: { projects: {
type: 'array', type: 'array',
description: 'A list of projects',
items: { items: {
$ref: '#/components/schemas/projectSchema', $ref: '#/components/schemas/projectSchema',
}, },
}, },
featureStrategies: { featureStrategies: {
type: 'array', type: 'array',
description: 'A list of feature strategies as applied to features',
items: { items: {
$ref: '#/components/schemas/featureStrategySchema', $ref: '#/components/schemas/featureStrategySchema',
}, },
}, },
featureEnvironments: { featureEnvironments: {
type: 'array', type: 'array',
description: 'A list of feature environment configurations',
items: { items: {
$ref: '#/components/schemas/featureEnvironmentSchema', $ref: '#/components/schemas/featureEnvironmentSchema',
}, },
}, },
environments: { environments: {
type: 'array', type: 'array',
description: 'A list of environments',
items: { items: {
$ref: '#/components/schemas/environmentSchema', $ref: '#/components/schemas/environmentSchema',
}, },
}, },
segments: { segments: {
type: 'array', type: 'array',
description: 'A list of segments',
items: { items: {
$ref: '#/components/schemas/segmentSchema', $ref: '#/components/schemas/segmentSchema',
}, },
}, },
featureStrategySegments: { featureStrategySegments: {
type: 'array', type: 'array',
description: 'A list of segment/strategy pairings',
items: { items: {
$ref: '#/components/schemas/featureStrategySegmentSchema', $ref: '#/components/schemas/featureStrategySegmentSchema',
}, },

View File

@ -3,9 +3,13 @@ import { FromSchema } from 'json-schema-to-ts';
export const toggleMaintenanceSchema = { export const toggleMaintenanceSchema = {
$id: '#/components/schemas/toggleMaintenanceSchema', $id: '#/components/schemas/toggleMaintenanceSchema',
type: 'object', type: 'object',
description:
'Data used when to activate or deactivate maintenance mode for Unleash.',
required: ['enabled'], required: ['enabled'],
properties: { properties: {
enabled: { enabled: {
description:
'`true` if you want to activate maintenance mode, `false` if you want to deactivate it.',
type: 'boolean', type: 'boolean',
example: true, example: true,
}, },

View File

@ -4,9 +4,11 @@ import { legalValueSchema } from './legal-value-schema';
export const upsertContextFieldSchema = { export const upsertContextFieldSchema = {
$id: '#/components/schemas/upsertContextFieldSchema', $id: '#/components/schemas/upsertContextFieldSchema',
type: 'object', type: 'object',
description: 'Data to create or update a context field configuration.',
required: ['name'], required: ['name'],
properties: { properties: {
name: { name: {
description: 'The name of the context field.',
type: 'string', type: 'string',
}, },
description: { description: {

View File

@ -7,18 +7,42 @@ export const usersGroupsBaseSchema = {
$id: '#/components/schemas/usersGroupsBaseSchema', $id: '#/components/schemas/usersGroupsBaseSchema',
type: 'object', type: 'object',
additionalProperties: false, additionalProperties: false,
description: 'An overview of user groups and users.',
properties: { properties: {
groups: { groups: {
type: 'array', type: 'array',
description: 'A list of user groups and their configuration.',
items: { items: {
$ref: '#/components/schemas/groupSchema', $ref: '#/components/schemas/groupSchema',
}, },
example: [
{
id: 1,
name: 'unleash-e2e-7095756699593281',
userCount: 1,
rootRole: null,
},
],
}, },
users: { users: {
type: 'array', type: 'array',
items: { items: {
$ref: '#/components/schemas/userSchema', $ref: '#/components/schemas/userSchema',
}, },
description: 'A list of users.',
example: [
{
id: 4,
name: 'unleash-e2e-user2-7095756699593281',
email: 'unleash-e2e-user2-7095756699593281@test.com',
accountType: 'User',
},
{
id: 1,
username: 'admin',
accountType: 'User',
},
],
}, },
}, },
components: { components: {

View File

@ -4,6 +4,7 @@ import { userSchema } from './user-schema';
export const usersSearchSchema = { export const usersSearchSchema = {
$id: '#/components/schemas/usersSearchSchema', $id: '#/components/schemas/usersSearchSchema',
type: 'array', type: 'array',
description: 'A list of users',
items: { items: {
$ref: '#/components/schemas/userSchema', $ref: '#/components/schemas/userSchema',
}, },

View File

@ -5,6 +5,7 @@ import { overrideSchema } from './override-schema';
export const variantsSchema = { export const variantsSchema = {
$id: '#/components/schemas/variantsSchema', $id: '#/components/schemas/variantsSchema',
type: 'array', type: 'array',
description: 'A list of variants',
items: { items: {
$ref: '#/components/schemas/variantSchema', $ref: '#/components/schemas/variantSchema',
}, },

View File

@ -16,6 +16,7 @@ import {
maintenanceSchema, maintenanceSchema,
} from '../../openapi/spec/maintenance-schema'; } from '../../openapi/spec/maintenance-schema';
import MaintenanceService from 'lib/services/maintenance-service'; import MaintenanceService from 'lib/services/maintenance-service';
import { ToggleMaintenanceSchema } from 'lib/openapi/spec/toggle-maintenance-schema';
export default class MaintenanceController extends Controller { export default class MaintenanceController extends Controller {
private maintenanceService: MaintenanceService; private maintenanceService: MaintenanceService;
@ -77,8 +78,8 @@ export default class MaintenanceController extends Controller {
} }
async toggleMaintenance( async toggleMaintenance(
req: IAuthRequest<unknown, unknown, MaintenanceSchema>, req: IAuthRequest<unknown, unknown, ToggleMaintenanceSchema>,
res: Response, res: Response<MaintenanceSchema>,
): Promise<void> { ): Promise<void> {
await this.maintenanceService.toggleMaintenanceMode( await this.maintenanceService.toggleMaintenanceMode(
req.body, req.body,