Skip to content

Commit

Permalink
Merge pull request #2064 from walaniam/issue_1886_202403
Browse files Browse the repository at this point in the history
Issue 1886
  • Loading branch information
gracekarina authored Mar 21, 2024
2 parents 46e3ca9 + 5dc1cf1 commit e3746af
Show file tree
Hide file tree
Showing 20 changed files with 1,152 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.swagger.v3.parser.ResolverCache;
import io.swagger.v3.parser.models.RefFormat;
import io.swagger.v3.parser.models.RefType;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -130,10 +131,11 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
String[] parts = schemaFullRef.split("#/");
String schemaFullRefFilePart = parts[0];
String schemaFullRefInternalRefPart = parts[1];
schemaFullRef = Paths.get(parent, schemaFullRefFilePart).normalize().toString() + "#/" + schemaFullRefInternalRefPart;
schemaFullRef = Paths.get(parent, schemaFullRefFilePart).normalize() + "#/" + schemaFullRefInternalRefPart;
} else {
schemaFullRef = Paths.get(parent, schemaFullRef).normalize().toString();
}
schemaFullRef = FilenameUtils.separatorsToUnix(schemaFullRef);
}
schema.set$ref(processRefToExternalSchema(schemaFullRef, ref));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3269,4 +3269,20 @@ public void test31SafeURLResolvingWithLocalhost() {
}
}
}

@Test
public void testIssue1886() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
SwaggerParseResult parseResult = openApiParser.readLocation("issue-1886/openapi.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();
assertEqualsNoOrder(
openAPI.getComponents().getSchemas().keySet(),
Arrays.asList("ArrayPojo", "Enum1", "Enum1_1", "Enum2", "Enum3", "MapPojo", "SetPojo", "SimplePojo",
"TransactionsPatchRequestBody", "additional-properties", "array-pojo", "locale-translation-item",
"map-pojo", "set-pojo", "simple-pojo", "translation-item")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Enum1:
$ref: schemas/enum1.yaml
Enum2:
type: string
enum: [a, b, c]
nullable: false
Enum3:
type: string
enum: [x, y, z]
nullable: true

SimplePojo:
$ref: schemas/simple-pojo.yaml
ArrayPojo:
$ref: schemas/array-pojo.yaml
MapPojo:
$ref: schemas/map-pojo.yaml
SetPojo:
$ref: schemas/set-pojo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
openapi: 3.0.3

info:
title: Arrangement Support
version: '1.0'

paths:
/simple-types:
$ref: paths/simple-types.yaml
/simple-types/{id}/{ids}:
$ref: paths/simple-types-ids.yaml
/array-types:
$ref: paths/array-types.yaml
/array-types/{id}/{ids}:
$ref: paths/array-types-ids.yaml
/set-types:
$ref: paths/set-types.yaml
/set-types/{id}/{ids}:
$ref: paths/set-types-ids.yaml
/map-types:
$ref: paths/map-types.yaml
/map-types/{id}/{ids}:
$ref: paths/map-types-ids.yaml
/transactions:
patch:
tags:
- transactions
summary: patch
description: Updates list of transactions
operationId: patchTransactions
requestBody:
description: Updates list of transactions
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/TransactionsPatchRequestBody'
responses:
"204":
description: OK

components:
schemas:
TransactionsPatchRequestBody:
required:
- id
type: object
properties:
id:
maxLength: 300
type: string
description: Unique identification for the transaction as used in the external
system
arrangementId:
maxLength: 50
type: string
description: An external reference to the arrangement the transaction belongs
to
category:
maxLength: 50
type: string
description: Transaction category
billingStatus:
maxLength: 8
type: string
creationTime:
type: string
format: date-time
x-java-type: java.time.OffsetDateTime

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
parameters:
- name: id
required: true
in: path
schema:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: ids
in: path
required: true
schema:
type: array
items:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
delete:
tags:
- array-types
x-content-language: application/json
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
$ref: '../components.yaml#/ArrayPojo'
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '../components.yaml#/ArrayPojo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
get:
tags:
- array-types
x-content-language: application/json
parameters:
- name: h-param
in: header
schema:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: h-params
in: header
schema:
type: array
items:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: c-param
in: cookie
schema:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: c-params
in: cookie
schema:
type: array
items:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: q-param
in: query
required: false
schema:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: q-param-enum
in: query
required: false
schema:
$ref: '../components.yaml#/Enum1'
- name: q-param-req
in: query
required: true
schema:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: q-param-enum-req
in: query
required: true
schema:
$ref: '../components.yaml#/Enum2'
- name: q-params
in: query
schema:
type: array
items:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: q-params-enum
in: query
schema:
type: array
items:
$ref: '../components.yaml#/Enum3'
- name: q-params-req
in: query
required: true
schema:
type: array
items:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: q-params-set
in: query
required: false
schema:
type: array
uniqueItems: true
items:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: q-params-set-req
in: query
required: true
schema:
type: array
uniqueItems: true
items:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '../components.yaml#/ArrayPojo'
post:
tags:
- array-types
x-content-language: application/json
requestBody:
required: true
content:
application/json:
schema:
$ref: '../components.yaml#/ArrayPojo'
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '../components.yaml#/ArrayPojo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
parameters:
- name: id
required: true
in: path
schema:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
- name: ids
in: path
required: true
schema:
type: array
items:
type: string
minLength: 1
maxLength: 36
pattern: '^[A-Z]+$'
delete:
tags:
- simple-types
x-content-language: application/json
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
$ref: '../components.yaml#/SimplePojo'
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '../components.yaml#/SimplePojo'
Loading

0 comments on commit e3746af

Please sign in to comment.