Skip to content
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 @@ -794,7 +794,6 @@ public String processRefToExternalParameter(String $ref, RefFormat refFormat) {
if(renamedRef != null) {
return renamedRef;
}

final Parameter parameter = cache.loadRef($ref, refFormat, Parameter.class);

if(parameter == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public void processParameter(Parameter parameter) {
if($ref != null){
RefFormat refFormat = computeRefFormat(parameter.get$ref());
if (isAnExternalRefFormat(refFormat)){
final String newRef = externalRefProcessor.processRefToExternalParameter($ref, refFormat);
String newRef = externalRefProcessor.processRefToExternalParameter($ref, refFormat);
if (newRef != null) {
newRef = "#/components/parameters/" + newRef;
parameter.set$ref(newRef);
}
}
Expand Down Expand Up @@ -75,11 +76,9 @@ public void processParameter(Parameter parameter) {
}

public List<Parameter> processParameters(List<Parameter> parameters) {

if (parameters == null) {
return null;
}

final List<Parameter> processedPathLevelParameters = new ArrayList<>();
final List<Parameter> refParameters = new ArrayList<>();

Expand All @@ -92,7 +91,6 @@ public List<Parameter> processParameters(List<Parameter> parameters) {
//result.warning(location, "The parameter should use Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters.");
continue;
}

if(resolvedParameter == null) {
// can't resolve it!
processedPathLevelParameters.add(parameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ public void processPaths() {
PathItem pathItem = pathMap.get(pathStr);

if (pathItem.get$ref() != null) {

PathItem resolvedPath = processReferencePath(pathItem);

String pathRef = pathItem.get$ref().split("#")[0];

if (resolvedPath != null) {
updateRefs(resolvedPath, pathRef);
//we need to put the resolved path into swagger object
Expand All @@ -84,7 +81,6 @@ public void processPaths() {
final List<Parameter> processedPathParameters = parameterProcessor.processParameters(pathItem.getParameters());
pathItem.setParameters(processedPathParameters);


final Map<PathItem.HttpMethod, Operation> operationMap = pathItem.readOperationsMap();

for (PathItem.HttpMethod httpMethod : operationMap.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.Set;
import java.util.stream.Collectors;


import io.swagger.v3.parser.core.models.SwaggerParseResult;
import org.junit.Before;
import org.junit.Test;
import org.testng.Assert;
Expand All @@ -33,6 +35,31 @@ public void parseOASSpec() {
options.setResolve(true);
oas = new OpenAPIV3Parser().read("oas3-refs-test/openapi.json", null, options);
}

@Test
public void testRefContainingDot() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("resolve-dot-containing-ref/standaloneSpec.yaml", null, options);

Assert.assertNotNull(result.getOpenAPI());
Assert.assertTrue(result.getMessages().isEmpty(), "No error messages should be present");
Assert.assertNotNull(result.getOpenAPI().getPaths().get("/endpoint").getGet().getParameters());
Assert.assertEquals(result.getOpenAPI().getPaths().get("/endpoint").getGet().getParameters().get(0).getName(), "FbtPrincipalIdentity");
}

@Test
public void testExternalRefContainingDot() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation("resolve-dot-containing-ref/externalRefSpec.yaml", null, options);

Assert.assertNotNull(result.getOpenAPI());
Assert.assertTrue(result.getMessages().isEmpty(), "No error messages should be present");
Assert.assertNotNull(result.getOpenAPI().getPaths().get("/endpoint").getGet().getParameters());
Assert.assertEquals(result.getOpenAPI().getPaths().get("/endpoint").getGet().getParameters().get(0).getName(), "FbtPrincipalIdentity");
}

@Test
public void testParameterExampleRefProcessed() {
String paramName = "correlation_id";
Expand Down Expand Up @@ -85,3 +112,4 @@ public void testComposedArrayItemsRef() {
assertEquals(adopterAlias.getItems().getAllOf().size(), 2, "Processed schemas items");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.0
info:
title: Test domain
description: Domain for testing
version: '1.0.0'
components:
parameters:
FbtPrincipalIdentity_V3.1:
name: FbtPrincipalIdentity
in: query
schema:
type: string
FbtPrincipalIdentity_V31:
name: FbtPrincipalIdentity
in: query
schema:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
openapi: 3.0.0
info:
title: Test API
version: 1.0.0
description: Test API with dot-containing $ref
paths:
/endpoint:
get:
summary: summary
operationId: id
description: Test description
parameters:
- $ref: 'resolve-dot-containing-ref/externalRefDomain.yaml#/components/parameters/FbtPrincipalIdentity_V3.1'
responses:
'200':
description: get description
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/item'
components:
schemas:
item:
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
openapi: 3.0.0
info:
title: Test API
version: 1.0.0
description: Test API with dot-containing $ref
paths:
/endpoint:
get:
summary: summary
operationId: id
description: Test description
parameters:
- $ref: '#/components/parameters/FbtPrincipalIdentity_V3.1'
responses:
'200':
description: get description
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/item'
components:
parameters:
FbtPrincipalIdentity_V3.1:
name: FbtPrincipalIdentity
in: query
schema:
type: string
FbtPrincipalIdentity_V31:
name: FbtPrincipalIdentity
in: query
schema:
type: string
schemas:
item:
type: object
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
<swagger-parser-v2-version>1.0.75</swagger-parser-v2-version>
<commons-io-version>2.19.0</commons-io-version>
<slf4j-version>2.0.9</slf4j-version>
<swagger-core-version>2.2.32</swagger-core-version>
<swagger-core-version>2.2.34</swagger-core-version>
<swagger-core-v2-version>1.6.16</swagger-core-v2-version>
<junit-version>4.13.2</junit-version>
<testng-version>7.11.0</testng-version>
Expand Down
Loading