KaiZen-OpenApi-Parser
KaiZen-OpenApi-Parser copied to clipboard
Server with relative location are not converted to an absolute url
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:
OpenApi3 model = new OpenApi3Parser().parse(new URL("http://localhost:8090/openapi.json"), validate);
if (!validate || model.isValid()) {
for (Server s : model.getServers()) {
System.out.println(s.getUrl());
}
describeModel(model);
}
You get /rel where the expected value is http://localhost:8090/rel
Tested with:
<dependency>
<groupId>com.reprezen.kaizen</groupId>
<artifactId>openapi-parser</artifactId>
<version>2.1.1-201803281732</version>
</dependency>