-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schema resolution options - Phase 2: global allOf
- Loading branch information
Showing
17 changed files
with
607 additions
and
213 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
165 changes: 165 additions & 0 deletions
165
modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/AllofResolvingTest.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,165 @@ | ||
package io.swagger.v3.core.resolving; | ||
|
||
import io.swagger.v3.core.converter.AnnotatedType; | ||
import io.swagger.v3.core.converter.ModelConverterContextImpl; | ||
import io.swagger.v3.core.jackson.ModelResolver; | ||
import io.swagger.v3.core.matchers.SerializationMatchers; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.testng.annotations.Test; | ||
|
||
public class AllofResolvingTest extends SwaggerTestBase { | ||
|
||
@Test | ||
public void testAllofResolving() { | ||
|
||
final ModelResolver modelResolver = new ModelResolver(mapper()).openapi31(false).schemaResolution(io.swagger.v3.oas.models.media.Schema.SchemaResolution.ALL_OF); | ||
final ModelConverterContextImpl c = new ModelConverterContextImpl(modelResolver); | ||
// ModelConverters c = ModelConverters.getInstance(false, io.swagger.v3.oas.models.media.Schema.SchemaResolution.INLINE); | ||
c.resolve(new AnnotatedType(UserSchema.class)); | ||
|
||
String expectedYaml = "UserProperty:\n" + | ||
" type: object\n" + | ||
" description: Represents a user-specific property\n" + | ||
" example: User-specific example value\n" + | ||
"UserSchema:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" propertyOne:\n" + | ||
" allOf:\n" + | ||
" - type: object\n" + | ||
" description: First user schema property\n" + | ||
" nullable: true\n" + | ||
" - $ref: '#/components/schemas/UserProperty'\n" + | ||
" propertyTwo:\n" + | ||
" allOf:\n" + | ||
" - type: object\n" + | ||
" description: Second user schema property\n" + | ||
" example: example value for propertyTwo\n" + | ||
" - $ref: '#/components/schemas/UserProperty'\n" + | ||
" propertyThree:\n" + | ||
" allOf:\n" + | ||
" - type: object\n" + | ||
" description: \"Third user schema property, with example for testing\"\n" + | ||
" example: example value for propertyThree\n" + | ||
" - $ref: '#/components/schemas/UserProperty'\n"; | ||
|
||
SerializationMatchers.assertEqualsToYaml(c.getDefinedModels(), expectedYaml); | ||
// stringSchemaMap = c.readAll(InlineSchemaSecond.class); | ||
c.resolve(new AnnotatedType(OrderSchema.class)); | ||
expectedYaml = "BasicProperty:\n" + | ||
" type: object\n" + | ||
" description: Represents a basic schema property\n" + | ||
"OrderProperty:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" basicProperty:\n" + | ||
" $ref: '#/components/schemas/BasicProperty'\n" + | ||
" description: Represents an order-specific property\n" + | ||
" example: Order-specific example value\n" + | ||
"OrderSchema:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" propertyOne:\n" + | ||
" allOf:\n" + | ||
" - type: object\n" + | ||
" description: First order schema property\n" + | ||
" nullable: true\n" + | ||
" - $ref: '#/components/schemas/OrderProperty'\n" + | ||
" userProperty:\n" + | ||
" allOf:\n" + | ||
" - type: object\n" + | ||
" description: \"Order schema property, references UserProperty\"\n" + | ||
" example: example value for userProperty\n" + | ||
" - $ref: '#/components/schemas/UserProperty'\n" + | ||
"UserProperty:\n" + | ||
" type: object\n" + | ||
" description: Represents a user-specific property\n" + | ||
" example: User-specific example value\n" + | ||
"UserSchema:\n" + | ||
" type: object\n" + | ||
" properties:\n" + | ||
" propertyOne:\n" + | ||
" allOf:\n" + | ||
" - type: object\n" + | ||
" description: First user schema property\n" + | ||
" nullable: true\n" + | ||
" - $ref: '#/components/schemas/UserProperty'\n" + | ||
" propertyTwo:\n" + | ||
" allOf:\n" + | ||
" - type: object\n" + | ||
" description: Second user schema property\n" + | ||
" example: example value for propertyTwo\n" + | ||
" - $ref: '#/components/schemas/UserProperty'\n" + | ||
" propertyThree:\n" + | ||
" allOf:\n" + | ||
" - type: object\n" + | ||
" description: \"Third user schema property, with example for testing\"\n" + | ||
" example: example value for propertyThree\n" + | ||
" - $ref: '#/components/schemas/UserProperty'\n"; | ||
SerializationMatchers.assertEqualsToYaml(c.getDefinedModels(), expectedYaml); | ||
} | ||
|
||
// Renamed class to better describe what it represents | ||
static class UserSchema { | ||
|
||
@Schema(description = "First user schema property", nullable = true) | ||
public UserProperty propertyOne; | ||
|
||
private UserProperty propertyTwo; | ||
|
||
@Schema(description = "Second user schema property", example = "example value for propertyTwo") | ||
public UserProperty getPropertyTwo() { | ||
return propertyTwo; | ||
} | ||
|
||
// Third property with no specific annotation. It's good to add some description or example for clarity | ||
@Schema(description = "Third user schema property, with example for testing", example = "example value for propertyThree") | ||
public UserProperty getPropertyThree() { | ||
return null; // returning null as per the test scenario | ||
} | ||
} | ||
|
||
// Renamed class to represent a different entity for the schema test | ||
static class OrderSchema { | ||
|
||
@Schema(description = "First order schema property", nullable = true) | ||
public OrderProperty propertyOne; | ||
|
||
private UserProperty userProperty; | ||
|
||
@Schema(description = "Order schema property, references UserProperty", example = "example value for userProperty") | ||
public UserProperty getUserProperty() { | ||
return userProperty; | ||
} | ||
} | ||
|
||
// Renamed properties to make them clearer about their role in the schema | ||
@Schema(description = "Represents a user-specific property", example = "User-specific example value") | ||
static class UserProperty { | ||
// public String value; | ||
} | ||
|
||
@Schema(description = "Represents an order-specific property", example = "Order-specific example value") | ||
static class OrderProperty { | ||
public BasicProperty basicProperty; | ||
} | ||
|
||
static class BasicSchema { | ||
|
||
@Schema(description = "First basic schema property") | ||
public BasicProperty propertyOne; | ||
|
||
private BasicProperty propertyTwo; | ||
|
||
@Schema(description = "Second basic schema property", example = "example value for propertyTwo") | ||
public BasicProperty getPropertyTwo() { | ||
return propertyTwo; | ||
} | ||
} | ||
|
||
// Renamed to represent a basic property common in various schemas | ||
@Schema(description = "Represents a basic schema property") | ||
static class BasicProperty { | ||
// public String value; | ||
} | ||
} |
Oops, something went wrong.