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

test case with deep properties which can't be resolved #1522

Merged
merged 5 commits into from
Mar 11, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,18 @@ public Schema resolveSchema(Schema schema) {

if(schema.get$ref() != null) {
String ref= schema.get$ref();
ref = ref.substring(ref.lastIndexOf("/") + 1);
Schema resolved = schemas != null ? schemas.get(ref) : null;
Schema resolved;
//This validation is done to solve deep properties eg. '#/components/schemas/TypeProject/properties/id'
if (ref.contains("/properties/")){
String split[] = ref.split("/");
String refSchema = split[3];
Schema parentSchema = schemas.get(refSchema);
ref = ref.substring(ref.lastIndexOf("/") + 1);
resolved = (Schema)parentSchema.getProperties().get(ref);
}else {
ref = ref.substring(ref.lastIndexOf("/") + 1);
resolved = schemas != null ? schemas.get(ref) : null;
}

if (resolved != null) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
Expand All @@ -82,6 +83,18 @@ public class OpenAPIV3ParserTest {
protected int serverPort = getDynamicPort();
protected WireMockServer wireMockServer;

@Test
public void testCantReadDeepProperties() {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolveFully(true);

final SwaggerParseResult parseResult = parser.readLocation("src/test/resources/cant-read-deep-properties.yaml", null, options);
assertEquals(parseResult.getMessages().size(), 0);
Schema projects = (Schema) parseResult.getOpenAPI().getComponents().getSchemas().get("Project").getProperties().get("project_type");
assertEquals(projects.getType(), "integer");
}

@Test
public void testIssueSameRefsDifferentModel() throws IOException {
String pathFile = FileUtils.readFileToString(new File("src/test/resources/same-refs-different-model-domain.yaml"), "UTF-8");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
openapi: 3.0.0
servers:
# Added by API Auto Mocking Plugin
- description: SwaggerHub API Auto Mocking
url: http://host.docker.internal:8081/p.siudy2/awfsdgrfhtgh/1.0

info:
version: '1.0'
title: issue
description: TypeProject/properties/id is not resolved
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: issue
description: issue
paths:
/projects:
get:
tags:
- project
description: list projects
responses:
'200':
description: results
content:
application/json:
schema:
type: object
properties:
projects:
type: array
items:
$ref: '#/components/schemas/Project'
'400':
description: Invalid
'401':
description: You are not authorized
'500':
description: Internal Server Error
components:
schemas:
ProjectId:
type: integer
enum: [1, 2]
description: one of project type ids
Project:
type: object
required:
- user
- project_type
properties:
user:
$ref: '#/components/schemas/User'
project_type:
$ref: '#/components/schemas/TypeProject/properties/id'
User:
type: object
required:
- full_name
- id
properties:
full_name:
type: string
example: ful lname
id:
type: string
format: uuid
TypeProject:
type: object
properties:
id:
type: integer
enum: [1, 2]
description: one of project type ids
name:
type: string
enum: ['project1', 'project2']
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
<swagger-parser-v2-version>1.0.55-SNAPSHOT</swagger-parser-v2-version>
<commons-io-version>2.6</commons-io-version>
<slf4j-version>1.7.30</slf4j-version>
<swagger-core-version>2.1.7-SNAPSHOT</swagger-core-version>
<swagger-core-version>2.1.8-SNAPSHOT</swagger-core-version>
<swagger-core-v2-version>1.6.3-SNAPSHOT</swagger-core-v2-version>
<junit-version>4.13.1</junit-version>
<testng-version>6.14.2</testng-version>
Expand Down