Skip to content

added host section #646

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

Merged
merged 1 commit into from
Apr 14, 2016
Merged

added host section #646

merged 1 commit into from
Apr 14, 2016

Conversation

fehguy
Copy link
Contributor

@fehguy fehguy commented Apr 11, 2016

Fixes issue #214

@fehguy
Copy link
Contributor Author

fehguy commented Apr 11, 2016

Moved from #640.

@OAI/tdc please approve or reject

<a name="oasHost"></a>host | `string` | The host (name or ip) serving the API. This MUST be the host only and does not include the scheme nor sub-paths. It MAY include a port. If the `host` is not included, the host serving the documentation is to be used (including the port). The `host` does not support [path templating](#pathTemplating).
<a name="oasBasePath"></a>basePath | `string` | The base path on which the API is served, which is relative to the [`host`](#oasHost). If it is not included, the API is served directly under the `host`. The value MUST start with a leading slash (`/`). The `basePath` does not support [path templating](#pathTemplating).
<a name="oasSchemes"></a>schemes | [`string`] | The transfer protocol of the API. Values MUST be from the list: `"http"`, `"https"`, `"ws"`, `"wss"`. If the `schemes` is not included, the default scheme to be used is the one used to access the OpenAPI definition itself.
<a name="oasHosts"></a>hosts | [Hosts Object](#hostsObject) | An array of Host objects which provide `scheme`, `host`, `port`, and `basePath` in an associative manner.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Host Object

@webron
Copy link
Member

webron commented Apr 12, 2016

👍

This should also also affect the same fields as described at https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.md#operationObject.

@darrelmiller
Copy link
Member

👍

@whitlockjc
Copy link
Member

LGTM

@jharmn
Copy link
Contributor

jharmn commented Apr 13, 2016

The biggest issue I see with this:

  • Codegen: how does a client know which host to call? It seems like there are two options to make this useable:
    • default: which host is used if not specified
    • name/key: an arbitrary name for the environment, so the client can specify which environment they intend to call.

IMO in Swagger 2.0, host is useless in most situations. The client has to use some other system (dns, consul, etcd etc) to discover the correct host for the given environment. Adding an ambiguous set of hosts for any given environment makes it impossible to know which one to call programmatically.
Additionally, spec publishers really don't want to expose the internal hostnames of their dev/qa/staging environments in their public specs (granted, this could potentially be stripped with preprocessing, but would require name/key).

👎 as it stands

@IvanGoncharov
Copy link
Contributor

@jasonh-n-austin Please take a look at #641 it should addresses all your concerns.

name/key: an arbitrary name for the environment, so the client can specify which environment they intend to call.

I think best ID is URL generated from this element, so user can choose based on it.
At the same time it would be cool to support optional title and description to describe non-standard hosts like Sandbox.

IMO in Swagger 2.0, host is useless in most situations.

I strongly disagree, it's very useful for public APIs like Instagram, Facebook, etc.

Additionally, spec publishers really don't want to expose the internal hostnames of their dev/qa/staging environments in their public specs (granted, this could potentially be stripped with preprocessing, but would require name/key).

In that case you can strip based on some kind of vendor extension, e.g. x-internal: true.

@darrelmiller
Copy link
Member

I didn't realize the intent of the hosts array was to enable the identification of different environments. I thought it was for enumerating identical service instances. Therefore it wouldn't matter which host you chose, the effect would be the same. This would allow the client to pick a closest server, or round robin requests as well as pick the scheme they want to use.

Making OpenAPI responsible for identifying multiple different environments seems like a fairly significant increase in responsibility and certainly opens the questions about default environment and which hosts are equivalent and which are not. Are we sure we want to go there? The original issue was not trying to solve that problem.

@webron
Copy link
Member

webron commented Apr 14, 2016

@darrelmiller - that's a fair point. However, that's not really the intent. I think that's the difference between use and abuse. The spec shouldn't say it should be used for that or intended to be used for that, but users may end up doing so - we can't stop it.

I agree the goal here is just to be able to fine-tune the host definition is which is a bit limited today.

@fehguy
Copy link
Contributor Author

fehguy commented Apr 14, 2016

@jasonh-n-austin my view is that the hosts object is an ordered list, we can make it clear that there is an implicit order of precedence.

Given that and the other votes, I'm merging this and we can always revisit.

@sidhantdas007
Copy link

can someone just give an example of how they have implemented the multiple swagger host? I am a bit new to swagger

@MikeRalphson
Copy link
Member

@sidhantdas007 this can only be done natively in OpenAPI 3.0 (the successor to the Swagger specification). A simple example: https://github.com/APIs-guru/openapi-directory/blob/openapi3.0.0/APIs/bbci.co.uk/1.0/openapi.yaml#L1-L5

You can mention additional hosts in OpenAPI 2.0 only by using specification (vendor) extensions, but this will have no support in tooling other than your own.

handrews added a commit to handrews/OpenAPI-Specification that referenced this pull request Oct 11, 2024
add host section

[Manually ported merge]

Co-authored-by: Tony Tam <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants