-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
fix: improve schema validation #1071
Conversation
Prove it - let's see that before and after screenshot for whatever cases were improved :P. |
Given openapi: 3.0.1
info:
title: Example $ref error
version: 1.0.0
paths:
/user:
get:
operationId: getUser
responses:
"200":
description: An Example
content:
application/json:
schema:
type: object
properties:
user_id: 12345 Given openapi: 3.0.1
info:
title: Example $ref error
version: 1.0.0
paths:
/user:
get:
operationId: getUser
responses:
"200":
description: An Example
content:
application/json:
schema:
type: object
properties: Given openapi: 3.0.1
info:
title: Example $ref error
version: 1.0.0
paths:
/user:
get:
operationId: getUser
responses:
"200":
description: An Example
parameters: Given openapi: 3.0.1
info:
title: Example $ref error
version: 1.0.0
paths:
/user:
get:
operationId: getUser
parameters:
- type: string
name: module_id
in: path
required: true
schema:
type: string
description: Module ID
responses: Etc, etc. |
import { IFunction, IFunctionContext } from '../../../types'; | ||
|
||
// /shrug | ||
function prepareResults(errors: AJV.ErrorObject[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip As this is about to become a somewhat cornerstone of schema validation, how about covering it with targeted unit tests to better express what we expect from this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Also more comments on why would help future maintainers, our future selves (and my current self) understand whats going on better.
@P0lip this is amazing! It's the biggest issue we have with Spectral and it looks like you've nailed it. I know it might feel annoying and redundant, but can you make a test harness for each of those examples you put in? As it's such a complicated and important thing, I want to smother it with coverage so it doesn't rear its ugly head again. |
31034f0
to
8cf81f2
Compare
@nulltoken @philsturgeon do you have any additional comments or suggestions? |
To be honest, I've read the code of By taking a look at the results of the integration tests, I can see that it indeed works, however, I'd really like to get a better understanding at how it works and solves the initial issue. If we ever need to extend/patch this function, I'd feel more at ease with a set of tight unit tests that precisely express the behavioral contract of the function. |
Yep, I'll prepare errors. It'll certainly make it easier for everyone to reason about that function when you show what kind of errors it filters out and how it does it. |
@nulltoken added some. LMK if it's more clear now. In general all it does is removal of "evil" errors. |
@nulltoken done! |
Tried to use latest develop branch with this fix applied, have a different error from my issue I have
I see no problem with this JSON schema file, see https://github.com/maasglobal/maas-schemas/blob/develop/maas-schemas/schemas/core/components/travel-mode.json |
Is @philsturgeon any clue? |
Fixes #403
Checklist
Does this PR introduce a breaking change?
Besides addressing 403, it also improves the general readability and consistency of error messages generated by
schema
function.