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

MB-9620-edit-enpoint-docs #12

Merged
merged 6 commits into from
Oct 7, 2021
Merged

MB-9620-edit-enpoint-docs #12

merged 6 commits into from
Oct 7, 2021

Conversation

NamibiaTorres
Copy link
Contributor

@NamibiaTorres NamibiaTorres commented Oct 6, 2021

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

# 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.

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.

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

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@NamibiaTorres NamibiaTorres Oct 6, 2021

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.

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

Copy link
Contributor

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.

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

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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`

Choose a reason for hiding this comment

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

Copy link
Contributor

@rogeruiz rogeruiz left a 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:
Copy link
Contributor

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.

Suggested change
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.

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 see, and agree, we definitely want to push folks to started using our new way of writing descriptions.

Comment on lines 40 to 41
description: |
Gets all moves that have been reviewed and approved by the TOO.
Copy link
Contributor

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.

Suggested change
description: |
Gets all moves that have been reviewed and approved by the TOO.
description:
$ref: 'info/prime_listMoves.md'

Comment on lines 75 to 77
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.
Copy link
Contributor

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 the swagger-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.

Suggested change
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.
Copy link
Contributor

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.

@NamibiaTorres NamibiaTorres merged commit c08ae4d into main Oct 7, 2021
@NamibiaTorres NamibiaTorres deleted the MB-9620-edit-enpoint_docs branch October 7, 2021 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants