Skip to content

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

Closed

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>

Activity

  1. added a commit that references this issue on Jul 6, 2018
  2. added a commit that references this issue on Jul 11, 2018
  3. jmini commented on Jul 20, 2018

    @jmini
    ContributorAuthor

    Solved with merge of #773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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