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

Require schemas for APIs #719

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Require schemas for APIs #719

wants to merge 1 commit into from

Conversation

JoelQ
Copy link
Contributor

@JoelQ JoelQ commented Nov 13, 2024

When consuming an API from a client, a schema makes your life easier. Not only does it provide documentation, but it also can integrate into automated tooling such as type-checkers and code generators.

On the back end, it's nice to plug a schema into a unit test to guarantee that the implementation matches the spec. Depending on the system you use, schemas can also be used to generate API docs or test fixtures.

When consuming an API from a client, a schema makes your life easier. Not only does it provide documentation, but it also can integrate into automated tooling such as type-checkers and code generators.

On the back end, it's nice to plug a schema into a unit test to guarantee that the implementation matches the spec. Depending on the system you use, schemas can also be used to generate API docs or test fixtures.
Copy link
Member

@nickcharlton nickcharlton left a comment

Choose a reason for hiding this comment

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

To bring over my comment from the PR which spawned this one:

Do we have a general preference for tools for doing this?

I think something in the guides which provided specific direction there would be great (and also would make a good blog post!).

@purinkle
Copy link
Contributor

In Rails on iOS, we recommend using json-schema

@@ -36,6 +36,7 @@ while building applications.
### API

- Use GraphQL as an API layer when connecting a mobile app to a web service.
- Use a schema to describe the shape of the inputs and outputs of an API endpoint.
Copy link
Contributor

@pangolingo pangolingo Dec 27, 2024

Choose a reason for hiding this comment

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

Here are my opinions. This is what I generally do on a mature project.

Suggested change
- Use a schema to describe the shape of the inputs and outputs of an API endpoint.
- Use an [OpenAPI schema](https://learn.openapis.org/) to document the shape of the inputs and outputs of an API endpoint.
- When building a REST API, use the [JSON-API](https://jsonapi.org/) spec to determine the shape of API responses
- When using GraphQL and Typescript, use [GraphQL Codegen](https://the-guild.dev/graphql/codegen) to generate type definitions for the API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh JSON-API! I know that can be controversial. Any particular reason you like to default to it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh JSON-API! I know that can be controversial. Any particular reason you like to default to it?

It's a well-documented opinionated standard, and I haven't come across another public standard that's as fully defined. I actually don't like some of its opinions, but I also don't want to write my own API standards doc on every project.

Copy link
Member

Choose a reason for hiding this comment

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

Mmm. I think it's the one I've most frequently come across, that's well-supported, and is a good compliment to the HTTP specification.

I've been trying to think of others I've used and enjoyed, but it's been so long I'm coming up short. But I'd be happy with anything which emphasises the spirit of HTTP/the web and provides a standard we can follow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh JSON-API! I know that can be controversial. Any particular reason you like to default to it?

Why is JSON-API controversial @JoelQ ? 👀

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

Successfully merging this pull request may close these issues.

5 participants