Skip to content

Commit

Permalink
Update OpenAPI feature strategies (#4175)
Browse files Browse the repository at this point in the history
## About the changes
Updates for endpoint
`/api/admin/projects/{projectId}/features/{featureName}/environments/{environment}/strategies`
and similar
  • Loading branch information
Tymek committed Jul 7, 2023
1 parent 6f15eb9 commit ace499d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/lib/openapi/meta-schema-rules.test.ts
Expand Up @@ -123,7 +123,6 @@ const metaRules: Rule[] = [
'tagWithVersionSchema',
'uiConfigSchema',
'updateFeatureSchema',
'updateFeatureStrategySchema',
'updateTagTypeSchema',
'upsertContextFieldSchema',
'upsertStrategySchema',
Expand Down Expand Up @@ -151,7 +150,6 @@ const metaRules: Rule[] = [
'batchStaleSchema',
'cloneFeatureSchema',
'createFeatureSchema',
'createFeatureStrategySchema',
'createInvitedUserSchema',
'dateSchema',
'environmentsSchema',
Expand Down Expand Up @@ -183,7 +181,6 @@ const metaRules: Rule[] = [
'tagWithVersionSchema',
'uiConfigSchema',
'updateFeatureSchema',
'updateFeatureStrategySchema',
'updateTagTypeSchema',
'upsertContextFieldSchema',
'upsertStrategySchema',
Expand Down
6 changes: 4 additions & 2 deletions src/lib/openapi/spec/create-feature-strategy-schema.ts
Expand Up @@ -6,10 +6,11 @@ export const createFeatureStrategySchema = {
$id: '#/components/schemas/createFeatureStrategySchema',
type: 'object',
required: ['name'],
description: 'Create a strategy configuration in a feature',
properties: {
name: {
type: 'string',
description: 'The name or type of strategy',
description: 'The name of the strategy type',
example: 'flexibleRollout',
},
title: {
Expand All @@ -32,7 +33,8 @@ export const createFeatureStrategySchema = {
},
constraints: {
type: 'array',
description: 'A list of the constraints attached to the strategy',
description:
'A list of the constraints attached to the strategy. See https://docs.getunleash.io/reference/strategy-constraints',
example: [
{
values: ['1', '2'],
Expand Down
3 changes: 2 additions & 1 deletion src/lib/openapi/spec/feature-strategy-schema.ts
Expand Up @@ -53,7 +53,8 @@ export const featureStrategySchema = {
},
constraints: {
type: 'array',
description: 'A list of the constraints attached to the strategy',
description:
'A list of the constraints attached to the strategy. See https://docs.getunleash.io/reference/strategy-constraints',
items: {
$ref: '#/components/schemas/constraintSchema',
},
Expand Down
6 changes: 6 additions & 0 deletions src/lib/openapi/spec/update-feature-strategy-schema.ts
Expand Up @@ -5,18 +5,24 @@ import { constraintSchema } from './constraint-schema';
export const updateFeatureStrategySchema = {
$id: '#/components/schemas/updateFeatureStrategySchema',
type: 'object',
description: 'Update a strategy configuration in a feature',
properties: {
name: {
type: 'string',
description: 'The name of the strategy type',
},
sortOrder: {
type: 'number',
description:
'The order of the strategy in the list in feature environment configuration',
},
constraints: {
type: 'array',
items: {
$ref: '#/components/schemas/constraintSchema',
},
description:
'A list of the constraints attached to the strategy. See https://docs.getunleash.io/reference/strategy-constraints',
},
title: {
type: 'string',
Expand Down
33 changes: 29 additions & 4 deletions src/lib/routes/admin-api/project/project-features.ts
Expand Up @@ -261,9 +261,13 @@ export default class ProjectFeaturesController extends Controller {
middleware: [
openApiService.validPath({
tags: ['Features'],
summary: 'Get feature toggle strategies.',
operationId: 'getFeatureStrategies',
description:
'Get strategies defined for a feature toggle in the specified environment.',
responses: {
200: createResponseSchema('featureStrategySchema'),
...getStandardResponses(401, 403, 404),
},
}),
],
Expand All @@ -277,12 +281,16 @@ export default class ProjectFeaturesController extends Controller {
middleware: [
openApiService.validPath({
tags: ['Features'],
summary: 'Add a strategy to a feature toggle.',
description:
'Add a strategy to a feature toggle in the specified environment.',
operationId: 'addFeatureStrategy',
requestBody: createRequestSchema(
'createFeatureStrategySchema',
),
responses: {
200: createResponseSchema('featureStrategySchema'),
...getStandardResponses(401, 403, 404),
},
}),
],
Expand All @@ -296,6 +304,9 @@ export default class ProjectFeaturesController extends Controller {
middleware: [
openApiService.validPath({
tags: ['Features'],
summary: 'Get a strategy configuration.',
description:
'Get a strategy configuration for an environment in a feature toggle.',
operationId: 'getFeatureStrategy',
responses: {
200: createResponseSchema('featureStrategySchema'),
Expand All @@ -312,12 +323,14 @@ export default class ProjectFeaturesController extends Controller {
middleware: [
openApiService.validPath({
tags: ['Features'],
summary: 'Set the order of strategies on the list.',
operationId: 'setStrategySortOrder',
requestBody: createRequestSchema(
'setStrategySortOrderSchema',
),
responses: {
200: emptyResponse,
...getStandardResponses(401, 403),
},
}),
],
Expand All @@ -331,6 +344,9 @@ export default class ProjectFeaturesController extends Controller {
middleware: [
openApiService.validPath({
tags: ['Features'],
summary: 'Update a strategy.',
description:
'Replace strategy configuration for a feature toggle in the specified environment.',
operationId: 'updateFeatureStrategy',
requestBody: createRequestSchema(
'updateFeatureStrategySchema',
Expand All @@ -350,6 +366,9 @@ export default class ProjectFeaturesController extends Controller {
middleware: [
openApiService.validPath({
tags: ['Features'],
summary: 'Change specific properties of a strategy.',
description:
'Change specific properties of a strategy configuration in a feature toggle.',
operationId: 'patchFeatureStrategy',
requestBody: createRequestSchema('patchesSchema'),
responses: {
Expand All @@ -367,9 +386,15 @@ export default class ProjectFeaturesController extends Controller {
permission: DELETE_FEATURE_STRATEGY,
middleware: [
openApiService.validPath({
operationId: 'deleteFeatureStrategy',
tags: ['Features'],
responses: { 200: emptyResponse },
summary: 'Delete a strategy from a feature toggle.',
description:
'Delete a strategy configuration from a feature toggle in the specified environment.',
operationId: 'deleteFeatureStrategy',
responses: {
200: emptyResponse,
...getStandardResponses(401, 403, 404),
},
}),
],
});
Expand Down Expand Up @@ -798,7 +823,7 @@ export default class ProjectFeaturesController extends Controller {
const { features } = req.body;

if (this.flagResolver.isEnabled('disableBulkToggle')) {
res.status(409).end();
res.status(403).end();
return;
}

Expand Down Expand Up @@ -830,7 +855,7 @@ export default class ProjectFeaturesController extends Controller {
const { features } = req.body;

if (this.flagResolver.isEnabled('disableBulkToggle')) {
res.status(409).end();
res.status(403).end();
return;
}

Expand Down

0 comments on commit ace499d

Please sign in to comment.