Skip to content

Instantly share code, notes, and snippets.

@mikekistler
Last active September 18, 2025 13:47
Show Gist options
  • Select an option

  • Save mikekistler/1983a8249c0df56a46f94b4df1b7181d to your computer and use it in GitHub Desktop.

Select an option

Save mikekistler/1983a8249c0df56a46f94b4df1b7181d to your computer and use it in GitHub Desktop.
Proposal for links in OpenAPI v4
@ralfhandl
Copy link

We should try to also address the "for any entry in the list" case, for example with a wildcard array index [*]:

          links:
            keyId:
              operationId: RegenerateKey
              # The id field of the first key can be set as id property of the request body of RegenerateKey
              requestBody:
                '/id': '$.response/body#value[*].id'

Extracting paired items could then be achieved by using both [*].id and [*].etag in a link object.

@chatelao
Copy link

Typo: Compatability -> Compatibility

Thanks for the proposal, I will have a deeper look later.

@Bert-R
Copy link

Bert-R commented Jun 4, 2024

This proposal also makes it much easier to document HATEOAS APIs. On OAI/OpenAPI-Specification#577, I said the following:

OAS with JSON Schema could describe:

  • The starting path(s) with belonging requests/responses
  • It should be possible to define a link truly as a link with:
    • Allowed HTTP methods
    • For each HTTP method the schema of the request/response

The paths that are used in the links should not be defined as paths in the OAS, as that would stimulate wrong behavior: just use these endpoints instead of following the links.

Your proposal here allows describing starting paths (a set of operations). The extended links refer to operations, which specify the allowed HTTP methods and schema of request and response. My bullet points are covered with that.

The issue that is not addressed is in the last sentence of the quote. A simple solution to that would be to annotate operations with some sort of flag indicating these operations should only be invoked through links returned from the server, never without that server guidance. Is that something that you can add to your proposal?

This way, we have a pragmatic way to define a mediatype, while retaining the dynamic hypermedia as the engine of application state.

@mikekistler
Copy link
Author

I've never understood HATEOAS. The notion of "just follow this link" with no definition of its parameters, headers, authorization scheme, response schema, response headers, etc does not make sense to me. I'm probably misrepresenting the concept of HATEOAS there but that's just the way it seems to me.

So you are correct that my proposal does not address excluding the paths used in links from the API definition. I think they should be in the API definition so that all the details of the request are well defined.

@Bert-R
Copy link

Bert-R commented Jun 4, 2024

The purist approach of HATEOAS is that you figure it all out at runtime. IMHO, that is not realistic.

Your approach allows defining links and the operations they relate to. In a HATEOAS API design, I would use that to define a single public GET operation that returns nothing but a bunch of links. That resource is what the client (e.g. a mobile app) would fetch. The app designers would read what possible links are returned. Then they would read the operations and know the possible subsequent requests. The links would generally be optional and the server will populate those links that are applicable in that actual state of the application.

Such an API design has two major benefits:

  • The app does not need to keep track of the state to know whether a certain operation will be possible. If the operation is possible, its link is available, otherwise not. So, the defined operations are documented in the OAS spec, the subset of actually possible operations is indicated through link availability. E.g. a pageable resource will on the first page not have a previous link, but it will have a next link if multiple pages exist. The next page will have a previous link.
  • The server can change URLs over time without the client being aware (e.g. add a query parameter and populate it from the server, in the the returned link). As long as the operations are the compatible, the app will continue to work.

So, my request to be able to mark operations as "use only through a link" is to guide app designers.

@vaskozl
Copy link

vaskozl commented Sep 18, 2025

The notion of "just follow this link" with no definition of its parameters, headers, authorization scheme, response schema, response headers, etc does not make sense to me

For a REST API as described by Roy Fielding, the idea is that you'd return not only the link but also define how it is meant to be used in the same response where you gave out the link.

For instance, when returning text/html you might use a <form> to declare that one should do a POST. The client (browser) knows t the media type (text/html) and infers that it should make a POST with whatever input values might be in the said form.

For JSON, you'd technically start the client without reading the global API spec, and in theory the OpenAPI enabled server would return application/openapi+json or some other well defined media type that returns the part of the spec documenting the operation you are linking to.

In theory this could be used for some clever communication of the next possible state. E.g. regular users get told they can only view a resource via a GET, while admin users get told they can additionally DELETE it or replace it edit it via a PUT. Similar to how you only return such a button on an HTML server.

Full HATEOAS support would imply that the clients should be able to dynamically read OpenAPI spec bit by bit. I agree with Bert-R that, this is highly unrealistic and unexpected by your general OpenAPI client.

As such I'm not sure I see a reason to "hide" it from the original spec, given that we don't have the facility to return the spec at all in the ecosystem. HATEAOS clients (such as browsers) wouldn't read the spec in the first place.

This proposal is still really useful because it allows interoperability. E.g. you can make a common "Location" header returning endpoint which is usable via both a regular OpenAPI Client and also a web browser -- which is really nice.

@mikekistler
Copy link
Author

@vaskozl @Bert-R Thanks for your comments. But sadly I think this proposal is dead. There is no agreement on what the current link object means in OpenAPI and the spec offers no guidance, so there is little appetitie in the TSC for fixing or improving a feature that is broken beyond repair.

It pains me to say this because I believe (as I think you do) that this could be an extremely useful feature. But I have given up trying to get others in TSC to find a path forward with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment