mirror of
https://github.com/Unleash/unleash.git
synced 2025-11-10 01:19:53 +01:00
Wip: fixup param types
This commit is contained in:
parent
e6cbe0b9d6
commit
fac6f24e31
@ -30,7 +30,6 @@ import { environmentSchema } from './spec/environment-schema';
|
|||||||
import { environmentsSchema } from './spec/environments-schema';
|
import { environmentsSchema } from './spec/environments-schema';
|
||||||
import { eventSchema } from './spec/event-schema';
|
import { eventSchema } from './spec/event-schema';
|
||||||
import { eventsSchema } from './spec/events-schema';
|
import { eventsSchema } from './spec/events-schema';
|
||||||
import { exportParametersSchema } from './spec/export-parameters-schema';
|
|
||||||
import { featureEnvironmentMetricsSchema } from './spec/feature-environment-metrics-schema';
|
import { featureEnvironmentMetricsSchema } from './spec/feature-environment-metrics-schema';
|
||||||
import { featureEnvironmentSchema } from './spec/feature-environment-schema';
|
import { featureEnvironmentSchema } from './spec/feature-environment-schema';
|
||||||
import { featureEventsSchema } from './spec/feature-events-schema';
|
import { featureEventsSchema } from './spec/feature-events-schema';
|
||||||
@ -134,7 +133,6 @@ export const schemas = {
|
|||||||
environmentsSchema,
|
environmentsSchema,
|
||||||
eventSchema,
|
eventSchema,
|
||||||
eventsSchema,
|
eventsSchema,
|
||||||
exportParametersSchema,
|
|
||||||
featureEnvironmentMetricsSchema,
|
featureEnvironmentMetricsSchema,
|
||||||
featureEnvironmentSchema,
|
featureEnvironmentSchema,
|
||||||
featureEventsSchema,
|
featureEventsSchema,
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import { FromSchema } from 'json-schema-to-ts';
|
import { FromSchema } from 'json-schema-to-ts';
|
||||||
|
import { OpenAPIV3 } from 'openapi-types';
|
||||||
import { createQueryParameters } from '../util/query-parameters';
|
import { createQueryParameters } from '../util/query-parameters';
|
||||||
import { Parameters } from '../util/query-parameters';
|
import { Parameters } from '../util/query-parameters';
|
||||||
|
|
||||||
const exportParameters: Parameters = {
|
const exportParameters = {
|
||||||
format: {
|
format: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: ['json', 'yaml'],
|
enum: ['json', 'yaml'],
|
||||||
@ -44,10 +45,109 @@ const exportParameters: Parameters = {
|
|||||||
description:
|
description:
|
||||||
'Whether environments should be included in the exported data.',
|
'Whether environments should be included in the exported data.',
|
||||||
},
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
type ExportParams = typeof exportParameters;
|
||||||
|
|
||||||
|
type Mutable = {
|
||||||
|
[Property in keyof ExportParams]: { type: ExportParams[Property]['type'] };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const p = {
|
||||||
|
$id: 'th',
|
||||||
|
type: 'object',
|
||||||
|
properties: createQueryParameters(exportParameters).reduce(
|
||||||
|
(acc, next: OpenAPIV3.ParameterObject) => ({
|
||||||
|
...acc,
|
||||||
|
[next.name]: {
|
||||||
|
type: (next.schema as OpenAPIV3.SchemaObject).type,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{} as Partial<Mutable>,
|
||||||
|
) as Mutable,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type ExpType = FromSchema<typeof p>;
|
||||||
|
|
||||||
export const exportQueryParameters = createQueryParameters(exportParameters);
|
export const exportQueryParameters = createQueryParameters(exportParameters);
|
||||||
|
|
||||||
|
const s = {
|
||||||
|
$id: '#/components/schemas/exportParametersSchema2',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: 'format',
|
||||||
|
description:
|
||||||
|
'Desired export format. Must be either `json` or `yaml`.',
|
||||||
|
schema: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['json', 'yaml'],
|
||||||
|
default: 'json',
|
||||||
|
},
|
||||||
|
in: 'query',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'download',
|
||||||
|
description:
|
||||||
|
'Whether exported data should be downloaded as a file.',
|
||||||
|
schema: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
in: 'query',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'strategies',
|
||||||
|
description:
|
||||||
|
'Whether strategies should be included in the exported data.',
|
||||||
|
schema: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
in: 'query',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'featureToggles',
|
||||||
|
description:
|
||||||
|
'Whether feature toggles should be included in the exported data.',
|
||||||
|
schema: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
in: 'query',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'projects',
|
||||||
|
description:
|
||||||
|
'Whether projects should be included in the exported data.',
|
||||||
|
schema: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
in: 'query',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'tags',
|
||||||
|
description:
|
||||||
|
'Whether tag types, tags, and feature_tags should be included in the exported data.',
|
||||||
|
schema: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
in: 'query',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'environments',
|
||||||
|
description:
|
||||||
|
'Whether environments should be included in the exported data.',
|
||||||
|
schema: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
in: 'query',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} as const;
|
||||||
|
|
||||||
export const exportParametersSchema = {
|
export const exportParametersSchema = {
|
||||||
$id: '#/components/schemas/exportParametersSchema',
|
$id: '#/components/schemas/exportParametersSchema',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
|||||||
@ -2,14 +2,14 @@ import { OpenAPIV3 } from 'openapi-types';
|
|||||||
|
|
||||||
export type ParameterType = OpenAPIV3.NonArraySchemaObjectType;
|
export type ParameterType = OpenAPIV3.NonArraySchemaObjectType;
|
||||||
|
|
||||||
export type ParameterDetails<U> = {
|
export type ParameterDetails<U> = Readonly<{
|
||||||
description: string;
|
description: string;
|
||||||
type: ParameterType;
|
type: ParameterType;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
default?: U;
|
default?: U;
|
||||||
enum?: [U, ...U[]];
|
enum?: Readonly<[U, ...U[]]>;
|
||||||
example?: U;
|
example?: U;
|
||||||
};
|
}>;
|
||||||
|
|
||||||
export type Parameters = {
|
export type Parameters = {
|
||||||
[parameterName: string]: ParameterDetails<unknown>;
|
[parameterName: string]: ParameterDetails<unknown>;
|
||||||
@ -25,7 +25,7 @@ export const toParamObject = (
|
|||||||
required: details.required,
|
required: details.required,
|
||||||
schema: {
|
schema: {
|
||||||
type: details.type,
|
type: details.type,
|
||||||
enum: details.enum,
|
enum: details.enum as unknown as any[],
|
||||||
default: details.default,
|
default: details.default,
|
||||||
},
|
},
|
||||||
in: 'query',
|
in: 'query',
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import { createResponseSchema } from '../../openapi/util/create-response-schema'
|
|||||||
import {
|
import {
|
||||||
exportQueryParameters,
|
exportQueryParameters,
|
||||||
ExportParametersSchema,
|
ExportParametersSchema,
|
||||||
|
ExpType,
|
||||||
} from '../../openapi/spec/export-parameters-schema';
|
} from '../../openapi/spec/export-parameters-schema';
|
||||||
import { emptyResponse } from '../../openapi/util/standard-responses';
|
import { emptyResponse } from '../../openapi/util/standard-responses';
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ class StateController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async export(
|
async export(
|
||||||
req: Request<unknown, unknown, unknown, ExportParametersSchema>,
|
req: Request<unknown, unknown, unknown, ExpType>,
|
||||||
res: Response,
|
res: Response,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { format } = req.query;
|
const { format } = req.query;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user