1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

openapi: enable strict schema validation by default and fix (#4355)

Enable strict schema validation by default. It can still be overridden
by explicitly setting it to false.

I've also fixed the validation errors that appeared when turning it on.
I've opted for the simplest route and changed the schemas to comply with
the tests.
This commit is contained in:
Thomas Heartman 2023-07-31 11:04:13 +02:00 committed by GitHub
parent 799387e482
commit 1481c13b61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 19 deletions

View File

@ -12,15 +12,6 @@ exports[`tokenUserSchema 1`] = `
},
"schemaPath": "#/required",
},
{
"instancePath": "",
"keyword": "required",
"message": "must have required property 'name'",
"params": {
"missingProperty": "name",
},
"schemaPath": "#/required",
},
{
"instancePath": "",
"keyword": "required",

View File

@ -29,6 +29,7 @@ export const publicSignupTokenSchema = {
description:
'The public signup link for the token. Users who follow this link will be taken to a signup page where they can create an Unleash user.',
type: 'string',
nullable: true,
example:
'https://sandbox.getunleash.io/enterprise/new-user?invite=a3c84b25409ea8ca1782ef17f94a42fc',
},

View File

@ -6,7 +6,7 @@ export const tokenUserSchema = {
type: 'object',
additionalProperties: false,
description: 'A user identified by a token',
required: ['id', 'name', 'email', 'token', 'createdBy', 'role'],
required: ['id', 'email', 'token', 'createdBy', 'role'],
properties: {
id: {
type: 'integer',

View File

@ -25,6 +25,7 @@ export const userSchema = {
description: 'Name of the user',
type: 'string',
example: 'User',
nullable: true,
},
email: {
description: 'Email of the user',

View File

@ -18,11 +18,11 @@ import {
resourceCreatedResponseSchema,
} from '../../openapi/util/create-response-schema';
import { TagTypesSchema } from '../../openapi/spec/tag-types-schema';
import { ValidateTagTypeSchema } from '../../openapi/spec/validate-tag-type-schema';
import {
tagTypeSchema,
TagTypeSchema,
} from '../../openapi/spec/tag-type-schema';
validateTagTypeSchema,
ValidateTagTypeSchema,
} from '../../openapi/spec/validate-tag-type-schema';
import { TagTypeSchema } from '../../openapi/spec/tag-type-schema';
import { UpdateTagTypeSchema } from '../../openapi/spec/update-tag-type-schema';
import { OpenApiService } from '../../services/openapi-service';
import {
@ -180,10 +180,16 @@ class TagTypeController extends Controller {
res: Response<ValidateTagTypeSchema>,
): Promise<void> {
await this.tagTypeService.validate(req.body);
this.openApiService.respondWithValidation(200, res, tagTypeSchema.$id, {
valid: true,
tagType: req.body,
});
this.openApiService.respondWithValidation(
200,
res,
validateTagTypeSchema.$id,
{
valid: true,
tagType: req.body,
},
);
}
async createTagType(

View File

@ -179,7 +179,16 @@ async function createApp(
server: {
unleashUrl: 'http://localhost:4242',
},
...customOptions,
...{
...customOptions,
experimental: {
...(customOptions?.experimental ?? {}),
flags: {
strictSchemaValidation: true,
...(customOptions?.experimental?.flags ?? {}),
},
},
},
});
const services = createServices(stores, config, db);
const unleashSession = sessionDb(config, undefined);