Review the OpenAPI 2.0 host address

How to specify the host, protocol and base path for an OpenAPI 2.0 endpoint.

Description

OpenAPI 2.0 host contains only the hostname or IP address and an optional port. Define the protocol and path separately in schemes and basePath.

Potential impact

Documentation tools or generated clients may use an incorrect server address.

Remediation

Put the hostname or IPv4 address and optional port in host. A bracketed IPv6 address is valid URI syntax, but the published OpenAPI 2.0 validation schema rejects it. Use a DNS name that resolves to the IPv6 address and verify the URL formed with schemes and basePath.

Examples

These excerpts compare kics.io/test, which contains a path, with the host-and-port format 127.0.0.1:8080. The local address only illustrates the format; replace it with the actual API host.

Before

json
{
  "swagger": "2.0",
  "host": "kics.io/test"
}

After

json
{
  "swagger": "2.0",
  "host": "127.0.0.1:8080"
}

References