Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3587e6d

Browse files
committed
Made the spec that is generated compliant (as far as possible)
Added xml attributes and removed content where it wasnt appropriate (2311)
1 parent db071b0 commit 3587e6d

4 files changed

Lines changed: 91 additions & 15 deletions

File tree

springfox-data-rest/src/main/java/springfox/documentation/spring/data/rest/schema/EmbeddedCollectionModelProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import springfox.documentation.schema.Model;
2929
import springfox.documentation.schema.ModelProperty;
3030
import springfox.documentation.schema.TypeNameExtractor;
31+
import springfox.documentation.schema.Xml;
3132
import springfox.documentation.spi.DocumentationType;
3233
import springfox.documentation.spi.schema.SyntheticModelProviderPlugin;
3334
import springfox.documentation.spi.schema.contexts.ModelContext;
@@ -69,6 +70,10 @@ public Model create(ModelContext context) {
6970
.qualifiedType(type.getName())
7071
.type(typeParameters.get(0))
7172
.properties(Maps.uniqueIndex(properties(context), byName()))
73+
.xml(new Xml()
74+
.wrapped(true)
75+
.name("content")
76+
)
7277
.build();
7378
}
7479

springfox-data-rest/src/main/java/springfox/documentation/spring/data/rest/schema/ResourcesModelProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import springfox.documentation.schema.Model;
2929
import springfox.documentation.schema.ModelProperty;
3030
import springfox.documentation.schema.TypeNameExtractor;
31+
import springfox.documentation.schema.Xml;
3132
import springfox.documentation.spi.DocumentationType;
3233
import springfox.documentation.spi.schema.SyntheticModelProviderPlugin;
3334
import springfox.documentation.spi.schema.contexts.ModelContext;
@@ -68,6 +69,11 @@ public Model create(ModelContext context) {
6869
.qualifiedType(type.getName())
6970
.type(typeParameters.get(0))
7071
.properties(Maps.uniqueIndex(properties(context), byName()))
72+
.xml(new Xml()
73+
.name("entities")
74+
.wrapped(false)
75+
.attribute(false)
76+
)
7177
.build();
7278
}
7379

@@ -86,7 +92,6 @@ public List<ModelProperty> properties(ModelContext context) {
8692
.position(0)
8793
.required(true)
8894
.isHidden(false)
89-
.description("Resource collection")
9095
.build()
9196
.updateModelRef(modelRefFactory(context, typeNameExtractor)),
9297
new ModelPropertyBuilder()

springfox-schema/src/main/java/springfox/documentation/schema/DefaultModelProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public com.google.common.base.Optional<Model> modelFor(ModelContext modelContext
9090

9191
Optional<Model> syntheticModel = schemaPluginsManager.syntheticModel(modelContext);
9292
if (syntheticModel.isPresent()) {
93-
return syntheticModel;
93+
return Optional.of(schemaPluginsManager.model(modelContext));
9494
}
9595
return reflectionBasedModel(modelContext, propertiesHost);
9696
}

swagger-contract-tests/src/test/resources/contract/swagger2/declaration-spring-data-rest.json

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,11 @@
16671667
}
16681668
},
16691669
"title": "EmbeddedCollectionOfAddress",
1670-
"description": "Embedded collection of Address"
1670+
"description": "Embedded collection of Address",
1671+
"xml": {
1672+
"name": "content",
1673+
"wrapped": true
1674+
}
16711675
},
16721676
"EmbeddedCollectionOfPerson": {
16731677
"type": "object",
@@ -1701,21 +1705,76 @@
17011705
}
17021706
},
17031707
"title": "EmbeddedCollectionOfTag",
1704-
"description": "Embedded collection of Tag"
1708+
"description": "Embedded collection of Tag",
1709+
"xml": {
1710+
"name": "content",
1711+
"wrapped": true
1712+
}
17051713
},
17061714
"Link": {
17071715
"type": "object",
1708-
"required": [
1709-
"href"
1710-
],
17111716
"properties": {
1717+
"deprecation": {
1718+
"type": "string",
1719+
"xml": {
1720+
"name": "deprecation",
1721+
"attribute": true,
1722+
"wrapped": false
1723+
}
1724+
},
17121725
"href": {
17131726
"type": "string",
1714-
"description": "Resource collection"
1727+
"xml": {
1728+
"name": "href",
1729+
"attribute": true,
1730+
"wrapped": false
1731+
}
1732+
},
1733+
"hreflang": {
1734+
"type": "string",
1735+
"xml": {
1736+
"name": "hreflang",
1737+
"attribute": true,
1738+
"wrapped": false
1739+
}
1740+
},
1741+
"media": {
1742+
"type": "string",
1743+
"xml": {
1744+
"name": "media",
1745+
"attribute": true,
1746+
"wrapped": false
1747+
}
1748+
},
1749+
"rel": {
1750+
"type": "string",
1751+
"xml": {
1752+
"name": "rel",
1753+
"attribute": true,
1754+
"wrapped": false
1755+
}
1756+
},
1757+
"templated": {
1758+
"type": "boolean"
1759+
},
1760+
"title": {
1761+
"type": "string",
1762+
"xml": {
1763+
"name": "title",
1764+
"attribute": true,
1765+
"wrapped": false
1766+
}
1767+
},
1768+
"type": {
1769+
"type": "string",
1770+
"xml": {
1771+
"name": "type",
1772+
"attribute": true,
1773+
"wrapped": false
1774+
}
17151775
}
17161776
},
1717-
"title": "Link",
1718-
"description": "Links"
1777+
"title": "Link"
17191778
},
17201779
"Person": {
17211780
"type": "object",
@@ -1869,7 +1928,6 @@
18691928
],
18701929
"properties": {
18711930
"_embedded": {
1872-
"description": "Resource collection",
18731931
"$ref": "#/definitions/EmbeddedCollectionOfAddress"
18741932
},
18751933
"_links": {
@@ -1881,7 +1939,12 @@
18811939
}
18821940
},
18831941
"title": "ResourcesOfAddress",
1884-
"description": "Resources of Address"
1942+
"description": "Resources of Address",
1943+
"xml": {
1944+
"name": "entities",
1945+
"attribute": false,
1946+
"wrapped": false
1947+
}
18851948
},
18861949
"ResourcesOfPerson": {
18871950
"type": "object",
@@ -1891,7 +1954,6 @@
18911954
],
18921955
"properties": {
18931956
"_embedded": {
1894-
"description": "Resource collection",
18951957
"$ref": "#/definitions/EmbeddedCollectionOfPerson"
18961958
},
18971959
"_links": {
@@ -1913,7 +1975,6 @@
19131975
],
19141976
"properties": {
19151977
"_embedded": {
1916-
"description": "Resource collection",
19171978
"$ref": "#/definitions/EmbeddedCollectionOfTag"
19181979
},
19191980
"_links": {
@@ -1925,7 +1986,12 @@
19251986
}
19261987
},
19271988
"title": "ResourcesOfTag",
1928-
"description": "Resources of Tag"
1989+
"description": "Resources of Tag",
1990+
"xml": {
1991+
"name": "entities",
1992+
"attribute": false,
1993+
"wrapped": false
1994+
}
19291995
},
19301996
"Tag": {
19311997
"type": "object",

0 commit comments

Comments
 (0)