Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Add swagger json #46

Merged
merged 18 commits into from
Oct 17, 2019
Merged

Conversation

nik-john
Copy link
Contributor

@nik-john nik-john commented Oct 15, 2019

This PR adds the first draft of the swagger.json file that enumerates the Open API specs for the Chapter UI project.

PS: The document is not complete and the reason why I am raising this PR is so no one else is working on this in parallel. Please commit your open API spec changes to this PR

#17

EVERYONE IS WELCOME to commit to this PR with improvements - this is very WIP with lots of rough edges. Because I don't have a lot of time to spend on this, the idea was to just get this off the ground so we can make it better as we go along

@nik-john
Copy link
Contributor Author

For the uninitiated, you can upload the swagger.json file to http://editor.swagger.io/ to see it in action

@kognise kognise mentioned this pull request Oct 16, 2019
7 tasks
@QuincyLarson
Copy link
Contributor

@nik-john Awesome. I've heard of Swagger but we haven't used it in a project before.

Would anyone who's familiar with Swagger be interested in helping QA this PR?

@nik-john
Copy link
Contributor Author

@QuincyLarson I've not got a ton of experience on it either but if you want to see it in action, you can upload the swagger.json file to http://editor.swagger.io - it's extremely useful for a number of reasons, not least of which is to agree on a API schema. Here are some screenshots of the file in action

Screen Shot 2019-10-15 at 11 58 01 PM

Screen Shot 2019-10-15 at 11 58 14 PM

Screen Shot 2019-10-15 at 11 58 23 PM

@koundinya
Copy link

are we going to use the swagger doc to create server and client stubs? I see that as a way to unblock front end devs and also write test cases :)

@koundinya
Copy link

My suggestion would also to have a linter in place early for swagger, I have seen swagger docs get messy very quickly, I like using speccy for this ~ https://github.com/wework/speccy

@nik-john
Copy link
Contributor Author

@koundinya @email2vimalraj Would you like to contribute to this PR and review it? @email2vimalraj - I saw your comment on another PR about the open API spec, therefore tagging you

@email2vimalraj
Copy link
Contributor

@nik-john: Super fast man. I would definitely help reviewing it. I’m currently at work and will take a look tonight.

@nik-john
Copy link
Contributor Author

My suggestion would also to have a linter in place early for swagger, I have seen swagger docs get messy very quickly, I like using speccy for this ~ https://github.com/wework/speccy

Speccy seems to be very interesting - I've used JSON Schemas for this a while ago, but this is something we should do once the app is in good shape

@email2vimalraj
Copy link
Contributor

OpenApi supports yaml too, the linting won’t be an issue in that case

@koundinya
Copy link

"but this is something we should do once the app is in good shape" agree! 👍

@MirzaChilman
Copy link
Contributor

The pr looks interesting, definitely gonna review it later tonight utc+7

@iansltx
Copy link
Contributor

iansltx commented Oct 16, 2019

Nitpick here: this is using v2.0 of the spec. OpenAPI Spec 3 has been out for awhile, to the point that swagger-ui supports it just fine for visualizing, and for an API as simple as this one should be we shouldn't end up with too many rough edges. I recently built an OAS3-documented API, albeit via (quite similar to the end output format and manually written) annotations that compiled to JSON rather than building the doc directly by hand, in answer to the inevitable questions y'all should be asking me: "why do you have an opinion on this and why do we care about your opinion" ;)

@iansltx
Copy link
Contributor

iansltx commented Oct 16, 2019

With the above said, if this spec gets rewritten as OAS3.0, I'd be happy to review it beyond a cursory glance via the Swagger editor.

@nik-john
Copy link
Contributor Author

@iansltx I haven't particularly worked with Swagger/OAS3 recently, but I have converted the JSON to OAS3. Do take a look sometime

@iansltx
Copy link
Contributor

iansltx commented Oct 16, 2019

Thanks! Calling it a night shortly, but if this hasn't moved out from under my by the time I'm back online again I'll absolutely look through.

Copy link
Contributor

@allella allella left a comment

Choose a reason for hiding this comment

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

Looks good here. Simple find/replace.

Copy link

@hskrasek hskrasek left a comment

Choose a reason for hiding this comment

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

@iansltx Asked me to take a look at this due to some time constraints. Everything looks pretty solid, but I do have some suggested changes looking everything over.

I do agree with the comments about adding some OpenAPI linting in place either using Speccy or Stoplight.io's Spectral.

api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated
"externalDocs": {
"description": "Find out more about Swagger",
"url": "http://swagger.io"
},

Choose a reason for hiding this comment

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

Are there chapter.io docs that this externalDocs section could refer to instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have one as yet - this was just meant as placeholder

@vaibhavsingh97
Copy link
Member

@nik-john Aren't we using GraphQL? if yes then do we really need swagger documentation as afik GraphQL comes with documentation. Also, I know it's not a perfect documentation but we can override documentation and can always add something.

@nik-john
Copy link
Contributor Author

nik-john commented Oct 16, 2019

@vaibhavsingh97 #2 (comment)

Postgres with Sequalize (no GraphQL for now)

The consensus was that we aren't using GraphQL (unless something changed that I was unaware about)

@vaibhavsingh97
Copy link
Member

vaibhavsingh97 commented Oct 16, 2019

Thanks, @nik-john for updating me. Will review it

@nik-john
Copy link
Contributor Author

@hskrasek About this

I do agree with the comments about adding some OpenAPI linting in place either using Speccy or Stoplight.io's Spectral.

Would you be open to chipping in with this implementation? I'm afraid I don't have a lot of experience with either of those

@vaibhavsingh97
Copy link
Member

vaibhavsingh97 commented Oct 16, 2019

Also, the YAML file would be easier to digest and read. Would love to know about your opinion

Would you be open to chipping in with this implementation? I'm afraid I don't have a lot of experience with either of those

I guess, just install the tool locally and try to run the tool across swagger.json and fix the linting issue. I can help you with that if you need any help

PS: Fixing one issue, I found

nik-john and others added 4 commits October 16, 2019 20:55
Co-Authored-By: Franco Correa <franco.correa@auth0.com>
Co-Authored-By: Franco Correa <franco.correa@auth0.com>
Co-Authored-By: Franco Correa <franco.correa@auth0.com>
Co-Authored-By: Franco Correa <franco.correa@auth0.com>
@orbitalhop
Copy link

are we going to use the swagger doc to create server and client stubs? I see that as a way to unblock front end devs and also write test cases :)

@koundinya, were you thinking of using the codegen CLI tool (provided by swagger) to achieve this? I've found in the past that it's picky about the files exactly matching the swagger schema, so as long as we validate/lint correctly as discussed above then that shouldn't 🤞be a problem.

Here's a link for the curious:
https://swagger.io/tools/swagger-codegen/

@allella
Copy link
Contributor

allella commented Oct 17, 2019

@francocorreasosa deferring to you on merging this one. I thought / requested QL give @nik-john write, but not sure that he did.

@bernhard-hofmann
Copy link
Contributor

I'm going to be picky because we're laying foundations here that will influence everything we build on it.

The POST routes should be singular to add singular entities. I.e. /location not /locations. The GET methods follow this so it would seem consistent to me.

I've not fully reviewed it yet, but wanted to mention this before it gets accepted.

@iansltx
Copy link
Contributor

iansltx commented Oct 17, 2019

Definitely a case of "pick one" for resource naming. Either singular (which makes POSTs and collections feel awkward) or plural (which IMO doesn't, but others may argue that it has other issues). But be consistent either way.

@nik-john
Copy link
Contributor Author

@bernhard-hofmann @iansltx I think it makes sense to be consistent considering that there's no global standard for pluralization. I'll move everything to plural https://stackoverflow.com/questions/6845772/rest-uri-convention-singular-or-plural-name-of-resource-while-creating-it

@bernhard-hofmann
Copy link
Contributor

If you're posting one location, why would singular feel awkward?

I think we're on the same page that the resource is either a (singular) location, group, etc, or it could be a collection of locations, groups, etc

I mentioned it because the POST to locations (plural) had a description indicating it was to add a (single) location.

@nik-john
Copy link
Contributor Author

I've changed all the resources to be plural. I think it makes sense to have:

POST https://api.chapter.io/v1/chapters => chapters.push(req.body.chapter);
GET https://api.chapter.io/v1/chapters=> chapters
GET https://api.chapter.io/v1/chapters/:chapterId => chapters.find(c => c.id === req.params.chapterId); etc. considering that it will be impossible to come to a consensus here - it's a matter of picking one and going with it imo. Could you go through the updated doc and see?

Copy link
Contributor

@iansltx iansltx left a comment

Choose a reason for hiding this comment

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

Bunch of comments here.

Main takeaways:

  1. Not sure we need 400s for invalid ID type. IMO that should end up as a 404; the client shouldn't care about whether an ID was a valid UUID or not.
  2. Flatten out route structures so you don't have to include a ton of IDs just to get to a single sub-resource. The deepest things should be is /resource/{id}/subresource, with that subresource collection containing entities that are available at the top level.
  3. IDs should be UUIDs across the board.
  4. To avoid locking things in, don't define schemas for entities that aren't referenced in endpoints.

Additionally, I'm not seeing requestBody schemas for anything, though I saw a requestBodies path referenced in at least one of the endpoints. Guessing that e.g. user creation will look a bit different than a user PATCH, so we do want to document that difference.

Finally, having a /me endpoint or similar so the currently logged in user can get their info (e.g. chapter membership, upcoming RSVP'd events, etc.) would be useful. Just in case opaque tokens end up getting used for auth, or in case a client wants to treat a JWT as opaque.

package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Outdated Show resolved Hide resolved
api/swagger.json Show resolved Hide resolved
@nik-john
Copy link
Contributor Author

@iansltx Thanks for the detailed review. I'll make the fixes tomorrow when I get some time. TIL a lot of stuff 🙇

@allella
Copy link
Contributor

allella commented Oct 17, 2019

@francocorreasosa this still seems to be the pinch point for a lot of other PRs and progress. I know you can help move this along better than me so when @nik-john rejoins I'm hoping you guys can get something merged in.

@QuincyLarson
Copy link
Contributor

@nik-john I'm thrilled that you're learning so much.

It sounds like merging this will help unblock a lot of other contributors.

This is better done than perfect, if that makes sense. So I encourage us to merge as soon as we can, then make other tweaks / improvements afterward.

@nik-john
Copy link
Contributor Author

@QuincyLarson Agreed. I'll try and accommodate as many changes as possible as suggested above in the next half hour and then let's plan to merge. Any further changes can be made to master

@nik-john
Copy link
Contributor Author

@iansltx I have addressed a bunch of stuff you brought up - could you please take a second look? I did not get the time to address a few (including the route hierarchy changes) - so I would appreciate it if you could take a stab at it. If you think that can slide for now, I would recommend getting the PR merged asap so everyone else is unblocked

cc: @QuincyLarson

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

Successfully merging this pull request may close these issues.