Skip to content

Commit

Permalink
#1553 fails to generate spec on relative server urls on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jhannes committed May 19, 2021
1 parent bb28d1d commit 29ede86
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
Expand Up @@ -145,17 +145,10 @@ public SwaggerParseResult deserialize(JsonNode rootNode) {

public SwaggerParseResult deserialize(JsonNode rootNode, String path) {
SwaggerParseResult result = new SwaggerParseResult();
try {

ParseResult rootParse = new ParseResult();
OpenAPI api = parseRoot(rootNode, rootParse, path);
result.setOpenAPI(api);
result.setMessages(rootParse.getMessages());

} catch (Exception e) {
result.setMessages(Arrays.asList(e.getMessage()));

}
ParseResult rootParse = new ParseResult();
OpenAPI api = parseRoot(rootNode, rootParse, path);
result.setOpenAPI(api);
result.setMessages(rootParse.getMessages());
return result;
}

Expand Down Expand Up @@ -480,7 +473,7 @@ public Server getServer(ObjectNode obj, String location, ParseResult result, Str
if (StringUtils.isNotBlank(value)) {
if (!isValidURL(value) && path != null) {
try {
final URI absURI = new URI(path);
final URI absURI = new URI(path.replaceAll("\\\\", "/"));
if ("http".equals(absURI.getScheme()) || "https".equals(absURI.getScheme())) {
value = absURI.resolve(new URI(value)).toString();
}
Expand Down
Expand Up @@ -624,5 +624,14 @@ public void testMultipleOfBetweenZeroAndOne() {
BigDecimal multipleOf = decimalValue.getMultipleOf();
assertEquals(multipleOf, new BigDecimal("0.3", new MathContext(multipleOf.precision())));
}

@Test
public void testConvertWindowsPathsToUnixWhenResolvingServerPaths() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIParser().readLocation("exampleSpecs\\specs\\issue1553.yaml", null, options);

assertEquals("/api/customer1/v1", result.getOpenAPI().getServers().get(0).getUrl());
}
}

@@ -0,0 +1,33 @@
openapi: 3.0.2
info:
title: Sample API
description: A small example to demonstrate individual problems
version: 0.1.9
servers:
- url: /api/customer1/v1
description: Server
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'200':
description: Updated
components:
schemas:
Pet:
type: object
required:
- pet_type
properties:
pet_type:
type: string
name:
type: string
birth_date:
type: string
format: date

0 comments on commit 29ede86

Please sign in to comment.