1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-05-03 01:18:43 +02:00

OpenAPI - feature environment endpoints (#4166)

## About the changes
Fix OpenAPI definitions for endpoint

`/api/admin/projects/{projectId}/features/{featureName}/environments/{environment}`
and similar.
This commit is contained in:
Tymoteusz Czech 2023-07-07 14:31:03 +02:00 committed by GitHub
parent ec1bc9bb4e
commit 1b99b700d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 10 deletions

View File

@ -90,7 +90,6 @@ const metaRules: Rule[] = [
}, },
}, },
knownExceptions: [ knownExceptions: [
'batchFeaturesSchema',
'batchStaleSchema', 'batchStaleSchema',
'cloneFeatureSchema', 'cloneFeatureSchema',
'createFeatureSchema', 'createFeatureSchema',
@ -98,7 +97,6 @@ const metaRules: Rule[] = [
'environmentsSchema', 'environmentsSchema',
'environmentsProjectSchema', 'environmentsProjectSchema',
'featureEnvironmentSchema', 'featureEnvironmentSchema',
'featureSchema',
'featuresSchema', 'featuresSchema',
'featureStrategySegmentSchema', 'featureStrategySegmentSchema',
'featureTypeSchema', 'featureTypeSchema',
@ -150,7 +148,6 @@ const metaRules: Rule[] = [
'adminFeaturesQuerySchema', 'adminFeaturesQuerySchema',
'applicationSchema', 'applicationSchema',
'applicationsSchema', 'applicationsSchema',
'batchFeaturesSchema',
'batchStaleSchema', 'batchStaleSchema',
'cloneFeatureSchema', 'cloneFeatureSchema',
'createFeatureSchema', 'createFeatureSchema',
@ -158,7 +155,6 @@ const metaRules: Rule[] = [
'createInvitedUserSchema', 'createInvitedUserSchema',
'dateSchema', 'dateSchema',
'environmentsSchema', 'environmentsSchema',
'featureSchema',
'featuresSchema', 'featuresSchema',
'featureStrategySegmentSchema', 'featureStrategySegmentSchema',
'featureTypeSchema', 'featureTypeSchema',
@ -169,7 +165,6 @@ const metaRules: Rule[] = [
'groupUserModelSchema', 'groupUserModelSchema',
'maintenanceSchema', 'maintenanceSchema',
'toggleMaintenanceSchema', 'toggleMaintenanceSchema',
'parametersSchema',
'patchesSchema', 'patchesSchema',
'patchSchema', 'patchSchema',
'playgroundSegmentSchema', 'playgroundSegmentSchema',

View File

@ -3,6 +3,7 @@ import { FromSchema } from 'json-schema-to-ts';
export const batchFeaturesSchema = { export const batchFeaturesSchema = {
$id: '#/components/schemas/batchFeaturesSchema', $id: '#/components/schemas/batchFeaturesSchema',
type: 'object', type: 'object',
description: 'A list of feature toggle names for batch operations',
required: ['features'], required: ['features'],
properties: { properties: {
features: { features: {
@ -10,6 +11,7 @@ export const batchFeaturesSchema = {
items: { items: {
type: 'string', type: 'string',
}, },
description: 'List of feature toggle names',
}, },
}, },
components: { components: {

View File

@ -42,6 +42,7 @@ export const featureEnvironmentSchema = {
}, },
variantCount: { variantCount: {
type: 'number', type: 'number',
description: 'The number of defined variants',
}, },
strategies: { strategies: {
type: 'array', type: 'array',

View File

@ -12,6 +12,7 @@ export const featureSchema = {
type: 'object', type: 'object',
additionalProperties: false, additionalProperties: false,
required: ['name'], required: ['name'],
description: 'A feature toggle definition',
properties: { properties: {
name: { name: {
type: 'string', type: 'string',
@ -44,6 +45,7 @@ export const featureSchema = {
enabled: { enabled: {
type: 'boolean', type: 'boolean',
example: true, example: true,
description: '`true` if the feature is enabled, otherwise `false`.',
}, },
stale: { stale: {
type: 'boolean', type: 'boolean',
@ -68,18 +70,22 @@ export const featureSchema = {
format: 'date-time', format: 'date-time',
nullable: true, nullable: true,
example: '2023-01-28T15:21:39.975Z', example: '2023-01-28T15:21:39.975Z',
description: 'The date the feature was created',
}, },
archivedAt: { archivedAt: {
type: 'string', type: 'string',
format: 'date-time', format: 'date-time',
nullable: true, nullable: true,
example: '2023-01-29T15:21:39.975Z', example: '2023-01-29T15:21:39.975Z',
description: 'The date the feature was archived',
}, },
lastSeenAt: { lastSeenAt: {
type: 'string', type: 'string',
format: 'date-time', format: 'date-time',
nullable: true, nullable: true,
example: '2023-01-28T16:21:39.975Z', example: '2023-01-28T16:21:39.975Z',
description:
'The date when metrics where last collected for the feature',
}, },
environments: { environments: {
type: 'array', type: 'array',

View File

@ -3,6 +3,7 @@ import { FromSchema } from 'json-schema-to-ts';
export const parametersSchema = { export const parametersSchema = {
$id: '#/components/schemas/parametersSchema', $id: '#/components/schemas/parametersSchema',
type: 'object', type: 'object',
description: 'A list of parameters for a strategy',
additionalProperties: { additionalProperties: {
type: 'string', type: 'string',
}, },

View File

@ -161,7 +161,7 @@ class FeatureController extends Controller {
operationId: 'removeTag', operationId: 'removeTag',
responses: { responses: {
200: emptyResponse, 200: emptyResponse,
...getStandardResponses(404), ...getStandardResponses(401, 403, 404),
}, },
}), }),
], ],

View File

@ -152,10 +152,14 @@ export default class ProjectFeaturesController extends Controller {
handler: this.getFeatureEnvironment, handler: this.getFeatureEnvironment,
middleware: [ middleware: [
openApiService.validPath({ openApiService.validPath({
summary: 'Get a feature environment.',
description:
'Information about the enablement status and strategies for a feature toggle in specified environment.',
tags: ['Features'], tags: ['Features'],
operationId: 'getFeatureEnvironment', operationId: 'getFeatureEnvironment',
responses: { responses: {
200: createResponseSchema('featureEnvironmentSchema'), 200: createResponseSchema('featureEnvironmentSchema'),
...getStandardResponses(401, 403, 404),
}, },
}), }),
], ],
@ -169,9 +173,15 @@ export default class ProjectFeaturesController extends Controller {
permission: UPDATE_FEATURE_ENVIRONMENT, permission: UPDATE_FEATURE_ENVIRONMENT,
middleware: [ middleware: [
openApiService.validPath({ openApiService.validPath({
summary: 'Disable a feature toggle.',
description:
'Disable a feature toggle in the specified environment.',
tags: ['Features'], tags: ['Features'],
operationId: 'toggleFeatureEnvironmentOff', operationId: 'toggleFeatureEnvironmentOff',
responses: { 200: createResponseSchema('featureSchema') }, responses: {
200: createResponseSchema('featureSchema'),
...getStandardResponses(400, 401, 403, 404),
},
}), }),
], ],
}); });
@ -184,9 +194,15 @@ export default class ProjectFeaturesController extends Controller {
permission: UPDATE_FEATURE_ENVIRONMENT, permission: UPDATE_FEATURE_ENVIRONMENT,
middleware: [ middleware: [
openApiService.validPath({ openApiService.validPath({
summary: 'Enable a feature toggle.',
description:
'Enable a feature toggle in the specified environment.',
tags: ['Features'], tags: ['Features'],
operationId: 'toggleFeatureEnvironmentOn', operationId: 'toggleFeatureEnvironmentOn',
responses: { 200: createResponseSchema('featureSchema') }, responses: {
200: createResponseSchema('featureSchema'),
...getStandardResponses(400, 401, 403, 404),
},
}), }),
], ],
}); });
@ -206,7 +222,10 @@ export default class ProjectFeaturesController extends Controller {
requestBody: createRequestSchema( requestBody: createRequestSchema(
'bulkToggleFeaturesSchema', 'bulkToggleFeaturesSchema',
), ),
responses: { 405: emptyResponse }, responses: {
200: emptyResponse,
...getStandardResponses(400, 401, 403, 404, 413, 415),
},
}), }),
], ],
}); });
@ -226,7 +245,10 @@ export default class ProjectFeaturesController extends Controller {
requestBody: createRequestSchema( requestBody: createRequestSchema(
'bulkToggleFeaturesSchema', 'bulkToggleFeaturesSchema',
), ),
responses: { 405: emptyResponse }, responses: {
200: emptyResponse,
...getStandardResponses(400, 401, 403, 404, 413, 415),
},
}), }),
], ],
}); });