Skip to content

Commit 2d38d13

Browse files
committed
Fixed id parameter not showing up and removed format
(10)
1 parent b610d01 commit 2d38d13

15 files changed

+107
-24
lines changed

springfox-grails-contract-tests/src/integration-test/groovy/grails/springfox/sample/SpringFoxSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SpringFoxSpec extends Specification implements FileAccess {
1515
@LocalServerPort
1616
private int port
1717

18-
void "test something"() {
18+
void "Contract tests for the api documentation"() {
1919
given:
2020
def expected = fileContents("/expected-service-description.json")
2121
def actual = get("http://localhost:$port/v2/api-docs").asString()

springfox-grails-contract-tests/src/integration-test/resources/expected-service-description.json

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
}
4747
],
4848
"paths": {
49-
"/album.{format}": {
49+
"/album": {
5050
"get": {
5151
"tags": [
5252
"album"
@@ -244,7 +244,7 @@
244244
}
245245
}
246246
},
247-
"/album/{id}.{format}": {
247+
"/album/{id}": {
248248
"get": {
249249
"tags": [
250250
"album"
@@ -259,6 +259,16 @@
259259
"application/xml",
260260
"application/json"
261261
],
262+
"parameters": [
263+
{
264+
"name": "id",
265+
"in": "path",
266+
"description": "id",
267+
"required": true,
268+
"type": "integer",
269+
"format": "int64"
270+
}
271+
],
262272
"responses": {
263273
"200": {
264274
"description": "OK",
@@ -460,7 +470,7 @@
460470
}
461471
}
462472
},
463-
"/artist.{format}": {
473+
"/artist": {
464474
"get": {
465475
"tags": [
466476
"artist"
@@ -658,7 +668,7 @@
658668
}
659669
}
660670
},
661-
"/artist/{id}.{format}": {
671+
"/artist/{id}": {
662672
"get": {
663673
"tags": [
664674
"artist"
@@ -673,6 +683,16 @@
673683
"application/xml",
674684
"application/json"
675685
],
686+
"parameters": [
687+
{
688+
"name": "id",
689+
"in": "path",
690+
"description": "id",
691+
"required": true,
692+
"type": "integer",
693+
"format": "int64"
694+
}
695+
],
676696
"responses": {
677697
"200": {
678698
"description": "OK",
@@ -839,7 +859,7 @@
839859
}
840860
}
841861
},
842-
"/book.{format}": {
862+
"/book": {
843863
"post": {
844864
"tags": [
845865
"book"
@@ -956,7 +976,7 @@
956976
}
957977
}
958978
},
959-
"/book/{id}.{format}": {
979+
"/book/{id}": {
960980
"put": {
961981
"tags": [
962982
"book"
@@ -970,6 +990,16 @@
970990
"produces": [
971991
"application/json"
972992
],
993+
"parameters": [
994+
{
995+
"name": "id",
996+
"in": "path",
997+
"description": "id",
998+
"required": true,
999+
"type": "integer",
1000+
"format": "int64"
1001+
}
1002+
],
9731003
"responses": {
9741004
"200": {
9751005
"description": "OK",
@@ -1033,7 +1063,7 @@
10331063
}
10341064
}
10351065
},
1036-
"/genre.{format}": {
1066+
"/genre": {
10371067
"get": {
10381068
"tags": [
10391069
"genre"
@@ -1231,7 +1261,7 @@
12311261
}
12321262
}
12331263
},
1234-
"/genre/{id}.{format}": {
1264+
"/genre/{id}": {
12351265
"get": {
12361266
"tags": [
12371267
"genre"
@@ -1246,6 +1276,16 @@
12461276
"application/xml",
12471277
"application/json"
12481278
],
1279+
"parameters": [
1280+
{
1281+
"name": "id",
1282+
"in": "path",
1283+
"description": "id",
1284+
"required": true,
1285+
"type": "integer",
1286+
"format": "int64"
1287+
}
1288+
],
12491289
"responses": {
12501290
"200": {
12511291
"description": "OK",
@@ -1412,7 +1452,7 @@
14121452
}
14131453
}
14141454
},
1415-
"/label.{format}": {
1455+
"/label": {
14161456
"get": {
14171457
"tags": [
14181458
"label"
@@ -1610,7 +1650,7 @@
16101650
}
16111651
}
16121652
},
1613-
"/label/{id}.{format}": {
1653+
"/label/{id}": {
16141654
"get": {
16151655
"tags": [
16161656
"label"
@@ -1625,6 +1665,16 @@
16251665
"application/xml",
16261666
"application/json"
16271667
],
1668+
"parameters": [
1669+
{
1670+
"name": "id",
1671+
"in": "path",
1672+
"description": "id",
1673+
"required": true,
1674+
"type": "integer",
1675+
"format": "int64"
1676+
}
1677+
],
16281678
"responses": {
16291679
"200": {
16301680
"description": "OK",
@@ -1791,7 +1841,7 @@
17911841
}
17921842
}
17931843
},
1794-
"/song.{format}": {
1844+
"/song": {
17951845
"get": {
17961846
"tags": [
17971847
"song"
@@ -1989,7 +2039,7 @@
19892039
}
19902040
}
19912041
},
1992-
"/song/{id}.{format}": {
2042+
"/song/{id}": {
19932043
"get": {
19942044
"tags": [
19952045
"song"
@@ -2004,6 +2054,16 @@
20042054
"application/xml",
20052055
"application/json"
20062056
],
2057+
"parameters": [
2058+
{
2059+
"name": "id",
2060+
"in": "path",
2061+
"description": "id",
2062+
"required": true,
2063+
"type": "integer",
2064+
"format": "int64"
2065+
}
2066+
],
20072067
"responses": {
20082068
"200": {
20092069
"description": "OK",

springfox-grails/src/main/java/springfox/documentation/grails/GrailsActionAttributes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public Set<RequestMethod> httpMethod(GrailsActionContext context) {
6565
public boolean isRestfulAction(String action) {
6666
return methodMap.containsKey(action);
6767
}
68+
6869
public Optional<UrlMapping> urlMapping(Predicate<UrlMapping> selector) {
6970
return Arrays.stream(urlMappings.getUrlMappings())
7071
.filter(selector)
@@ -79,6 +80,7 @@ public String actionUrl(GrailsActionContext context, UrlMapping mapping) {
7980
"UTF-8")
8081
.replace("%7B", "{").replace("%7D", "}")
8182
.replace(linkGenerator.getServerBaseURL(), "")
83+
.replace(".{format}", "")
8284
.toLowerCase();
8385
}
8486

springfox-grails/src/main/java/springfox/documentation/grails/IndexActionSpecificationFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public ActionSpecification create(GrailsActionContext context) {
3232

3333
private List<ResolvedMethodParameter> parameters(Set<MediaType> mediaTypes) {
3434
List<ResolvedMethodParameter> parameters = newArrayList(queryParameter(
35-
1,
35+
0,
3636
"max",
3737
resolver.resolve(Integer.class),
3838
false,
3939
""));
4040
if (mediaTypes.size() > 1) {
4141
parameters.add(pathParameter(
42-
2,
42+
1,
4343
"format",
4444
resolver.resolve(String.class)));
4545
}

springfox-grails/src/main/java/springfox/documentation/grails/UrlMappings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static ResolvedType resolvedPropertyType(
8080
}
8181

8282
private static Predicate<ConstrainedProperty> domainProperties(GrailsDomainClass domain) {
83-
return c -> domain.hasPersistentProperty(c.getPropertyName());
83+
return c -> domain.hasProperty(c.getPropertyName());
8484
}
8585

8686
private static boolean httpMethodMatches(String methodName, UrlMapping urlMapping) {

springfox-grails/src/test/groovy/springfox/documentation/grails/ActionSpecificationFactorySpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ActionSpecificationFactorySpec extends Specification implements UrlMapping
4545
def mockDomain() {
4646
def domain = Mock(GrailsDomainClass)
4747
domain.clazz >> ADomain
48-
domain.hasPersistentProperty("id") >> true
48+
domain.hasProperty("id") >> true
4949
def id = idProperty()
5050
domain.getPropertyByName("id") >> id
5151
domain.identifier >> id

springfox-grails/src/test/groovy/springfox/documentation/grails/DeleteActionSpecificationFactorySpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DeleteActionSpecificationFactorySpec extends ActionSpecificationFactorySpe
1818
spec.produces == [MediaType.APPLICATION_JSON] as Set
1919
spec.supportedMethods == [RequestMethod.DELETE] as Set
2020
spec.handlerMethod.method == AController.methods.find {it.name == "delete" }
21-
spec.path == "/a/{id}.{format}"
21+
spec.path == "/a/{id}"
2222

2323
and: "Parameters match"
2424
spec.parameters.size() == 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package springfox.documentation.grails
2+
3+
import spock.lang.Specification
4+
5+
6+
class GrailsActionContextSpec extends Specification {
7+
}

springfox-grails/src/test/groovy/springfox/documentation/grails/IndexActionSpecificationFactorySpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class IndexActionSpecificationFactorySpec extends ActionSpecificationFactorySpec
1818
spec.produces == [MediaType.APPLICATION_JSON] as Set
1919
spec.supportedMethods == [RequestMethod.GET] as Set
2020
spec.handlerMethod.method == RestfulController.declaredMethods.find {it.name == "index" }
21-
spec.path == "/a.{format}"
21+
spec.path == "/a"
2222

2323
and: "Parameters match"
2424
spec.parameters.size() == 1
2525
spec.parameters[0].parameterType == resolver.resolve(Integer)
26-
spec.parameters[0].parameterIndex == 1
26+
spec.parameters[0].parameterIndex == 0
2727
spec.parameters[0].defaultName().isPresent()
2828
spec.parameters[0].defaultName().get() == "max"
2929

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package springfox.documentation.grails
2+
3+
import spock.lang.Specification
4+
5+
6+
class ParametersSpec extends Specification {
7+
}

0 commit comments

Comments
 (0)