-
-
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
feat: add /diff endpoint #69
Conversation
@magicmatatjahu I have to init the |
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.
Hi @ritik307, thanks for working on this 👍.
I have some initial thoughts, but in general, you're going in the right direction 🙂.
Let me know what you think of my comments.
pinging @magicmatatjahu since he probably knows the diff package better than me 😃
src/controllers/diff.controller.ts
Outdated
|
||
private async difference(req: Request, res: Response, next: NextFunction) { | ||
try { | ||
const output = await diff(req.body.asyncapi, req.body.other); |
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 is an important step we should do before calling diff
, which is to validate the AsyncAPI document that is sent. Like the diff
docs say: "(...) but you must make sure that the document is valid and dereferenced.", so you can check out how we use parser
in the validate
controller 🙂
src/controllers/diff.controller.ts
Outdated
const output = await diff(req.body.asyncapi, req.body.other); | ||
res.status(200).json(output); | ||
} catch (err) { | ||
return next(err); |
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.
maybe we should make sure we call next
with an instance of ProblemException
, wdyt?
You can check out other controllers to see how they are implemented, and do something similar 👍
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.
@ritik307 Thanks for contribution, looks good, but we need to improve several things :) Please refer to my comments :)
src/controllers/diff.controller.ts
Outdated
private ajv: Ajv; | ||
diffService: DiffService; |
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.
You don't need the ajv
. We validate the request body in the https://github.com/asyncapi/server-api/blob/master/src/app.ts#L58 middleware which runs on every request. Also diffService
is unnecessary because it's only single method, so you don't need to wrap the diff
library in the separate service.
@magicmatatjahu I have made the changes according to my understanding. Kindly look into them.🙂 |
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.
Good, but we have to still improve some things :)
.post('/v1/diff') | ||
.send({ | ||
asyncapi: './diff/asyncapi-diff-test-1.yaml', | ||
other: './diff/asyncapi-diff-test-2.yaml', | ||
|
||
}) | ||
.expect(200); |
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.
That test is broken :)
@magicmatatjahu I have made changes and also improved my test but it's still failing 😕 |
type: array | ||
minItems: 2 |
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.
We should have only two files, so please add maxItems: 2
as well :)
type: array | |
minItems: 2 | |
type: array | |
minItems: 2 | |
maxItems: 2 |
return request(app.getServer()) | ||
.post('/v1/diff') | ||
.send({ | ||
asyncapis: ['./diff/asyncapi-diff-test-1.yaml','./diff/asyncapi-diff-test-2.yaml'] |
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.
You operate on content sent by the user, you cannot use filesystem because these files are sent as a value anyway, not a file path. So you need to load that files before making request and then pass them as value. Did I make it clearer?
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 am not able to get this part. How should I pass the file like using fs or is there any other way?
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.
@ritik307 You should create tests data like here
const validJSONAsyncAPI = { |
{
asyncapis: [asyncapi1, asyncapi2]
}
Please also check response data in test :)
return request(app.getServer()) | ||
.post('/v1/diff') | ||
.send({ | ||
asyncapis: ['./diff/asyncapi-diff-test-1.yaml','./diff/asyncapi-diff-test-2.yaml'] |
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.
@ritik307 You should create tests data like here
const validJSONAsyncAPI = { |
{
asyncapis: [asyncapi1, asyncapi2]
}
Please also check response data in test :)
@magicmatatjahu I have made changes but I am still facing issues in the test. Kindly help me out 😢😢 |
ef39ac2
to
c4d8ea9
Compare
Kudos, SonarCloud Quality Gate passed!
|
/rtm |
Hello, @magicmatatjahu! 👋🏼 |
@ritik307 Thanks for contribution and patience! I hope you learned something new :) |
🎉 This PR is included in version 0.8.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
@magicmatatjahu Thanks for providing the opportunity to contribute. I surely learned a lot of things while contributing.😊 |
Description
openapi.yaml
package.json
src/controllers/diff.controller.ts
src/services/diff.service.ts
Related issue(s)
Fixes #56