Proposed: Add oasdoc notation for linking to API elements #5232
DavidBiesack
started this conversation in
Enhancements
Replies: 2 comments
-
|
This is an interesting idea. My first thought is that it should be a separate specification from the OAS proper, as it is specific to one sort of application (documentation rendering) and not universally essential. This is not meant to be a comment on the merits of either the general idea or on the specifics of this proposal. Just an observation that this is a different level of abstraction and a different scope of application than the OAS proper. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
@DavidBiesack Thanks for the proposal. This is quite an interesting one. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal: oasdoc
Several programming languages support documentation annotations which
make it convenient to author more comprehensive documentation by
allowing hyperlinks bewteen language elements.
javadocjsdoc.I propose OAS devise conventions for embedded documentation links in the
OpenAPI source, so that tools (such as API doc rendering tools) can
support well-known documentation anchors for OAS elements such as operations
and schemas, and that
descriptionstrings in OAS elements andexternal web pages can add links to those elements in a manner that is
agnostic to the tool vendor.
Justification
By adding
oasdocas an extension or convention of the OpenAPISpecification, API authors can use a tool-agnostic way to ennhance API
documentation, so developers can render the API doc consistently across
different OAS-compliant tools.
Downstream API consumers should be able to download an
OpenAPI description from an API vendor's developer portal or open source
repository and render API documentation with the tool of their choice.
For example, it is useful to provide a summary of an APIs capabilities
in the
info.descriptionMarkdown text, and link to the important APIoperations. Some vendors may create anchors for each
operationIdbutthere is no standard or convention.
For example, given the
The Train Travel API
from bump.sh :
Adding infdormational links to the
the top-level
info.descriptionmakes it easier to highlightthe important operations in the API:
API Documentation Vendor Differences
bump.sh
bump.shgenerates a URL for each operation.which does not even yield an anchor; it yields a unique URL such as
https://bump.sh/bump-examples/doc/train-travel-api/operation/operation-get-stationsRedocly
ReDocly creates an anchor for the operation by concatenating:
"tag/"tags"/operation/"operationIdif one exists (else some other heuristic...)which would yields the anchor
#/tag/Stations/operations/get-stationsSuch vendor differences are an inhibitor to writing useful documentation.
By establishing a common (standard) notation, it's more likely API authors
will add links and API navigation aids, increasing the utility of the API doc.
I propose the
oasdocnotation, which authors can use to enhanceAPI documentation and which tool vendors can treat as
a preprocessor to convert agostic links to vendor-specific links.
The API doc vendors may or may not create anchors for schemas or other OpenAPI elements.
For example, bump.sh does not provide anchors for reuest or response schemas;
see The Train Travel API.
However, the API doc tooling vendors can transform the Markdown notation
into navigation links as per their implementation. For example, examining the source
from the bump.sh Train travel API, the left hand navigation contains HTML:
The response for the
list-stationscall is an object with adataproperty withan array of objects but there is no link to expose what those array items are, only
The response is defined as
so it would be more helpful to the reader if this internal
Stationschema was called out (so the developer reading the doc
knew the schema name of the items was
Station, not just an anonymous object),and the API doc had an anchor for the
Stationschema (and the other schemas that are referenced here)so that they could be referenced by name elsewhere.
Likewise, the
descriptionfor thelist-trainsoperation could be more specificand document the response with an oasdoc link to the
Stationschema:The tooling could inject an HTML link to the
Stationsschema.Notation
I propose specific notation for
oasdoc.oasdoc annotations have the form
{@op operationId}{@op operationId|alt text}Add a hyperlink to the operation named by
operationid.The default hyperlink text is the
operationidif noalt textis given.{@schema schemaName}Add a hyperlink to the named schema within /components/schemas/schemaName`
{@property schemaName.property}{@property .property}The second form may be used within the
descriptiontext of a schema,to link to properties relative to that schema.
Add a hyperlink to the named property schema within /components/schemas/schemaName`
This also allows nested properties and arrays,
for example, use
{@schema schemaName.subproperty}{@schema schemaName.subpropertyA.subpropertyB}{@schema schemaName.arrayX.items.subpropertyA.arrayY.items.subpropertyB}to access nested elements.
{@parameter parameterName|in:path}{@parameter parameterName}Add a hyperlink to a parameter in
/components/parametersthat matches the
parameterName. If there are multiple parmaetersof the same name, select one with
in:<location>using
in:path,in:headr,in:query,in:cookie.{@response responseItemName}Add a hyperlink to the named response item
{@securityScheme securitySchemeName}Add a hyperlink to the named security scheme.
{@id identifier}Establish a name for a document element. This is like
using
<a id="identifier">but does not assume HTML.If used in the description in an operation that does not have
an
operationId, this ID can be used as the well-knownanchor for the operation.
{@link identifier|alt text}Add a hyperlink to an anchor at a location defined by
{@id identifier}The default hyperlink text is the
identifierif noalt textis given.Well-known anchors
As noted above, different API doc vendors have established
different conventions for the anchors or URIs for the operations and other elements.
I propose
oasdocestablish well-known anchor namesfor OAS elements. This will allow linking to them from external (non oasdoc) sources
such as tutorials in a devportal.
operationId, the anchor#op-{operationId}may be appended to the API doc URL to jump directly to that operation.
This is important because vendors use different strategies which
are sometimes comples and hard to use. See the Redocly
section above
schemaNamein/components/schemas, the anchor#schema-{schemaName}As noted, some tool vendors (like bump.sh) do not use anchors; each operation
has it's own URL and the bump.sh user experience manages those links to yield
the equivalemt of a "Single Page App". So supporting such links
would require vendor support, but I think it is possible.
Open Topics
Cross-API Links
Many API providers have suites of APIs, each exposed via separate
API documentation generated from multiple OpenAPI descirptions.
It is common for APIs to be inter-connected. For example,
one API may reference a resource R defined by another API,
and thus it is convenient to link to the corresponding
GET /resources/{resourceId}operation to fetch the resource that is referenced
locally (for example, in a response object property)
via a resource ID or URL property or an OAS.
such cross-API links are hard to encode, as different tools
and developer portals manage API document catalogs in many ways.
A solution must also account for
API versions (
info.version), which adds a level of complexity.Syntax to be determined.
Subschemas within JSON Schema
allOf,oneOf,anyOf,if/then/elseJSON Schema supports conditional and unconditional schema composition
with
allOf,oneOf,anyOf,if/then/elsekeywords.DIfferent API doc systems yield different rendering
strategies for these constructs.
allOf,oneOfandanyOfeach support an array ofsubschemas.
oasdoc support for the
allOfkeywordThe 200 response for the
get-stationsoperation is defined asand is rendered as an aggregation of the properties of each item:
(These property descriptions come from the
Wrapper-Collection).Thus, to link to the
dataproperty for a schema defined withallOf,one can simply link to the
schemaName.dataproperty.oasdoc support for the
oneOfkeywordIn the Train Travel API, the
Paymentschema is defined as
which bump.sh renders as a panel selector:
Selecting each option ("Card object" or "Bank Account object" in
the bump.sh experience)
shows the properties of the selected
oneOfschema inside a panel listing.Rendering links to items within
oneOforanyOfconstructs isnot straight forward in a complex conditionally-rendered UX.
Neither the Train Travel (or Redocly's Musuem AP)
use the
anyOfkeyword, but I believe it would be presented in a UX similarto
oneOfand thus not easily accessible via a link.Other components?
This proposal addresses well-known anchors for operations
(by
operationIdor{@id ...}) and named schemasin the
components/schemasobject. Is there need forwell-known anchors to other components?
Those elements are already typically represented
in API doc and, to my knowledge, do not merit other links
(for example, does API documentation need to link
to a parameter component, or a response object component
by name)?
Beta Was this translation helpful? Give feedback.
All reactions