Skip to content
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

Issue 1886 #2064

Merged
merged 3 commits into from
Mar 21, 2024
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 @@ -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
Loading