-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parameter data detection fix when PathParams changed (#353)
Fixes #353
- Loading branch information
1 parent
17c8142
commit 5105f0b
Showing
10 changed files
with
342 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/src/test/java/org/openapitools/openapidiff/core/PathParameterSchemaDiffTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.openapitools.openapidiff.core; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.openapitools.openapidiff.core.model.ChangedOpenApi; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class PathParameterSchemaDiffTest { | ||
final String TEST_MSG_1 = | ||
"Testing: \n" | ||
+ "1. Same path but different pathParameters\n" | ||
+ "2. different parameters in the parameters: section\n" | ||
+ "3. Parameters have different schema\n" | ||
+ "eg:\n" | ||
+ "old path -- students/{id}\n" | ||
+ "old schema -- id: integer\n" | ||
+ "new path -- students/{username}\n" | ||
+ "new schema -- username: string"; | ||
|
||
final String TEST_MSG_2 = | ||
"Testing: \n" | ||
+ "1. Same path but different pathParameters\n" | ||
+ "2. different parameters in the parameters: section\n" | ||
+ "3. Parameters have same schema\n"; | ||
|
||
@Test | ||
@DisplayName( | ||
"Same Path, different PathParams, Params in the `Parameters`: match pathParam, Different Schema") | ||
public void pathSamePathParamsDiffParamSameAsInPathButSchemaDiff() { | ||
final Logger logger = LoggerFactory.getLogger(PathParameterSchemaDiffTest.class); | ||
logger.info(TEST_MSG_1); | ||
String OPENAPI_DOC1 = "path_parameter_diff_param_schema_diff_old.yaml"; | ||
String OPENAPI_DOC2 = "path_parameter_diff_param_schema_diff_new.yaml"; | ||
ChangedOpenApi diff = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2); | ||
Assertions.assertTrue(diff.isDifferent()); | ||
Assertions.assertFalse(diff.isCompatible()); | ||
} | ||
|
||
@Test | ||
@DisplayName( | ||
"Same Path, different PathParams, Params in the `Parameters`: match pathParam, same Schema") | ||
public void pathSamePathParamsDiffParamNameDiffSchemaSame() { | ||
final Logger logger = LoggerFactory.getLogger(PathParameterSchemaDiffTest.class); | ||
logger.info(TEST_MSG_2); | ||
String OPENAPI_DOC1 = "path_parameter_diff_param_name_diff_old.yaml"; | ||
String OPENAPI_DOC2 = "path_parameter_diff_param_name_diff_new.yaml"; | ||
ChangedOpenApi diff = OpenApiCompare.fromLocations(OPENAPI_DOC1, OPENAPI_DOC2); | ||
Assertions.assertFalse(diff.isDifferent()); | ||
Assertions.assertTrue(diff.isCompatible()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
core/src/test/resources/path_parameter_diff_param_name_diff_new.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Sample API | ||
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. | ||
version: 0.1.9 | ||
servers: | ||
- url: http://api.example.com/v1 | ||
description: Example api server | ||
|
||
paths: | ||
|
||
/student/{username}: | ||
get: | ||
parameters: | ||
- in: path | ||
name: username # Note the name is the same as in the path | ||
required: true | ||
schema: | ||
type: string | ||
minimum: 1 | ||
|
||
|
||
summary: Returns data about a student | ||
responses: | ||
'200': # status code | ||
description: A JSON Object student data | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
items: | ||
$ref: '#/components/schemas/Student' | ||
|
||
components: | ||
schemas: | ||
Student: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
example: "1" | ||
username: | ||
type: string | ||
example: "alloy_horizon" | ||
pattern: A..Z a..z 0..9 . _ - | ||
name: | ||
type: string | ||
example: "Alloy Horizon" |
48 changes: 48 additions & 0 deletions
48
core/src/test/resources/path_parameter_diff_param_name_diff_old.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Sample API | ||
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. | ||
version: 0.1.9 | ||
servers: | ||
- url: http://api.example.com/v1 | ||
description: Example api server | ||
|
||
paths: | ||
|
||
/student/{id}: | ||
get: | ||
parameters: | ||
- in: path | ||
name: id # Note the name is the same as in the path | ||
required: true | ||
schema: | ||
type: string | ||
minimum: 1 | ||
|
||
|
||
summary: Returns data about a student | ||
responses: | ||
'200': # status code | ||
description: A JSON Object student data | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
items: | ||
$ref: '#/components/schemas/Student' | ||
|
||
components: | ||
schemas: | ||
Student: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
example: "1" | ||
username: | ||
type: string | ||
example: "alloy_horizon" | ||
pattern: A..Z a..z 0..9 . _ - | ||
name: | ||
type: string | ||
example: "Alloy Horizon" |
48 changes: 48 additions & 0 deletions
48
core/src/test/resources/path_parameter_diff_param_schema_diff_new.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Sample API | ||
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. | ||
version: 0.1.9 | ||
servers: | ||
- url: http://api.example.com/v1 | ||
description: Example api server | ||
|
||
paths: | ||
|
||
/student/{username}: | ||
get: | ||
parameters: | ||
- in: path | ||
name: username # Note the name is the same as in the path | ||
required: true | ||
schema: | ||
type: string | ||
minimum: 1 | ||
|
||
|
||
summary: Returns data about a student | ||
responses: | ||
'200': # status code | ||
description: A JSON Object student data | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
items: | ||
$ref: '#/components/schemas/Student' | ||
|
||
components: | ||
schemas: | ||
Student: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
example: "1" | ||
username: | ||
type: string | ||
example: "alloy_horizon" | ||
pattern: A..Z a..z 0..9 . _ - | ||
name: | ||
type: string | ||
example: "Alloy Horizon" |
Oops, something went wrong.