Description
TLDR
(added after some discussion)
- "interfaces" (like path items, just without path parameters, and not linked to a path template)
- a path item can refer to an interface (which is implemented), possibly adding path parameters to it
- a string property (containing an URI) in a schema can refer to an interface (which means the consumer can know which operations can be used on this URI)
Background / Current Situation
I work at a company where our Restful API Guidelines prescribe both "document your API using OpenAPI" and "Use HATEOAS" ("Hypertext as the Engine of Application State", one of the core principles of REST).
Unfortunately both do not work together nicely:
- Swagger/OpenAPI 2.0's model is "we have paths which can be distinguished in some way, and describe the operations on those paths" (including their data format).
- The HATEOAS model is "The client gets a result which might contain links to other resources, and can decide to follow them, no matter which URI format they have".
Currently the intersection between both is "have links in your result, but just to URIs which are also described as paths in your Swagger definition, and describe in descriptions what kind of URIs you can expect".
Ideas
A core point of HATEOAS are media types and link relations. An API definition should mainly be a description of the media types and what operations they imply for links included in them. (Paraphrased from a blogpost of Roy Fielding.)
Media type definitions are analogous to what OpenAPI's definitions
are currently, might even be an extension of that. For models with a property of type string
, format uri
we can then additionally refer to the URI class of that URI.
A URI class is defined analogously to the current path definitions, but with some name to be used in model definitions. The URI class defines what operations are possible on an URI, which parameters are allowed/needed (no path parameters, I guess), and what can be expected in return. (The URI class is not a property of the URI itself, but of its usage in a specific place. The same URI could appear with multiple URI classes.)
I'm not yet sure how link relations can come into this – I guess we might need a way to define the URI class depending on link relation or similar.
A client needs just some initial "bookmark URI" (so a single path definition might be fine), and then can take a link (with a given URI class) and use the operation behind the URI class to do what it wants to do. The format of the second URI doesn't matter anymore to the client – it can even have a different domain name than the bookmark one. But still everything can be strongly typed if wanted.