Skip to content

Commit

Permalink
Merge branch 'master' into sean/setup-java-v4-ftw
Browse files Browse the repository at this point in the history
  • Loading branch information
sullis authored Apr 5, 2024
2 parents 07b84e9 + 5040b8b commit 8d09557
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ You can include this library from Sonatype OSS for SNAPSHOTS, or Maven central f
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.1.21</version>
<version>2.1.22</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions modules/swagger-parser-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>swagger-parser-project</artifactId>
<groupId>io.swagger.parser.v3</groupId>
<version>2.1.22-SNAPSHOT</version>
<version>2.1.22</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-v3</artifactId>
<version>2.1.22-SNAPSHOT</version>
<version>2.1.22</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-parser-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-project</artifactId>
<version>2.1.22-SNAPSHOT</version>
<version>2.1.22</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-parser-safe-url-resolver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-project</artifactId>
<version>2.1.22-SNAPSHOT</version>
<version>2.1.22</version>
<relativePath>../../pom.xml</relativePath>

</parent>
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-parser-v2-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-project</artifactId>
<version>2.1.22-SNAPSHOT</version>
<version>2.1.22</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-parser-v3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-project</artifactId>
<version>2.1.22-SNAPSHOT</version>
<version>2.1.22</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,36 +147,7 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {

if(schema instanceof ComposedSchema){
ComposedSchema composedSchema = (ComposedSchema) schema;
if (composedSchema.getAllOf() != null){
for(Schema item : composedSchema.getAllOf()){
if (item.get$ref() != null){
processRefSchema(item,file);
} else{
processSchema(item, file);
}
}

}if (composedSchema.getOneOf() != null){
for(Schema item : composedSchema.getOneOf()){
if (item.get$ref() != null){
if (item.get$ref() != null){
processRefSchema(item,file);
}else{
processSchema(item, file);
}
}
}
}if (composedSchema.getAnyOf() != null){
for(Schema item : composedSchema.getAnyOf()){
if (item.get$ref() != null){
if (item.get$ref() != null){
processRefSchema(item,file);
}else{
processSchema(item, file);
}
}
}
}
processComposedSchema(composedSchema, file);
}
//Loop the properties and recursively call this method;
Map<String, Schema> subProps = schema.getProperties();
Expand Down Expand Up @@ -213,13 +184,52 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
if (StringUtils.isNotBlank(arraySchema.getItems().get$ref())) {
processRefSchema(((ArraySchema) schema).getItems(), file);
} else {
processProperties(arraySchema.getItems().getProperties() ,file);
if (arraySchema.getItems() instanceof ComposedSchema) {
ComposedSchema composedSchema = (ComposedSchema) arraySchema.getItems();
processComposedSchema(composedSchema, file);
}
processProperties(arraySchema.getItems().getProperties(), file);
}
}
}
return newRef;
}

private void processComposedSchema(ComposedSchema composedSchema, String file) {
if (composedSchema.getAllOf() != null) {
for (Schema item : composedSchema.getAllOf()) {
if (item.get$ref() != null) {
processRefSchema(item, file);
} else {
processSchema(item, file);
}
}

}
if (composedSchema.getOneOf() != null) {
for (Schema item : composedSchema.getOneOf()) {
if (item.get$ref() != null) {
if (item.get$ref() != null) {
processRefSchema(item, file);
} else {
processSchema(item, file);
}
}
}
}
if (composedSchema.getAnyOf() != null) {
for (Schema item : composedSchema.getAnyOf()) {
if (item.get$ref() != null) {
if (item.get$ref() != null) {
processRefSchema(item, file);
} else {
processSchema(item, file);
}
}
}
}
}

private void processSchema(Schema property, String file) {
if (property != null) {
if (StringUtils.isNotBlank(property.get$ref())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.parser.OpenAPIV3Parser;
import io.swagger.v3.parser.ResolverCache;
import io.swagger.v3.parser.core.models.AuthorizationValue;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import io.swagger.v3.parser.models.RefFormat;
import io.swagger.v3.parser.util.RemoteUrl;
import mockit.Expectations;
import mockit.Injectable;
import mockit.Mocked;
import mockit.Expectations;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.ArrayList;
Expand All @@ -23,6 +27,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.testng.Assert.assertEquals;


Expand Down Expand Up @@ -206,4 +211,22 @@ public void testRelativeRefIncludingUrlRef()
is("./relative-with-url/relative-with-local.yaml#/relative-same-file")
);
}

@Test
public void testHandleComposedSchemasInArrayItems() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult parseResult = openApiParser.readLocation("issue-2071/openapi.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();

Map<String, Schema> components = openAPI.getComponents().getSchemas();
assertEquals(components.size(), 5);
assertTrue(components.containsKey("Response"));
assertTrue(components.containsKey("ProductRow"));
assertTrue(components.containsKey("ProductRowType"));
assertTrue(components.containsKey("OrderRow"));
assertTrue(components.containsKey("OrderRowType"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
components:
schemas:
Response:
type: array
items:
oneOf:
- $ref: '#/components/schemas/ProductRow'
properties:
orderRow:
$ref: '#/components/schemas/OrderRow'
discriminator:
propertyName: type
mapping:
'product': '#/components/schemas/ProductRow'
ProductRow:
type: object
additionalProperties: false
required:
- type
properties:
type:
$ref: '#/components/schemas/ProductRowType'
payload:
type: string
ProductRowType:
type: string
enum:
- product
OrderRow:
type: object
additionalProperties: false
required:
- type
properties:
type:
$ref: '#/components/schemas/OrderRowType'
payload:
type: string
OrderRowType:
type: string
enum:
- order
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
openapi: 3.0.1
info:
title: API
description: API
version: LATEST
paths:
/test-path:
post:
requestBody:
required: true
content:
text/plain:
schema:
type: string
responses:
200:
description: OK
content:
application/json:
schema:
$ref: 'definitions.yaml#/components/schemas/Response'
2 changes: 1 addition & 1 deletion modules/swagger-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-project</artifactId>
<version>2.1.22-SNAPSHOT</version>
<version>2.1.22</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-project</artifactId>
<version>2.1.22-SNAPSHOT</version>
<version>2.1.22</version>
<packaging>pom</packaging>
<name>swagger-parser-project</name>
<developers>
Expand Down

0 comments on commit 8d09557

Please sign in to comment.