Skip to content

#1553 fails to generate spec on relative server urls on Windows #1565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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());
}
}

Original file line number Diff line number Diff line change
@@ -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