-
Notifications
You must be signed in to change notification settings - Fork 6
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
MB-9620-edit-enpoint-docs #12
Conversation
# Creating an Endpoint | ||
###### These are the various steps that are involved in creating a new endpoint. | ||
|
||
Prior to creating adding an endpoint to the Handler folder, we must first add a new endpoint definition to swagger. We are using Swagger 2.0, which is [OpenAPI](https://swagger.io/specification/v2/), a specification we use to format our RESTful APIs and provide a template for us to communicate the information in our API. |
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.
creating adding, typo
###### These are the various steps that are involved in creating a new endpoint. | ||
|
||
Prior to creating adding an endpoint to the Handler folder, we must first add a new endpoint definition to swagger. We are using Swagger 2.0, which is [OpenAPI](https://swagger.io/specification/v2/), a specification we use to format our RESTful APIs and provide a template for us to communicate the information in our API. | ||
Always start with swagger. This step creates your endpoint definition and generates the files and helper functions you will need to create your endpoint. More specifically, swagger converts JSON user input into generated Go types. |
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.
Can you add the link to the documentation that discusses the mock files?
availableToPrimeAt: | ||
format: date-time | ||
type: string | ||
x-nullable: true |
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.
It may be good to highlight that for any nullable field we need to use
x-nullable: true
x-omitempty: false
This will return null
in the response if the value doesn't exist. If we didn't all this, the field would be omitted.
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.
Oh yes! I agree it's important to mention that the field will be omitted otherwise.
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.
It may be good to highlight that for any nullable field we need to use
x-nullable: true x-omitempty: false
This will return
null
in the response if the value doesn't exist. If we didn't all this, the field would be omitted.
I'm adding the field about the field being ommitted to this line on line 69:
- x-nullable - this indicates that the value of a particular property may be null.
I also added a new bullet point and description for x-omitempty.
|
||
#### Gen files: | ||
Once you finishing updating the yaml files with the new endpoint information make sure to run your make commands to autogenerate your swagger files, or simply run `make server_run`, | ||
which runs your server and other useful make commands in one go. |
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.
Can you add you may need to run make swagger-generate
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.
It may also be helpful to add a Troubleshooting section here so that folks can fix their local Swagger state if they get stuck. Here's the Slack conversation that documents this now.
Once you finishing updating the yaml files with the new endpoint information make sure to run your make commands to autogenerate your swagger files, or simply run `make server_run`, | ||
which runs your server and other useful make commands in one go. | ||
|
||
## Creating an endpoint. |
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 may want to rename this section Creating a Handler
|
||
|
||
#### How to handle errors | ||
TODO: WIP |
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 believe we have documentation for errors: https://github.com/transcom/mymove-docs/blob/720592c63db4bffe402a801417f7c14772573c28/docs/dev/contributing/backend/API-Errors.md
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.
Great! I'll just like to that. It felt like this should be a separate doc anyways.
#### How to handle errors | ||
TODO: WIP | ||
### Add event key and update event map | ||
Each API has a corresponding file in `/pkg/services/event/<apiName>_endpoint.go` |
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.
This is only part 1️⃣ of my review @NamibiaTorres but I am submitting as a comment so I don't stop this from getting merged in. Great work on this 🎉 . I think it's going to be super helpful to have this type of breakdown in our documentation.
My concerns here is that maybe some of this documentation would be better suited as examples similar to the work in the other PR transcom/mymove#7435. But I'm including some of my comments here so they don't get lost.
/your path: | ||
HTTP request: | ||
summary: | ||
description: |
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.
This section will eventually need to be refactored to something like this after transcom/mymove#7435 is merged into the default branch over on that repo.
description: | |
description: | |
$ref: 'info/{file_name}.md' |
I appreciate the breakdown here, but since this type of documentation must stay in sync with the way the Swagger files are written in the other repository I'm worried that it's double the effort to make sure this Yaml structure is kept up to date with how the Swagger files are maintained.
cc: @scarequotes for their opinion on where this type of documentation is more appropriate.
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 see, and agree, we definitely want to push folks to started using our new way of writing descriptions.
description: | | ||
Gets all moves that have been reviewed and approved by the TOO. |
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.
Same as the description block above. Once the work I've started in transcom/mymove#7435 is finalized and merged in, this will need to be updated to something like the suggestion below.
description: | | |
Gets all moves that have been reviewed and approved by the TOO. | |
description: | |
$ref: 'info/prime_listMoves.md' |
description: > | ||
An abbreviated definition for a move, without all the nested information (shipments, service items, etc). Used to | ||
fetch a list of moves more efficiently. |
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.
Looking at how the documentation is written here, I'm starting to think that with transcom/mymove#7435 we can update this documentation page to say something along the lines of
Make sure the
description:
file is pointing to a Markdown file in theswagger-def/info
directory contains the description of the endpoint.
Relevant but redundant comment because this documentation is similar to the documentation above.
Same as the description block above. Once the work I've started in transcom/mymove#7435 is finalized and merged in, this will need to be updated to something like the suggestion below.
description: > | |
An abbreviated definition for a move, without all the nested information (shipments, service items, etc). Used to | |
fetch a list of moves more efficiently. | |
description: | |
$ref: 'info/prime_listMoves.md' |
|
||
#### Gen files: | ||
Once you finishing updating the yaml files with the new endpoint information make sure to run your make commands to autogenerate your swagger files, or simply run `make server_run`, | ||
which runs your server and other useful make commands in one go. |
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.
It may also be helpful to add a Troubleshooting section here so that folks can fix their local Swagger state if they get stuck. Here's the Slack conversation that documents this now.
The purpose of this PR is to update the Endpoint documentation in Docusaurus with more detailed information (i.e. steps to creating an endpoint) and technical examples.
Feedback request
I'd like to add more context to the event maps section at the end. What information would be most useful to put in this section.
For the "How to handle errors" section is this the right place for this info or should we create a separate document for that? If so, I can add a template for that document and work on it while on A Team.
Other info
jira ticket