Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 @@ -207,6 +207,9 @@ public SwaggerParseResult readWithInfo(String location, List<AuthorizationValue>

private SwaggerParseResult resolve(SwaggerParseResult result, List<AuthorizationValue> auth, ParseOptions options,
String location) {
if (location != null) {
location = location.replace('\\', '/');
}
try {
if (options != null) {
if (options.isResolve() || options.isResolveFully()) {
Expand Down Expand Up @@ -284,7 +287,7 @@ private ObjectMapper getRightMapper(String data) {
}

private String readContentFromLocation(String location, List<AuthorizationValue> auth) {
final String adjustedLocation = location.replaceAll("\\\\", "/");
final String adjustedLocation = location.replace('\\', '/');
try {
if (adjustedLocation.toLowerCase().startsWith("http")) {
return RemoteUrl.urlToString(adjustedLocation, auth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
public class OpenAPIV3ParserTest {
List<AuthorizationValue> auths = new ArrayList<>();

@Test(description = "Issue 2223: reading 3.1 spec from Windows file path location produces URISyntaxException" )
public void testWindowsFilePathRead() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
OpenAPI openAPI = openApiParser.read("\\issue-2223\\openapi.yaml");
assertNotNull(openAPI, "OpenAPI object should not be null (no errors during read())");
}

@Test
public void testFailedToResolveResponseReferences() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
Expand All @@ -51,7 +58,7 @@ public void testFailedToResolveResponseReferences() {
SwaggerParseResult parseResult = openApiParser.readLocation("issue-2037/openapi.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();

Assert.assertTrue(openAPI.getPaths().get("/get").get$ref() == null);
assertNull(openAPI.getPaths().get("/get").get$ref());
Assert.assertEquals(openAPI.getPaths().get("/get").getGet().getResponses().get("200").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/ResponsesRef");
}

Expand All @@ -64,13 +71,13 @@ public void testFailedToResolveExternalReferences() {
SwaggerParseResult parseResult = openApiParser.readLocation("resolve-external-ref/failedToResolveExternalRefs.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();

Assert.assertTrue(openAPI.getPaths().get("/permAssignments").get$ref() == null);
Assert.assertEquals(openAPI.getPaths().get("/permAssignments").getGet().getResponses().get("202").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/schemaResponseSuccess");
Assert.assertTrue(openAPI.getPaths().get("/permAssignmentChangeRequests").get$ref() == null);
Assert.assertEquals(openAPI.getPaths().get("/permAssignmentChangeRequests").getGet().getResponses().get("202").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/schemaResponseSuccess");
Assert.assertTrue(openAPI.getPaths().get("/permAssignmentChange").get$ref() == null);
Assert.assertEquals(openAPI.getPaths().get("/permAssignmentChange").getGet().getResponses().get("201").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/Error");
Assert.assertEquals(openAPI.getPaths().get("/permAssignmentChange").getGet().getResponses().get("404").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/RemoteError");
assertNull(openAPI.getPaths().get("/permAssignments").get$ref());
assertEquals(openAPI.getPaths().get("/permAssignments").getGet().getResponses().get("202").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/schemaResponseSuccess");
assertNull(openAPI.getPaths().get("/permAssignmentChangeRequests").get$ref());
assertEquals(openAPI.getPaths().get("/permAssignmentChangeRequests").getGet().getResponses().get("202").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/schemaResponseSuccess");
assertNull(openAPI.getPaths().get("/permAssignmentChange").get$ref());
assertEquals(openAPI.getPaths().get("/permAssignmentChange").getGet().getResponses().get("201").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/Error");
assertEquals(openAPI.getPaths().get("/permAssignmentChange").getGet().getResponses().get("404").getContent().get("application/vnd.api+json").getSchema().get$ref(),"#/components/schemas/RemoteError");

}

Expand Down Expand Up @@ -2188,7 +2195,7 @@ public void testIssue393() {
}

@Test
public void testBadFormat() throws Exception {
public void testBadFormat() {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
final OpenAPI openAPI = parser.read("src/test/resources/bad_format.yaml");

Expand Down Expand Up @@ -3429,4 +3436,4 @@ public void testVersion(){
SwaggerParseResult parseResult = openApiParser.readLocation("version-missing.yaml", null, options);
assertEquals(parseResult.getMessages().get(0), "attribute info.version is missing");
}
}
}
246 changes: 246 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue-2223/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
openapi: 3.1.1
info:
title: Ferguson Customer Public API
description: Services that provide access to Ferguson's customer information
contact:
name: Ferguson Middleware Services team
license:
name: Ferguson Services
url: 'https://ferguson.com/licenses/LICENSE-1.0.html'
version: v1.0
servers:
- url: https://localhost:8083/customer-publicapi-v1/svc
description: Development
tags:
- name: domain
description: Customer
- name: visibility
description: public
paths:
/{mainCustomerId}/billToZip/{billToZipCode}:
get:
operationId: getMainCustomerInfoBillZipcode
summary: Service to get Customer information from main Customer account and associated billTo zipcode
description: Service to get related Customer information
parameters:
- $ref: '#/components/parameters/transId'
- $ref: '#/components/parameters/mainCustomerId'
- $ref: '#/components/parameters/billToZipCode'

responses:
'200':
description: Request Successful
headers:
trans-id:
$ref: '#/components/headers/trans-id'
content:
application/json:
schema:
$ref: '#/components/schemas/customerInfoResponse'

'400':
description: Bad request
headers:
trans-id:
$ref: '#/components/headers/trans-id'
content:
application/json:
schema:
$ref: '#/components/schemas/validationErrors'

'404':
description: Not Found
headers:
trans-id:
$ref: '#/components/headers/trans-id'
'500':
description: Internal Error
headers:
trans-id:
$ref: '#/components/headers/trans-id'
fe-resp-code:
$ref: '#/components/headers/fe-resp-code'
fe-resp-msg:
$ref: '#/components/headers/fe-resp-msg'

components:
schemas:
regionId:
type: string
description: Region Id
example: "RICH"
branchId:
type: string
description: Branch Id
example: "1350"
customerType:
type: string
enum:
- MASTER
- MAIN
- JOB
customerName:
type: string
description: Account name
example: "WP CLARKS FARM LLC"
contractIds:
type: array
items:
type: string
description: Contract Id
customerNumber:
type: string
description: Customer Id
example: "276962"
jobName:
type: string
description: Job name
example: "OTIS HATFIELD"
jobNumber:
type: string
description: Customer Id of the Job
example: "93738"
billingAddress:
description: Billing address of the account
type: object
properties:
streets:
title: Line(s) of Street Address
type: array
items:
type: string
example: "1250 W. Mockingbird Lane"
city:
title: City
type: string
example: "Newport News"
state:
title: State Code
type: string
example: VA
postalCode:
title: Postal Code
type: string
example: 23606

customerInfoResponse:
title: Customer Info Response with master, main and job info
type: object
properties:
masterCustomerNumber:
type: string
description: Master customer number
example: '371394'
customerType:
$ref: '#/components/schemas/customerType'
mainCustomers:
type: array
items:
$ref: '#/components/schemas/mainCustomer'
mainCustomer:
type: object
properties:
customerType:
$ref: '#/components/schemas/customerType'
regionId:
$ref: '#/components/schemas/regionId'
branchId:
$ref: '#/components/schemas/branchId'
customerName:
$ref: '#/components/schemas/customerName'
contractIds:
$ref: '#/components/schemas/contractIds'
customerNumber:
$ref: '#/components/schemas/customerNumber'
billingAddress:
type: array
items:
$ref: '#/components/schemas/billingAddress'
mainCustomerJobs:
type: array
items:
$ref: '#/components/schemas/mainCustomerJob'

mainCustomerJob:
type: object
properties:
customerType:
$ref: '#/components/schemas/customerType'
regionId:
$ref: '#/components/schemas/regionId'
branchId:
$ref: '#/components/schemas/branchId'
jobName:
$ref: '#/components/schemas/jobName'
contractIds:
$ref: '#/components/schemas/contractIds'
jobNumber:
$ref: '#/components/schemas/jobNumber'
billingAddress:
type: array
items:
$ref: '#/components/schemas/billingAddress'
validationError:
title: Parameter Validation Error
type: object
x-allArgsConstructor: true
properties:
errorCode:
title: Error Code
description: Error Code indicating the nature of the error.
type: string
example: dataerror.k8.app.zipcode.invalid
errorMsg:
title: Error Message
description: Human readable message associated with the errorCode.
type: string
example: invalid zipcode format
field:
title: Parameter in Error
type: string
example: billToZipCode
validationErrors:
title: List of Validation Errors
type: array
minItems: 1
items:
$ref: '#/components/schemas/validationError'
headers:
fe-resp-code:
schema:
type: string
example: severe.error
description: Response code
fe-resp-msg:
schema:
type: string
example: Severe Error
description: Response message
trans-id:
schema:
type: string
description: Transaction Id (passed in by consumer or generated by the service)

parameters:
transId:
name: trans-id
in: header
description: Transaction Id (Provided by service consumer)
required: false
schema:
type: string
mainCustomerId:
name: mainCustomerId
in: path
description: Main Customer id
required: true
schema:
type: string
billToZipCode:
name: billToZipCode
in: path
description: Billed to zip code associated with the Main Account
required: true
schema:
type: string
pattern: '^(\\d{5})([-\\s]*\\d{4})?$'
Loading