-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
refactor: combine asyncapi validation with request body #78
refactor: combine asyncapi validation with request body #78
Conversation
oneOf: | ||
- type: string # can be in YAML format | ||
- $ref: https://raw.githubusercontent.com/asyncapi/spec-json-schemas/master/schemas/2.0.0.json | ||
- $ref: https://raw.githubusercontent.com/asyncapi/spec-json-schemas/master/schemas/2.1.0.json | ||
- $ref: https://raw.githubusercontent.com/asyncapi/spec-json-schemas/master/schemas/2.2.0.json | ||
- $ref: https://raw.githubusercontent.com/asyncapi/spec-json-schemas/master/schemas/2.3.0.json | ||
Template: | ||
AsyncAPIDocuments: |
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.
I don't see this schema being used anywhere. Was this made on purpose?
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.
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.
Not a big fan of adding things that are not used TBH. But I understand you do for helping the other two PR's so, 👍
export interface ValidationMiddlewareOptions { | ||
path: string; | ||
method: 'all' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head', | ||
documents?: Record<string, 'single' | 'list'>; |
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.
Is this needed? Can't we just base the validation on the number of documents passed?
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.
Do you mean list/single? 🤔 I don't see any problems with this approach. Ok, I'll change it, thanks!
@smoya I applied changes, please check again :) |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
- '2.1.0' | ||
- '2.2.0' | ||
- '2.3.0' | ||
- 'latest' |
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.
I just realized latest
is a dangerous option here since at some point it could differ with what the real latest spec version is unless we sync spec releases with the update of this list and the parser-js
dependency update supporting that version in server-api
. Maybe this can go into a new issue?
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.
Yes, but I wouldn't treat it as a huge problem. We always release every package after every spec release so we don't miss it.
try { | ||
for (const field of documents) { | ||
const body = req.body[String(field)]; | ||
if (Array.isArray(body)) { |
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.
Much simpler IMHO, isn't?
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.
LGTM! Nice work @magicmatatjahu !
/rtm |
Hello, @magicmatatjahu! 👋🏼 |
🎉 This PR is included in version 0.7.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Description
At the moment we validate AsyncAPI documents in separate middleware as well
request body
. That PR merge functionalities to one middleware and also introduce validation of multiple AsyncAPI documents. It's very important for PR such as #70 to validate not onlyasyncapi
field but also another one likebase
or list of documents likeasyncapis
.validationMiddleware
openapi.yaml