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

Support discovering OpenAPI document from Link header? #2128

Open
evankanderson opened this issue Feb 7, 2020 · 10 comments
Open

Support discovering OpenAPI document from Link header? #2128

evankanderson opened this issue Feb 7, 2020 · 10 comments
Labels
discovery How to find OADs

Comments

@evankanderson
Copy link

I'm looking at various options to "upgrade" a simple API (HTTP POST of CloudEvents) to allow clients and servers to be able to extend into more complex OpenAPI space (e.g. "what events are you interested in" or "what types of events might be returned in the HTTP response").

One attractive option would be to provide a Link header pointing to the OpenAPI spec on the existing endpoint to provide a hint that upgrade is available.

I don't see a documented rel (relation) value for OpenAPI; would something like "oas-3.0" be a reasonable value?

@MikeRalphson
Copy link
Member

MikeRalphson commented Feb 7, 2020

I think more generically service-desc might suit the bill. See https://tools.ietf.org/html/rfc8631

See #1511 #724 #734 for previous discussions including describedBy, and #110 for a proposed media-type for OAS documents.

@evankanderson
Copy link
Author

service-desc looks like it fits the bill, thanks!

Any chance that this usage pattern could be documented better? A search for openapi link "service-desc" brings up #724 and then some usage from the opengeospatial project.

If it's useful, I can try to figure out where to add appropriate documentation?

@MikeRalphson
Copy link
Member

When #110 (@darrelmiller) is resolved we would definitely look at an updated version of #734 wording, either in the spec. or in a guidance / technical note document.

@larsgsvensson
Copy link

+1 to using Link header. You might also consider to register a .well-known URI, which could make the description available at example.org/.well-known/openapi.

@MikeRalphson
Copy link
Member

I recall @darrelmiller had some objection to using a .well-known URI for this case - could we document it here? It may have been that an OpenAPI document doesn't meet the criteria of

the discovery of information about an origin ... (sometimes called "site-wide metadata")

Of course one issue it doesn't cater for is an organisation having many APIs (which could be handled by something like apis.json). There is also the schema.org WebAPI type in this discovery space.

@POnakS
Copy link

POnakS commented Feb 21, 2022

I think using Link is bad idea, as it assumes we're serving some kind of HTML. Which is not always the case.

@evankanderson
Copy link
Author

This is the Link HTTP header, which will work with any content-type, not just text/html.

@POnakS
Copy link

POnakS commented Feb 21, 2022

Sorry, I think I've misunderstood this issue. I think having link pointing to documentation of current method is good idea, my comment does not really applies to this discussion.

(I was thinking of service discovery, i.e. getting Open API json just from domain).

@dret
Copy link
Contributor

dret commented Apr 1, 2022

Why be specific about the Link header and not just recommend the pattern by recommending a link relation to use?

andrewhowdencom added a commit to andrewhowdencom/x40.link that referenced this issue Jan 10, 2024
While doing parallel work to implement an API, the Gin framework proved
especially challenging to integrate with other HTTP handlers (e.g. GRPC
or the GRPC Gateway). It was difficult to convert between the HTTP
Handler interface and Gin's "context" approach, and Gin replaced the
way status codes were delivered (breaking compat between the two).

On review, Gin was becoming more of a challenge to work with than the
value it brought. Rather than "opt in" to the entire Gin framework, this
commit replaces Gin with a simpler, closer to the standard library
framework — "Chi". This seems to be well maintained, in fairly broad use
and easier to reason through.

=== Additional Tests

In the initial, gin design there were fewer tests. This commit adds more
test, somehow achieving 100% in the server package.

=== Errors w. Context

One of the things the Gin package did that was nice was centralize error
handling for the API, through the use of "context errors". This commit
replicates a simpler version of the same, allowing requests to end by
setting context on the request.

There is a new, central middleware that will look at all requests
egressing the stack, and if there is an error, write out an appropriate
response. This prevents many painful repetitions of the same content.

=== Problem+JSON

With the use of the Errors library, the opportunity came up to improve
the way erros are displayed. One of the more useful ways — absent a UI —
is to respond with a JSON (or similarly structured) blob.

This commit takes advantage of an existing library that does exactly
this, rather than writing it again.

=== Noroute to Get<slug>

This commit swaps the existing "noroute" design to a design that matches
the first slug in the URL. This is marginally different than the
previous design, which would (by definition) match the entire URL.

This allows, in principle, other bindings later for things like the
.well-known URLs:

  * OAI/OpenAPI-Specification#2128
andrewhowdencom added a commit to andrewhowdencom/x40.link that referenced this issue Jan 10, 2024
While doing parallel work to implement an API, the Gin framework proved
especially challenging to integrate with other HTTP handlers (e.g. GRPC
or the GRPC Gateway). It was difficult to convert between the HTTP
Handler interface and Gin's "context" approach, and Gin replaced the
way status codes were delivered (breaking compat between the two).

On review, Gin was becoming more of a challenge to work with than the
value it brought. Rather than "opt in" to the entire Gin framework, this
commit replaces Gin with a simpler, closer to the standard library
framework — "Chi". This seems to be well maintained, in fairly broad use
and easier to reason through.

=== Additional Tests

In the initial, gin design there were fewer tests. This commit adds more
test, somehow achieving 100% in the server package.

=== Errors w. Context

One of the things the Gin package did that was nice was centralize error
handling for the API, through the use of "context errors". This commit
replicates a simpler version of the same, allowing requests to end by
setting context on the request.

There is a new, central middleware that will look at all requests
egressing the stack, and if there is an error, write out an appropriate
response. This prevents many painful repetitions of the same content.

=== Problem+JSON

With the use of the Errors library, the opportunity came up to improve
the way erros are displayed. One of the more useful ways — absent a UI —
is to respond with a JSON (or similarly structured) blob.

This commit takes advantage of an existing library that does exactly
this, rather than writing it again.

=== Noroute to Get<slug>

This commit swaps the existing "noroute" design to a design that matches
the first slug in the URL. This is marginally different than the
previous design, which would (by definition) match the entire URL.

This allows, in principle, other bindings later for things like the
.well-known URLs:

  * OAI/OpenAPI-Specification#2128
andrewhowdencom added a commit to andrewhowdencom/x40.link that referenced this issue Jan 10, 2024
While doing parallel work to implement an API, the Gin framework proved
especially challenging to integrate with other HTTP handlers (e.g. GRPC
or the GRPC Gateway). It was difficult to convert between the HTTP
Handler interface and Gin's "context" approach, and Gin replaced the
way status codes were delivered (breaking compat between the two).

On review, Gin was becoming more of a challenge to work with than the
value it brought. Rather than "opt in" to the entire Gin framework, this
commit replaces Gin with a simpler, closer to the standard library
framework — "Chi". This seems to be well maintained, in fairly broad use
and easier to reason through.

=== Additional Tests

In the initial, gin design there were fewer tests. This commit adds more
test, somehow achieving 100% in the server package.

=== Errors w. Context

One of the things the Gin package did that was nice was centralize error
handling for the API, through the use of "context errors". This commit
replicates a simpler version of the same, allowing requests to end by
setting context on the request.

There is a new, central middleware that will look at all requests
egressing the stack, and if there is an error, write out an appropriate
response. This prevents many painful repetitions of the same content.

=== Problem+JSON

With the use of the Errors library, the opportunity came up to improve
the way erros are displayed. One of the more useful ways — absent a UI —
is to respond with a JSON (or similarly structured) blob.

This commit takes advantage of an existing library that does exactly
this, rather than writing it again.

=== Noroute to Get<slug>

This commit swaps the existing "noroute" design to a design that matches
the first slug in the URL. This is marginally different than the
previous design, which would (by definition) match the entire URL.

This allows, in principle, other bindings later for things like the
.well-known URLs:

  * OAI/OpenAPI-Specification#2128
@jkobus
Copy link

jkobus commented Jan 18, 2024

If anyone comes around wandering about this, I did it like that:
<link rel="service-desc" type="application/vnd.oai.openapi+json;version=3.0" href="https://example.com/.well-known/openapi">

For json it would be application/vnd.oai.openapi+json as mentioned here: #110 (comment)

@handrews handrews added the discovery How to find OADs label Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discovery How to find OADs
Projects
None yet
Development

No branches or pull requests

7 participants