diff --git a/modules/swagger-parser/src/main/java/io/swagger/parser/processors/ExternalRefProcessor.java b/modules/swagger-parser/src/main/java/io/swagger/parser/processors/ExternalRefProcessor.java index 8d91d8972e..180a769258 100644 --- a/modules/swagger-parser/src/main/java/io/swagger/parser/processors/ExternalRefProcessor.java +++ b/modules/swagger-parser/src/main/java/io/swagger/parser/processors/ExternalRefProcessor.java @@ -3,6 +3,7 @@ import io.swagger.models.*; import io.swagger.models.properties.ArrayProperty; import io.swagger.models.properties.MapProperty; +import io.swagger.models.properties.ObjectProperty; import io.swagger.models.properties.Property; import io.swagger.models.properties.RefProperty; import io.swagger.models.refs.RefFormat; @@ -218,6 +219,12 @@ private void processProperties(final Map subProps, final Strin if (arrayProp.getItems() instanceof RefProperty) { processRefProperty((RefProperty) arrayProp.getItems(), file); } + if (arrayProp.getItems() != null){ + if (arrayProp.getItems() instanceof ObjectProperty) { + ObjectProperty objectProperty = (ObjectProperty) arrayProp.getItems(); + processProperties(objectProperty.getProperties(), file); + } + } } else if (prop.getValue() instanceof MapProperty) { MapProperty mapProp = (MapProperty) prop.getValue(); if (mapProp.getAdditionalProperties() instanceof RefProperty) { diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java index 40fb752d0e..f4ce3f3777 100644 --- a/modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java +++ b/modules/swagger-parser/src/test/java/io/swagger/parser/SwaggerParserTest.java @@ -25,6 +25,7 @@ import io.swagger.models.properties.ByteArrayProperty; import io.swagger.models.properties.IntegerProperty; import io.swagger.models.properties.MapProperty; +import io.swagger.models.properties.ObjectProperty; import io.swagger.models.properties.Property; import io.swagger.models.properties.RefProperty; import io.swagger.models.properties.StringProperty; @@ -54,6 +55,19 @@ public class SwaggerParserTest { + @Test + public void testIssueRelativeRefs2(){ + String location = "exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json"; + Swagger swagger = new SwaggerParser().read(location, null, true); + assertNotNull(swagger); + Map definitions = swagger.getDefinitions(); + Assert.assertTrue(definitions.get("confirmMessageType_v01").getProperties().get("resources") instanceof ArrayProperty); + ArrayProperty arraySchema = (ArrayProperty) definitions.get("confirmMessageType_v01").getProperties().get("resources"); + ObjectProperty prop = (ObjectProperty) arraySchema.getItems(); + RefProperty refProperty = (RefProperty) prop.getProperties().get("resourceID"); + assertEquals(refProperty.get$ref(),"#/definitions/simpleIDType_v01"); + } + @Test public void testIssue845() { SwaggerDeserializationResult swaggerDeserializationResult = new SwaggerParser().readWithInfo(""); diff --git a/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/confirmMessageType_v01.json b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/confirmMessageType_v01.json new file mode 100755 index 0000000000..763be74cdb --- /dev/null +++ b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/confirmMessageType_v01.json @@ -0,0 +1,50 @@ +{ + "description": "", + "type": "object", + "properties": { + "confirmMessageID": { + "description": "", + "$ref": "./simpleIDType_v01.json" + }, + "processID": { + "description": "", + "$ref": "./simpleIDType_v01.json" + }, + "processStatus": { + "description": "", + "type": "string", + "enum": [ + "success", "partial-failure", "failure" + ] + }, + "resources": { + "type": "array", + "items": { + "type": "object", + "properties": { + "resourceID": { + "description": "", + "$ref": "./simpleIDType_v01.json" + }, + "resourceReference": { + "description": "", + "type": "string" + }, + "resourceStatus": { + "description": "", + "type": "string", + "enum": [ + "success", "partial-failure", "failure" + ] + } + } + } + }, + "links": { + "type": "array", + "items": { + "$ref": "./linkType_v01.json" + } + } + } +} \ No newline at end of file diff --git a/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/confirmMessageType_v02.json b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/confirmMessageType_v02.json new file mode 100755 index 0000000000..763be74cdb --- /dev/null +++ b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/confirmMessageType_v02.json @@ -0,0 +1,50 @@ +{ + "description": "", + "type": "object", + "properties": { + "confirmMessageID": { + "description": "", + "$ref": "./simpleIDType_v01.json" + }, + "processID": { + "description": "", + "$ref": "./simpleIDType_v01.json" + }, + "processStatus": { + "description": "", + "type": "string", + "enum": [ + "success", "partial-failure", "failure" + ] + }, + "resources": { + "type": "array", + "items": { + "type": "object", + "properties": { + "resourceID": { + "description": "", + "$ref": "./simpleIDType_v01.json" + }, + "resourceReference": { + "description": "", + "type": "string" + }, + "resourceStatus": { + "description": "", + "type": "string", + "enum": [ + "success", "partial-failure", "failure" + ] + } + } + } + }, + "links": { + "type": "array", + "items": { + "$ref": "./linkType_v01.json" + } + } + } +} \ No newline at end of file diff --git a/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/dateType_v01.json b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/dateType_v01.json new file mode 100755 index 0000000000..d2fc1d9be5 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/dateType_v01.json @@ -0,0 +1,6 @@ +{ + "title": "date", + "description": "The string representation", + "type": "string", + "format": "date" +} \ No newline at end of file diff --git a/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/linkType_v01.json b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/linkType_v01.json new file mode 100755 index 0000000000..fba85bbb4e --- /dev/null +++ b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/linkType_v01.json @@ -0,0 +1,64 @@ +{ + "title": "link", + "description": "A link description object", + "type": "object", + "properties": { + "href": { + "$ref": "./simpleIDType_v01.json" + }, + "mediaType": { + "description": "media type description", + "type": "string", + "enum": [ + "application/gzip", + "application/json", + "application/msword", + "application/pdf", + "application/postscript", + "application/vnd.ms-excel", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "application/xml", + "application/x-www-form-urlencoded", + "image/gif", + "image/jpeg", + "image/png", + "image/tiff", + "multipart/mixed", + "text/html", + "text/plain", + "application/vnd.visio", + "image/bmp", + "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "application/vnd.ms-powerpoint", + "video/mp4", + "audio/mpeg", + "video/x-msvideo", + "video/x-ms-wmv", + "application/rtf", + "application/vnd.ms-outlook", + "text/csv", + "video/quicktime", + "application/zip", + "application/illustrator", + "text/xml" + ] + }, + "payloadArguments": { + "type": "array", + "items": { + "type": "object", + "properties": { + "argumentPath": { + "description": "payloadArguments", + "type": "string" + }, + "argumentValue": { + "description": "payloadArguments", + "type": "string" + } + } + } + } + } +} \ No newline at end of file diff --git a/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/simpleIDType_v01.json b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/simpleIDType_v01.json new file mode 100755 index 0000000000..81a02b5f15 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/common/simpleIDType_v01.json @@ -0,0 +1,7 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "simpleID", + "description": "Simple (string) identifier of an object to be used when there is no appropriate specific named ID Type", + "type": "string", + "pattern": "^[a-zA-Z0-9.$-_\/]+$" +} \ No newline at end of file diff --git a/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/schemas/test-api-schema_v01.json b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/schemas/test-api-schema_v01.json new file mode 100755 index 0000000000..c470b62f02 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/schemas/test-api-schema_v01.json @@ -0,0 +1,28 @@ +{ + "description": "Description", + "type": "object", + "properties": { + "testingApi": { + "type": "array", + "items": { + "title": "testingApi", + "type": "object", + "properties": { + "itemID": { + "$ref": "../../../../common/simpleIDType_v01.json" + }, + "testLink": { + "type": "array", + "items": { + "$ref": "../../../../common/linkType_v01.json" + } + } + }, + "additionalProperties": false + } + }, + "_confirmMessage": { + "$ref": "../../../../common/confirmMessageType_v01.json" + } + } +} \ No newline at end of file diff --git a/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/schemas/test-api-schema_v02.json b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/schemas/test-api-schema_v02.json new file mode 100755 index 0000000000..5e02ac8c45 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/schemas/test-api-schema_v02.json @@ -0,0 +1,28 @@ +{ + "description": "Test Description", + "type": "object", + "properties": { + "testingApi": { + "type": "array", + "items": { + "title": "testingApi", + "type": "object", + "properties": { + "itemID": { + "$ref": "../../../../common/simpleIDType_v01.json" + }, + "testLink": { + "type": "array", + "items": { + "$ref": "../../../../common/linkType_v01.json" + } + } + }, + "additionalProperties": false + } + }, + "_confirmMessage": { + "$ref": "../../../../common/confirmMessageType_v02.json" + } + } +} \ No newline at end of file diff --git a/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json new file mode 100755 index 0000000000..90bd50b266 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json @@ -0,0 +1,78 @@ +{ + "swagger": "2.0", + "info": { + "description": "APIs to retrieve some data", + "version": "1.0", + "title": "TEST A NEW API", + "contact": { + "name": "mine", + "email": "mine@me.com" + } + }, + "tags": [ + { + "name": "Test", + "description": "APIs to retrieve some data" + } + ], + "paths": { + "/my-domain/v1/test-system": { + "get": { + "description": "Retrieve relevant data", + "tags": [ + "Test" + ], + "summary": "Retrieve relevant data", + "responses": { + "200": { + "description": "Request was successful", + "headers": { + }, + "schema": { + "$ref": "./schemas/test-api-schema_v02.json" + } + }, + "400": { + "$ref": "#/responses/400" + } + } + } + } + }, + "definitions": { + }, + "responses": { + "200": { + "description": "OK", + "headers": { + } + }, + "400": { + "description": "Bad Request", + "headers": { + }, + "schema": { + "$ref": "../../../common/confirmMessageType_v01.json" + } + } + }, + "parameters": { + "asOfDate": { + "name": "asOfDate", + "in": "query", + "description": "date", + "required": false, + "example": "2017-01-01" + }, + "header_Accept-Language": { + "name": "Accept-Language", + "in": "header", + "description": "Accept-Language", + "required": false, + "schema": { + "type": "string" + } + } + } + +} \ No newline at end of file