Skip to content

Issue in converting server url in RFC 3986 format from OpenAPI Spec 2 to Open API Spec 3 #745

@sandeep-chekuri

Description

@sandeep-chekuri

If the host is defined without defining schema in OpenAPI Spec 2 then Server.url shoud be //{hostname}/{basePath} but it is {hostname}/{basepath}

The same is explained in swagger documentation under Server URL format ( RFC 3986 )
https://swagger.io/docs/specification/api-host-and-base-path/

It is a minor bug fix in the SwaggerConvert.convert(List schemes, String host, String basePath) by changing to below lines

private List convert(List schemes, String host, String basePath) {
List servers = new ArrayList<>();
String baseUrl;

    if (StringUtils.isNotEmpty(basePath)) {
        baseUrl = basePath;
    } else {
        baseUrl = "/";
    }

    if (StringUtils.isNotEmpty(host)) {
        baseUrl = "//" + host + baseUrl;
    }

    if (!StringUtils.startsWith(baseUrl, "/") && schemes != null && !schemes.isEmpty()) {
        for (Scheme scheme : schemes) {
            Server server = new Server();
            server.setUrl(scheme.toValue() + ":" + baseUrl);

            servers.add(server);
        }
    } else {
        if (!"/".equals(baseUrl)) {
            Server server = new Server();
            server.setUrl(baseUrl);

            servers.add(server);
        } else {
            return null;
        }
    }

    return servers;
}

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