mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
Add option to run unleash in strict schema validation (#3073)
feat: strict schema validation
This commit is contained in:
parent
c1679a9222
commit
8ee9b75e48
@ -83,6 +83,7 @@ exports[`should create default config 1`] = `
|
||||
"proxyReturnAllToggles": false,
|
||||
"responseTimeWithAppName": false,
|
||||
"showProjectApiAccess": false,
|
||||
"strictSchemaValidation": false,
|
||||
"variantsPerEnvironment": false,
|
||||
},
|
||||
},
|
||||
@ -104,6 +105,7 @@ exports[`should create default config 1`] = `
|
||||
"proxyReturnAllToggles": false,
|
||||
"responseTimeWithAppName": false,
|
||||
"showProjectApiAccess": false,
|
||||
"strictSchemaValidation": false,
|
||||
"variantsPerEnvironment": false,
|
||||
},
|
||||
"externalResolver": {
|
||||
|
@ -21,6 +21,7 @@ export const featureSchema = {
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
},
|
||||
archived: {
|
||||
type: 'boolean',
|
||||
|
@ -16,6 +16,7 @@ export const groupSchema = {
|
||||
},
|
||||
description: {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
},
|
||||
mappingsSSO: {
|
||||
type: 'array',
|
||||
|
@ -24,6 +24,7 @@ import {
|
||||
createRequestSchema,
|
||||
createResponseSchema,
|
||||
emptyResponse,
|
||||
featureEnvironmentSchema,
|
||||
FeatureEnvironmentSchema,
|
||||
featureSchema,
|
||||
FeatureSchema,
|
||||
@ -590,7 +591,13 @@ export default class ProjectFeaturesController extends Controller {
|
||||
const result = {
|
||||
...environmentInfo,
|
||||
strategies: environmentInfo.strategies.map((strategy) => {
|
||||
const { strategyName, ...rest } = strategy;
|
||||
const {
|
||||
strategyName,
|
||||
projectId: project,
|
||||
environment: environmentId,
|
||||
createdAt,
|
||||
...rest
|
||||
} = strategy;
|
||||
return { ...rest, name: strategyName };
|
||||
}),
|
||||
};
|
||||
@ -598,7 +605,7 @@ export default class ProjectFeaturesController extends Controller {
|
||||
this.openApiService.respondWithValidation(
|
||||
200,
|
||||
res,
|
||||
featureSchema.$id,
|
||||
featureEnvironmentSchema.$id,
|
||||
serializeDates(result),
|
||||
);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import {
|
||||
import { ApiOperation } from '../openapi/util/api-operation';
|
||||
import { Logger } from '../logger';
|
||||
import { validateSchema } from '../openapi/validate';
|
||||
import { IFlagResolver } from '../types';
|
||||
|
||||
export class OpenApiService {
|
||||
private readonly config: IUnleashConfig;
|
||||
@ -18,8 +19,11 @@ export class OpenApiService {
|
||||
|
||||
private readonly api: IExpressOpenApi;
|
||||
|
||||
private flagResolver: IFlagResolver;
|
||||
|
||||
constructor(config: IUnleashConfig) {
|
||||
this.config = config;
|
||||
this.flagResolver = config.flagResolver;
|
||||
this.logger = config.getLogger('openapi-service.ts');
|
||||
|
||||
this.api = openapi(
|
||||
@ -78,6 +82,9 @@ export class OpenApiService {
|
||||
'Invalid response:',
|
||||
JSON.stringify(errors, null, 4),
|
||||
);
|
||||
if (this.flagResolver.isEnabled('strictSchemaValidation')) {
|
||||
throw new Error(JSON.stringify(errors, null, 4));
|
||||
}
|
||||
}
|
||||
|
||||
Object.entries(headers).forEach(([header, value]) =>
|
||||
|
@ -66,6 +66,10 @@ const flags = {
|
||||
process.env.UNLEASH_EXPERIMENTAL_PROJECT_API_ACCESS,
|
||||
false,
|
||||
),
|
||||
strictSchemaValidation: parseEnvVarBoolean(
|
||||
process.env.UNLEASH_STRICT_SCHEMA_VALIDTION,
|
||||
false,
|
||||
),
|
||||
};
|
||||
|
||||
export const defaultExperimentalOptions: IExperimentalOptions = {
|
||||
|
@ -1245,6 +1245,7 @@ exports[`should serve the OpenAPI spec 1`] = `
|
||||
"type": "string",
|
||||
},
|
||||
"description": {
|
||||
"nullable": true,
|
||||
"type": "string",
|
||||
},
|
||||
"enabled": {
|
||||
@ -1524,6 +1525,7 @@ exports[`should serve the OpenAPI spec 1`] = `
|
||||
"type": "string",
|
||||
},
|
||||
"description": {
|
||||
"nullable": true,
|
||||
"type": "string",
|
||||
},
|
||||
"id": {
|
||||
|
Loading…
Reference in New Issue
Block a user