Beyond OpenAPI
antonz.org
antonz.org
example: https://docs.iommi.rocks/en/latest/cookbook_forms.html
corresponding documentation/tests: https://github.com/iommirocks/iommi/blob/master/docs/test_do...
my evil hack to get this working: https://github.com/iommirocks/iommi/blob/master/make_doc_rst... and https://github.com/iommirocks/iommi/blob/master/iommi/docs.p...
This is Diátaxis: https://diataxis.fr/
POST http://httpbingo.org/anything/chat
content-type: application/json
{
"message": "Hello!"
}
We extend it a bit to add checks on response, and add request chaining, but it's basically HTTP 1.x as this article shows it. A lot of others tools have the same idea, with minor differences:- Hurl (I'm one of the maintainer) https://hurl.dev
- HTTP Client https://www.jetbrains.com/help/idea/http-client-in-product-c...
- httpYac https://httpyac.github.io
- restclient.el https://github.com/pashky/restclient.el
- REST Client https://github.com/Huachao/vscode-restclient
- verb https://github.com/federicotdn/verb
And many more...
Worth noting, other tools have taken the YAML route (like Step CI https://stepci.com), JavaScript (k6 https://k6.io/docs/using-k6/http-requests/)... I'm biased of course, I've a tiny preference for the simple plain text format.
And of course, there are also GUI application (Postman, Insomnia, RecipeUI amon others)
[1]: https://hurl.dev
- Tutorial: learn how the system works
- How-to: recipes for common use-casesHow-to(s) is a cookbook, targeting specific use cases, and may not particularly cater to novices.
Following this standard, a tutorial may contain a simpler or more contrived example; it may contain things you'd never do in production.
The idea of an interactive tutorial is great, but as others have mentioned, likely very difficult to maintain over time.
If your specification is self rewriting, can be tested and can be used to generate docs then maintenance costs plummet.
Long time ago at Klarna we used this tool: https://github.com/for-GET/katt Here's an example: https://github.com/for-GET/katt/blob/master/doc/example-http...
I've always heard "containerization is not a security boundary" but I am not red-team enough to provide specific counter-examples
OpenAPI is wack though. It doesn't provide any guarantees that the API does what it is supposed to do. I think in most cases it is a distraction and developer time would be better spent understanding HTTP and implementing and testing the endpoints.
I'm curious if others have had good experiences consuming OpenAPI as intended, i.e. you get handed a new API and you generate the code interfaces and plug them directly into your business logic without writing any extra wrappers. Or do you end up writing lots of wrapping code anyways?
I was a bit surprised it or Divio (where it was created) announced when they talked about the four types of documentation. I would love to see it make its way into information systems curriculum, as it's a quite useful mental model.
> If there is a problem with DITA, then, it is not that it lacks a theory of information design. The problem is that many people actually believe that it does have a theory of information design, and that that theory can be summed up in three words: concept, task, and reference. But a theory for breaking content up into pieces is not a theory of information design unless it also includes a theory of how the pieces should go back together.
> There is, of course, nothing preventing DITA users from having or developing a sound theory about how the pieces should go back together. The problem is not that DITA does not provide one. The problem is that writers often do not see that they need one. They believe, or act as if they believed, that the devolution into concept, task, and reference is a complete information design. The result, generally, is Frankenbooks.
Which I think is a salient point, and less an indictment on the "three/four types" model than a reminder that you shouldn't just throw together a bunch of type-delineated docs for their on sake; the individual pieces have to make a functional whole.
So I'm certainly in favor of supplementing traditional OpenAPI-esque reference docs with more conceptual or task-based docs... provided that they're actually designed to complement each other.
[1] https://everypageispageone.com/2012/07/28/the-tyranny-of-the...
Anton has built a new thing, https://codapi.org/ - which provides a web component that makes it easy to embed interactive code snippets for HTTP APIs, Python code and more directly in pages of documentation.
This article demonstrates this new technology in the context of the https://diataxis.fr/ documentation framework, which recommends going beyond just straight API reference documentation and ensuring you cover tutorials, how-to guides and explanations as well.
I think this is really cool.
But HTTP APIs with types are pretty cool too. Carry on, please!
OpenAPI, being JSON or Yaml, is portable
Whole spec fits single page.
As it needs to describe only valid json values, the whole language needs to operate on 6 underlying data types only - it's really not that complicated to come up with minimal readable format that's easy to parse.
It doesn't matter much if it reassembles ts, flow, ocaml or haskell - the point is it can fit into single screen, serve as documentation and be parseable for verification/codegen etc.
There is a whole lot more to express than...
> 6 underlying data types only
... when automating REST documentation from some underlying source of truth
It seems this one-page spec is woefully insufficient to express the concepts that OpenAPI can. Hence why no one here thinks this is a viable alternative
Imagine api like this:
// @endpoint wss://localhost:3000/api/v1
notification heartbeat = {
timestamp: number
}
type User = {
id: string,
email: Email
type: "normal" | "admin"
}
type AuthError = {
message: string,
code: -123
}
type NotLoggedInError = {
message: string,
code: -124
}
// Logs you in.
//
// @throws AuthError
login(username: string, password): User
// Adds two numbers.
// @throws NotLoggedInError
add(x: number, y: number): number
// Logs you out.
// @throws NotLoggedInError
logout(): null
It's terse, straight forward and maps to your host programming language naturally. --> {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}
<-- {"jsonrpc": "2.0", "result": 19, "id": 1}
...example to: subtract(42, 23) -> 19there are reasons people left flow, why do you think it is a candidate for best? Simply claiming so does nothing to further anyone's understanding
The bottom line is that description is terse and natural. Ie. it can be generated directly from your code and code can be generated out of it.
Instead of describing protocol (headers, status codes, http verbs, redirects, urls, params, cookies, content types etc) - you describe function signatures - the very thing that already has first class support in your programming language. An api feels like a library.
Because it uses json as serialization the data types you need to cover are very small - there are no interfaces, classes, inheritance, functions (you can't provide or return objects that define functions) - everything is pretty much composed out of type aliases and unions on 6 basic json types.
Instead of programming in yaml to describe http protocol you work with functions having json on input and output - something that is natural to your host programming language already.
Think graphql but without its nonsense restrictions on query (unions on input are fine!) or cherry picking output (calling convention that is foreign to programming languages and requires embedding dsl/dedicated query engines).
Think more like header file for remote service constraint to list of functions and notifications using json as data type.
it's not going to work as a general solution because
1. nobody wants the bs out of that "ecosystem" (applies to any language specific ecosystem)
2. it's not implemented in all the other languages and therefore not portable. Who's going to write all the parsers for your "solution"?
If all you write is JS/TS, you should really try out some other languages so you get a better perspective.
This is exactly why we have standards like OpenAPI... your solution would be a single ecosystem solution.
How would one put things like authentication, examples, and response codes in their public schema under your "solution"?
CUE is the future I hope for