Skip to content

Server with relative location are not converted to an absolute url #742

Description

@jmini

The OAS3 spec specifies:

This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served.

With a server that serves on http://localhost:8090/openapi.json:

{
  "openapi": "3.0.1",
  "servers": [
    {
      "url": "/rel"
    }
  ],
  "info": {
    "description": "This is a sample server",
    "version": "1.0.0",
    "title": "OpenAPI Petstore",
    "license": {
      "name": "Apache-2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
    }
  },
  "paths": {
    "/ping": {
      "get": {
        "summary": "Some ping operation",
        "description": "Some ping operation",
        "operationId": "doPing",
        "responses": {
          "200": {
            "description": "OK",
            "content" : {
              "application/json" : {
                "schema" : {
                  "type" : "object",
                  "properties" : {
                    "status": {
                      "type" : "string",
                      "example" : "ok",
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

When you do:

String inputSpec = "http://localhost:8090/openapi.json";

OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);

System.out.println(openAPI.getServers().get(0).getUrl()); //should be http://localhost:8090/rel

You get /rel where the expected value is http://localhost:8090/rel


Tested with:

<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.0.1</version>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions