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

How to document cnd's HTTP API #38

Merged
merged 20 commits into from
Sep 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Follow one-line-per-sentence policy
  • Loading branch information
luckysori committed Sep 3, 2019
commit e0b4366e239e4045ce015ffa99a9dd5702b3a280
30 changes: 22 additions & 8 deletions 0015-how-to-document-cnd-http-api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ Tracking issue: https://github.com/comit-network/comit-rs/issues/1122[#1122]

== Context ==

We have no documentation for cnd's HTTP API. Having it is a hard requirement if we want to cater to application developers. It should also be helpful for the team and for newcomers.
We have no documentation for cnd's HTTP API.
Having it is a hard requirement if we want to cater to application developers.
It should also be helpful for the team and for newcomers.

== Research ==
luckysori marked this conversation as resolved.
Show resolved Hide resolved
We have no documentation for cnd's HTTP API. Having it is a hard requirement if we want to cater to application developers. It should also be helpful for the team and for newcomers.
We have no documentation for cnd's HTTP API.
Having it is a hard requirement if we want to cater to application developers.
It should also be helpful for the team and for newcomers.

=== Which API specification approach should we use? ===

Expand Down Expand Up @@ -45,10 +49,13 @@ We have no documentation for cnd's HTTP API. Having it is a hard requirement if
* An https://gist.github.com/iros/3426278[example] showing how it could look.

==== Recommendation ====
OpenAPI, because it appears to be the industry standard, and is compatible with the most tools. The better human readability of API Blueprint doesn't seem all that important given that these specifications can be viewed using powerful tools such as https://rebilly.github.io/ReDoc/[ReDoc].
OpenAPI, because it appears to be the industry standard, and is compatible with the most tools.
The better human readability of API Blueprint doesn't seem all that important given that these specifications can be viewed using powerful tools such as https://rebilly.github.io/ReDoc/[ReDoc].

=== How would a developer validate its API usage against the specification? ===
Mock servers powered by tools such as https://connexion.readthedocs.io/en/latest/[Connexion] or https://stoplight.io/prism[Prism]. These tools take a HTTP API specification and simulate a server that responds to requests according to the specification. This comes for free as long as we use one of the API description languages introduced above.
Mock servers powered by tools such as https://connexion.readthedocs.io/en/latest/[Connexion] or https://stoplight.io/prism[Prism].
These tools take a HTTP API specification and simulate a server that responds to requests according to the specification.
This comes for free as long as we use one of the API description languages introduced above.

=== [[test-specification]] How do we ensure that API specification and implementation are in sync? ===

Expand Down Expand Up @@ -110,12 +117,15 @@ describe('GET /example/request', function() {
----

==== Recommendation ====
Dredd, because it's well documented and has all the features we need. It looks like the main effort will be https://dredd.org/en/latest/how-it-works.html#making-your-api-description-ready-for-testing[preparing the specification] for testing.
Dredd, because it's well documented and has all the features we need.
It looks like the main effort will be https://dredd.org/en/latest/how-it-works.html#making-your-api-description-ready-for-testing[preparing the specification] for testing.

==== [[json-schema-integration]] JSON Schema integration ====
We currently use JSON Schema to validate the shape of the body of the response to `GET /
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't you expect to replace the JSON schema with our Open API doc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding is that JSON Schema is more expressive and can be used for things such as server-defined client-side validation. OpenAPI supports a subset of JSON Schema and in the near future if will be fully supported.

In any case, using the $ref keyword we can reference .schema.json files in OpenAPI files. Until OpenAPI supports JSON Schema in full there might be some pain points, but there are ways to work around them.

swaps` and `GET /
swaps/rfc003/:id`. JSON Schema is supported by OpenAPI, https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#schema-object[with some caveats]. There are https://apisyouwonthate.com/blog/solving-openapi-and-json-schema-divergence[ways to get around this situation], and full support for JSON Schema is https://github.com/OAI/OpenAPI-Specification/pull/1977[in the works].
swaps/rfc003/:id`.
JSON Schema is supported by OpenAPI, https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#schema-object[with some caveats].
There are https://apisyouwonthate.com/blog/solving-openapi-and-json-schema-divergence[ways to get around this situation], and full support for JSON Schema is https://github.com/OAI/OpenAPI-Specification/pull/1977[in the works].

=== How to generate the specification ===

Expand All @@ -135,7 +145,10 @@ swaps/rfc003/:id`. JSON Schema is supported by OpenAPI, https://github.com/OAI/O
* Make API calls to a running cnd through the UI and generate part of the specification.

==== Recommendation ====
Unfortunately the tools aren't there yet to automatically produce the API specification from source code in Rust. There seems to be some interest for this, so it may come in the future. For the time being, we will have to write it ourselves. Fortunately, this specification will be <<test-specification,tested>> and we can use tools such as https://speccy.io/[speccy] to validate it.
Unfortunately the tools aren't there yet to automatically produce the API specification from source code in Rust.
There seems to be some interest for this, so it may come in the future.
For the time being, we will have to write it ourselves.
Fortunately, this specification will be <<test-specification,tested>> and we can use tools such as https://speccy.io/[speccy] to validate it.

=== How to visualise specification ===

Expand Down Expand Up @@ -180,7 +193,8 @@ If we go for the recommended option of using <<redoc, ReDoc>>, it's https://www.
. Use a HTML tag that links to the API specification (there's even a https://www.npmjs.com/package/redoc#usage-as-a-react-component[React component]).
luckysori marked this conversation as resolved.
Show resolved Hide resolved

=== How to document extension link relation types? ===
I would argue that this is covered in https://github.com/comit-network/comit-rs/issues/843[the original issue]. Just replace `human-protocol-spec` key with a link to a static HTML page hosted on GitHub Pages (for example) where the meaning of `human-protocol-spec` is described.
I would argue that this is covered in https://github.com/comit-network/comit-rs/issues/843[the original issue].
Just replace `human-protocol-spec` key with a link to a static HTML page hosted on GitHub Pages (for example) where the meaning of `human-protocol-spec` is described.

=== Client-side validation ===

Expand Down