1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-21 13:47:39 +02:00
unleash.unleash/src/lib/openapi/spec/create-feature-schema.ts
Jaanus Sellin 0118f88964
fix: feature type is now validated (#7769)
Previously people were able to send random data to feature type. Now it
is validated.

Fixes https://github.com/Unleash/unleash/issues/7751

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.io>
2024-08-06 12:27:20 +03:00

56 lines
1.7 KiB
TypeScript

import type { FromSchema } from 'json-schema-to-ts';
import { tagSchema } from './tag-schema';
export const createFeatureSchema = {
$id: '#/components/schemas/createFeatureSchema',
type: 'object',
description: 'Data used to create a new feature flag.',
required: ['name'],
properties: {
name: {
type: 'string',
example: 'disable-comments',
description: 'Unique feature name',
},
type: {
enum: [
'experiment',
'kill-switch',
'release',
'operational',
'permission',
],
example: 'release',
description:
"The feature flag's [type](https://docs.getunleash.io/reference/feature-toggle-types). One of experiment, kill-switch, release, operational, or permission",
},
description: {
type: 'string',
nullable: true,
example:
'Controls disabling of the comments section in case of an incident',
description: 'Detailed description of the feature',
},
impressionData: {
type: 'boolean',
example: false,
description:
'`true` if the impression data collection is enabled for the feature, otherwise `false`.',
},
tags: {
type: 'array',
description: 'Tags to add to the feature.',
items: {
$ref: '#/components/schemas/tagSchema',
},
},
},
components: {
schemas: {
tagSchema,
},
},
} as const;
export type CreateFeatureSchema = FromSchema<typeof createFeatureSchema>;