mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
Wip: fix openapi spec
This commit is contained in:
parent
012da8469f
commit
5af24d0a11
@ -3,7 +3,6 @@ import { FromSchema } from 'json-schema-to-ts';
|
|||||||
export const clientFeaturesQuerySchema = {
|
export const clientFeaturesQuerySchema = {
|
||||||
$id: '#/components/schemas/clientFeaturesQuerySchema',
|
$id: '#/components/schemas/clientFeaturesQuerySchema',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: [],
|
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
properties: {
|
properties: {
|
||||||
tag: {
|
tag: {
|
||||||
|
@ -1,5 +1,34 @@
|
|||||||
import { FromSchema } from 'json-schema-to-ts';
|
import { FromSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
|
export const exportParameters = {
|
||||||
|
format: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['json', 'yaml'],
|
||||||
|
default: 'json',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
download: {
|
||||||
|
type: 'boolean',
|
||||||
|
default: 'false',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
strategies: {
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
|
featureToggles: {
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
|
projects: {
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
|
tags: {
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
|
environments: {
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const exportParametersSchema = {
|
export const exportParametersSchema = {
|
||||||
$id: '#/components/schemas/exportParametersSchema',
|
$id: '#/components/schemas/exportParametersSchema',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -4,7 +4,6 @@ export const feedbackSchema = {
|
|||||||
$id: '#/components/schemas/feedbackSchema',
|
$id: '#/components/schemas/feedbackSchema',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
additionalProperties: false,
|
additionalProperties: false,
|
||||||
required: [],
|
|
||||||
properties: {
|
properties: {
|
||||||
userId: {
|
userId: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
39
src/lib/openapi/util/request-parameters.test.ts
Normal file
39
src/lib/openapi/util/request-parameters.test.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { SchemaObject } from 'ajv';
|
||||||
|
import fc from 'fast-check';
|
||||||
|
import { createRequestParameters } from './request-parameters';
|
||||||
|
|
||||||
|
describe('request parameter utils', () => {
|
||||||
|
it('turns an object of names and descriptions into a an expected parameter list', () => {
|
||||||
|
fc.assert(
|
||||||
|
fc.property(
|
||||||
|
fc.dictionary(fc.string({ minLength: 1 }), fc.string()),
|
||||||
|
(parameters) => {
|
||||||
|
const result = createRequestParameters(parameters);
|
||||||
|
|
||||||
|
return result.every((paramsObject) => {
|
||||||
|
return (
|
||||||
|
paramsObject.description ===
|
||||||
|
parameters[paramsObject.name]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('says every parameter is of type string and goes in the query', () => {
|
||||||
|
fc.assert(
|
||||||
|
fc.property(
|
||||||
|
fc.dictionary(fc.string({ minLength: 1 }), fc.string()),
|
||||||
|
|
||||||
|
(parameters) => {
|
||||||
|
return createRequestParameters(parameters).every(
|
||||||
|
(paramsObject) =>
|
||||||
|
(paramsObject.schema as SchemaObject).type ===
|
||||||
|
'string' && paramsObject.in === 'query',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
25
src/lib/openapi/util/request-parameters.ts
Normal file
25
src/lib/openapi/util/request-parameters.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { OpenAPIV3 } from 'openapi-types';
|
||||||
|
|
||||||
|
// type ParameterDetails = {
|
||||||
|
// description: string;
|
||||||
|
// } & (
|
||||||
|
// | { type: 'boolean'; default?: boolean; enum?: boolean[] }
|
||||||
|
// | { type: 'string'; default?: string; enum?: string[] }
|
||||||
|
// | { type: 'number'; default?: number; enum?: number[] }
|
||||||
|
// );
|
||||||
|
|
||||||
|
// { [parameterName: string]: Parameter };
|
||||||
|
// type Parameters = Record<ParameterName, ParameterDetails>;
|
||||||
|
|
||||||
|
type ParameterName = string;
|
||||||
|
type Description = string;
|
||||||
|
|
||||||
|
export const createRequestParameters = (
|
||||||
|
params: Record<ParameterName, Description>,
|
||||||
|
): OpenAPIV3.ParameterObject[] =>
|
||||||
|
Object.entries(params).map(([name, description]) => ({
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
schema: { type: 'string' },
|
||||||
|
in: 'query',
|
||||||
|
}));
|
@ -14,8 +14,12 @@ import { IAuthRequest } from '../unleash-types';
|
|||||||
import { OpenApiService } from '../../services/openapi-service';
|
import { OpenApiService } from '../../services/openapi-service';
|
||||||
import { createRequestSchema } from '../../openapi/util/create-request-schema';
|
import { createRequestSchema } from '../../openapi/util/create-request-schema';
|
||||||
import { createResponseSchema } from '../../openapi/util/create-response-schema';
|
import { createResponseSchema } from '../../openapi/util/create-response-schema';
|
||||||
import { ExportParametersSchema } from '../../openapi/spec/export-parameters-schema';
|
import {
|
||||||
|
exportParametersSchema,
|
||||||
|
ExportParametersSchema,
|
||||||
|
} from '../../openapi/spec/export-parameters-schema';
|
||||||
import { emptyResponse } from '../../openapi/util/standard-responses';
|
import { emptyResponse } from '../../openapi/util/standard-responses';
|
||||||
|
import { createRequestParameters } from 'lib/openapi/util/request-parameters';
|
||||||
|
|
||||||
const upload = multer({ limits: { fileSize: 5242880 } });
|
const upload = multer({ limits: { fileSize: 5242880 } });
|
||||||
const paramToBool = (param, def) => {
|
const paramToBool = (param, def) => {
|
||||||
@ -75,11 +79,7 @@ class StateController extends Controller {
|
|||||||
responses: {
|
responses: {
|
||||||
200: createResponseSchema('stateSchema'),
|
200: createResponseSchema('stateSchema'),
|
||||||
},
|
},
|
||||||
parameters: [
|
parameters: createRequestParameters(exportParametersSchema),
|
||||||
{
|
|
||||||
$ref: '#/components/schema/exportParametersSchema',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user