Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Jul 31, 2023

Conversation

thomasheartman
Copy link
Contributor

@thomasheartman thomasheartman commented Jul 28, 2023

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.

@sonatype-lift
Copy link

sonatype-lift bot commented Jul 28, 2023

Sonatype Lift is retiring

Sonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@vercel
Copy link

vercel bot commented Jul 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2023 9:07am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Jul 28, 2023 9:07am

@@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what it means for this to be null, but it definitely can be in our tests. Does that mean we need to change our tests or is it actually nullable?

@@ -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'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name property is missing in responses in pretty much all of our tests, so I'm guessing it's not there. Should it be?

In fact, I don't know if it is ever used 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we definitely do use it sometimes: it's explicitly assigned to in UserService. I'm guessing that we do return it from the reset-password-controller as well if the user has a name.

@@ -25,6 +25,7 @@ export const userSchema = {
description: 'Name of the user',
type: 'string',
example: 'User',
nullable: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is null if the user has no name.

Comment on lines +184 to +192
this.openApiService.respondWithValidation(
200,
res,
validateTagTypeSchema.$id,
{
valid: true,
tagType: req.body,
},
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that's changed here (aside from formatting) is that we use the correct validateTagTypeSchema.$id instead of tagTypeSchema.$id in the response. This was probably a typo or copy/paste error.

Comment on lines +182 to +191
...{
...customOptions,
experimental: {
...(customOptions?.experimental ?? {}),
flags: {
strictSchemaValidation: true,
...(customOptions?.experimental?.flags ?? {}),
},
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable strict schema validation unless it's been explicitly disabled. This applies to all app setup methods.

@thomasheartman thomasheartman merged commit 1481c13 into main Jul 31, 2023
16 checks passed
@thomasheartman thomasheartman deleted the openapi/default-strict-schema-validation branch July 31, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants