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

feat: add /diff endpoint #69

Merged
merged 7 commits into from
Mar 29, 2022
Merged

feat: add /diff endpoint #69

merged 7 commits into from
Mar 29, 2022

Conversation

ritik307
Copy link
Contributor

@ritik307 ritik307 commented Mar 5, 2022

Description

  • Update openapi.yaml
  • Update package.json
  • Update src/controllers/diff.controller.ts
  • Update src/services/diff.service.ts

Related issue(s)

Fixes #56

@ritik307 ritik307 marked this pull request as draft March 5, 2022 15:29
@ritik307 ritik307 changed the title added /diff feat: /diff Mar 5, 2022
@ritik307
Copy link
Contributor Author

ritik307 commented Mar 5, 2022

@magicmatatjahu I have to init the /diff. Let me know if I am on the right path. 🙂

Copy link
Member

@BOLT04 BOLT04 left a 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 Show resolved Hide resolved

private async difference(req: Request, res: Response, next: NextFunction) {
try {
const output = await diff(req.body.asyncapi, req.body.other);
Copy link
Member

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 🙂

const output = await diff(req.body.asyncapi, req.body.other);
res.status(200).json(output);
} catch (err) {
return next(err);
Copy link
Member

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 👍

Copy link
Member

@magicmatatjahu magicmatatjahu left a 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 :)

openapi.yaml Outdated Show resolved Hide resolved
openapi.yaml Outdated Show resolved Hide resolved
openapi.yaml Outdated Show resolved Hide resolved
Comment on lines 12 to 13
private ajv: Ajv;
diffService: DiffService;
Copy link
Member

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.

src/controllers/diff.controller.ts Outdated Show resolved Hide resolved
src/controllers/diff.controller.ts Outdated Show resolved Hide resolved
src/controllers/diff.controller.ts Outdated Show resolved Hide resolved
src/services/diff.service.ts Outdated Show resolved Hide resolved
src/controllers/diff.controller.ts Outdated Show resolved Hide resolved
@ritik307
Copy link
Contributor Author

ritik307 commented Mar 7, 2022

@magicmatatjahu I have made the changes according to my understanding. Kindly look into them.🙂

@magicmatatjahu magicmatatjahu changed the title feat: /diff feat: add /diff endpoint Mar 10, 2022
Copy link
Member

@magicmatatjahu magicmatatjahu left a 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 :)

openapi.yaml Outdated Show resolved Hide resolved
openapi.yaml Outdated Show resolved Hide resolved
openapi.yaml Outdated Show resolved Hide resolved
openapi.yaml Outdated Show resolved Hide resolved
Comment on lines 11 to 17
.post('/v1/diff')
.send({
asyncapi: './diff/asyncapi-diff-test-1.yaml',
other: './diff/asyncapi-diff-test-2.yaml',

})
.expect(200);
Copy link
Member

Choose a reason for hiding this comment

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

That test is broken :)

src/controllers/diff.controller.ts Outdated Show resolved Hide resolved
openapi.yaml Outdated Show resolved Hide resolved
src/controllers/diff.controller.ts Outdated Show resolved Hide resolved
@ritik307
Copy link
Contributor Author

@magicmatatjahu I have made changes and also improved my test but it's still failing 😕

@ritik307 ritik307 requested a review from magicmatatjahu March 13, 2022 18:08
Comment on lines +188 to +348
type: array
minItems: 2
Copy link
Member

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 :)

Suggested change
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']
Copy link
Member

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?

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 am not able to get this part. How should I pass the file like using fs or is there any other way?

Copy link
Member

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

(two AsyncAPI documents whose are different each other) and send it as value:

{
  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']
Copy link
Member

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

(two AsyncAPI documents whose are different each other) and send it as value:

{
  asyncapis: [asyncapi1, asyncapi2]
}

Please also check response data in test :)

@ritik307 ritik307 marked this pull request as ready for review March 24, 2022 16:47
@ritik307
Copy link
Contributor Author

@magicmatatjahu I have made changes but I am still facing issues in the test. Kindly help me out 😢😢

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@magicmatatjahu
Copy link
Member

/rtm

@asyncapi-bot
Copy link
Contributor

Hello, @magicmatatjahu! 👋🏼
This PR is not up to date with the base branch and can't be merged.
You can add comment to this PR with text: /autoupdate or /au. This way you ask our bot to perform regular updates for you. The only requirement for this to work is to enable Allow edits from maintainers option in your PR. Otherwise the only option that you have is to manually update your branch with latest version of the base branch.
Thanks 😄

@asyncapi-bot asyncapi-bot merged commit 4dac650 into asyncapi:master Mar 29, 2022
@magicmatatjahu
Copy link
Member

@ritik307 Thanks for contribution and patience! I hope you learned something new :)

@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 0.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ritik307
Copy link
Contributor Author

ritik307 commented Mar 30, 2022

@magicmatatjahu Thanks for providing the opportunity to contribute. I surely learned a lot of things while contributing.😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add implementation for /diff path
4 participants