Skip to content

Commit a66bcd5

Browse files
committed
Updated the test to use the ignorable types as a parameter to model context
(1196)
1 parent bcd41d4 commit a66bcd5

File tree

26 files changed

+818
-266
lines changed

26 files changed

+818
-266
lines changed

springfox-schema/src/test/groovy/springfox/documentation/schema/BeanWithFactoryMethodSpec.groovy

Lines changed: 95 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1+
/*
2+
*
3+
* Copyright 2015-2016 the original author or authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*
18+
*/
119
package springfox.documentation.schema
20+
21+
import com.google.common.collect.ImmutableSet
222
import springfox.documentation.schema.mixins.ModelProviderSupport
323
import springfox.documentation.schema.mixins.TypesForTestingSupport
424

@@ -8,27 +28,35 @@ import static springfox.documentation.spi.schema.contexts.ModelContext.*
828
class BeanWithFactoryMethodSpec extends SchemaSpecification {
929
def "Type with bean properties in the constructor" () {
1030
given:
11-
def sut = defaultModelProvider()
12-
def typeToTest = typeWithConstructorProperties()
13-
def reqContext = inputParam(typeToTest, documentationType, alternateTypeProvider(), new
14-
DefaultGenericTypeNamingStrategy())
15-
def resContext = returnValue(typeToTest, documentationType, alternateTypeProvider(), new
16-
DefaultGenericTypeNamingStrategy())
31+
def sut = defaultModelProvider()
32+
def typeToTest = typeWithConstructorProperties()
33+
def reqContext = inputParam(
34+
typeToTest,
35+
documentationType,
36+
alternateTypeProvider(),
37+
new DefaultGenericTypeNamingStrategy(),
38+
ImmutableSet.builder().build())
39+
def resContext = returnValue(
40+
typeToTest,
41+
documentationType,
42+
alternateTypeProvider(),
43+
new DefaultGenericTypeNamingStrategy(),
44+
ImmutableSet.builder().build())
1745

1846
when:
19-
def models = [sut.modelFor(reqContext).get(), sut.modelFor(resContext).get()]
47+
def models = [sut.modelFor(reqContext).get(), sut.modelFor(resContext).get()]
2048

2149
then:
22-
models.each {
23-
it.properties.size() == 2
24-
it.properties.containsKey(fieldName)
25-
it.properties."$fieldName".description == description
26-
it.properties."$fieldName".required == isRequired
27-
it.properties."$fieldName".type.erasedType == type
28-
it.properties."$fieldName".qualifiedType == qualifiedTypeName
29-
it.properties."$fieldName".allowableValues == allowableValues
30-
true
31-
}
50+
models.each {
51+
it.properties.size() == 2
52+
it.properties.containsKey(fieldName)
53+
it.properties."$fieldName".description == description
54+
it.properties."$fieldName".required == isRequired
55+
it.properties."$fieldName".type.erasedType == type
56+
it.properties."$fieldName".qualifiedType == qualifiedTypeName
57+
it.properties."$fieldName".allowableValues == allowableValues
58+
true
59+
}
3260

3361
where:
3462
fieldName || description | isRequired | type | qualifiedTypeName | allowableValues
@@ -38,27 +66,35 @@ class BeanWithFactoryMethodSpec extends SchemaSpecification {
3866

3967
def "Type with delegated constructor (factory method)" () {
4068
given:
41-
def sut = defaultModelProvider()
42-
def typeToTest = typeWithDelegatedConstructor()
43-
def reqContext = inputParam(typeToTest, documentationType, alternateTypeProvider(), new
44-
DefaultGenericTypeNamingStrategy())
45-
def resContext = returnValue(typeToTest, documentationType, alternateTypeProvider(), new
46-
DefaultGenericTypeNamingStrategy())
69+
def sut = defaultModelProvider()
70+
def typeToTest = typeWithDelegatedConstructor()
71+
def reqContext = inputParam(
72+
typeToTest,
73+
documentationType,
74+
alternateTypeProvider(),
75+
new DefaultGenericTypeNamingStrategy(),
76+
ImmutableSet.builder().build())
77+
def resContext = returnValue(
78+
typeToTest,
79+
documentationType,
80+
alternateTypeProvider(),
81+
new DefaultGenericTypeNamingStrategy(),
82+
ImmutableSet.builder().build())
4783
4884
when:
49-
def models = [sut.modelFor(reqContext).get(), sut.modelFor(resContext).get()]
85+
def models = [sut.modelFor(reqContext).get(), sut.modelFor(resContext).get()]
5086
5187
then:
52-
models.each {
53-
it.properties.size() == 2
54-
it.properties.containsKey(fieldName)
55-
it.properties."$fieldName".description == description
56-
it.properties."$fieldName".required == isRequired
57-
it.properties."$fieldName".type.erasedType == type
58-
it.properties."$fieldName".qualifiedType == qualifiedTypeName
59-
it.properties."$fieldName".allowableValues == allowableValues
60-
true
61-
}
88+
models.each {
89+
it.properties.size() == 2
90+
it.properties.containsKey(fieldName)
91+
it.properties."$fieldName".description == description
92+
it.properties."$fieldName".required == isRequired
93+
it.properties."$fieldName".type.erasedType == type
94+
it.properties."$fieldName".qualifiedType == qualifiedTypeName
95+
it.properties."$fieldName".allowableValues == allowableValues
96+
true
97+
}
6298
6399
where:
64100
fieldName || description | isRequired | type | qualifiedTypeName | allowableValues
@@ -68,27 +104,35 @@ class BeanWithFactoryMethodSpec extends SchemaSpecification {
68104
69105
def "Type with @JsonCreator marked constructor" () {
70106
given:
71-
def sut = defaultModelProvider()
72-
def typeToTest = typeWithDelegatedConstructor()
73-
def reqContext = inputParam(typeToTest, documentationType, alternateTypeProvider(), new
74-
DefaultGenericTypeNamingStrategy())
75-
def resContext = returnValue(typeToTest, documentationType, alternateTypeProvider(), new
76-
DefaultGenericTypeNamingStrategy())
107+
def sut = defaultModelProvider()
108+
def typeToTest = typeWithDelegatedConstructor()
109+
def reqContext = inputParam(
110+
typeToTest,
111+
documentationType,
112+
alternateTypeProvider(),
113+
new DefaultGenericTypeNamingStrategy(),
114+
ImmutableSet.builder().build())
115+
def resContext = returnValue(
116+
typeToTest,
117+
documentationType,
118+
alternateTypeProvider(),
119+
new DefaultGenericTypeNamingStrategy(),
120+
ImmutableSet.builder().build())
77121
78122
when:
79-
def models = [sut.modelFor(reqContext).get(), sut.modelFor(resContext).get()]
123+
def models = [sut.modelFor(reqContext).get(), sut.modelFor(resContext).get()]
80124
81125
then:
82-
models.each {
83-
it.properties.size() == 2
84-
it.properties.containsKey(fieldName)
85-
it.properties."$fieldName".description == description
86-
it.properties."$fieldName".required == isRequired
87-
it.properties."$fieldName".type.erasedType == type
88-
it.properties."$fieldName".qualifiedType == qualifiedTypeName
89-
it.properties."$fieldName".allowableValues == allowableValues
90-
true
91-
}
126+
models.each {
127+
it.properties.size() == 2
128+
it.properties.containsKey(fieldName)
129+
it.properties."$fieldName".description == description
130+
it.properties."$fieldName".required == isRequired
131+
it.properties."$fieldName".type.erasedType == type
132+
it.properties."$fieldName".qualifiedType == qualifiedTypeName
133+
it.properties."$fieldName".allowableValues == allowableValues
134+
true
135+
}
92136
93137
where:
94138
fieldName || description | isRequired | type | qualifiedTypeName | allowableValues

springfox-schema/src/test/groovy/springfox/documentation/schema/CachingModelDependencyProviderSpec.groovy

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright 2015 the original author or authors.
3+
* Copyright 2015-2016 the original author or authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
package springfox.documentation.schema
2020

2121
import com.fasterxml.classmate.TypeResolver
22+
import com.google.common.collect.ImmutableSet
2223
import spock.lang.Specification
2324
import springfox.documentation.schema.mixins.TypesForTestingSupport
2425
import springfox.documentation.spi.DocumentationType
@@ -32,10 +33,11 @@ class CachingModelDependencyProviderSpec extends Specification {
3233
def "Implementation caches the invocations" () {
3334
given:
3435
def context = inputParam(
35-
complexType(),
36-
DocumentationType.SWAGGER_2,
37-
new AlternateTypeProvider([]),
38-
new CodeGenGenericTypeNamingStrategy())
36+
complexType(),
37+
DocumentationType.SWAGGER_2,
38+
new AlternateTypeProvider([]),
39+
new CodeGenGenericTypeNamingStrategy(),
40+
ImmutableSet.builder().build())
3941
def mock = Mock(ModelDependencyProvider) {
4042
dependentModels(context) >> newHashSet(aResolvedType())
4143
}
@@ -51,7 +53,8 @@ class CachingModelDependencyProviderSpec extends Specification {
5153
complexType(),
5254
DocumentationType.SWAGGER_2,
5355
new AlternateTypeProvider([]),
54-
new CodeGenGenericTypeNamingStrategy())
56+
new CodeGenGenericTypeNamingStrategy(),
57+
ImmutableSet.builder().build())
5558
def mock = Mock(ModelDependencyProvider) {
5659
dependentModels(context) >> { throw new NullPointerException() }
5760
}

springfox-schema/src/test/groovy/springfox/documentation/schema/CachingModelProviderSpec.groovy

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright 2015 the original author or authors.
3+
* Copyright 2015-2016 the original author or authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
package springfox.documentation.schema
2020

2121
import com.google.common.base.Optional
22+
import com.google.common.collect.ImmutableSet
2223
import spock.lang.Specification
2324
import springfox.documentation.schema.mixins.TypesForTestingSupport
2425
import springfox.documentation.spi.DocumentationType
@@ -31,10 +32,11 @@ class CachingModelProviderSpec extends Specification {
3132
def "Implementation caches the invocations" () {
3233
given:
3334
def context = inputParam(
34-
complexType(),
35-
DocumentationType.SWAGGER_2,
36-
new AlternateTypeProvider([]),
37-
new CodeGenGenericTypeNamingStrategy())
35+
complexType(),
36+
DocumentationType.SWAGGER_2,
37+
new AlternateTypeProvider([]),
38+
new CodeGenGenericTypeNamingStrategy(),
39+
ImmutableSet.builder().build())
3840
def model = aModel()
3941
def mock = Mock(ModelProvider) {
4042
modelFor(context) >> Optional.of(model)
@@ -51,7 +53,8 @@ class CachingModelProviderSpec extends Specification {
5153
complexType(),
5254
DocumentationType.SWAGGER_2,
5355
new AlternateTypeProvider([]),
54-
new CodeGenGenericTypeNamingStrategy())
56+
new CodeGenGenericTypeNamingStrategy(),
57+
ImmutableSet.builder().build())
5558
def mock = Mock(ModelProvider) {
5659
modelFor(context) >> { throw new NullPointerException() }
5760
}

springfox-schema/src/test/groovy/springfox/documentation/schema/ComplexTypeSpec.groovy

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright 2015 the original author or authors.
3+
* Copyright 2015-2016 the original author or authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919

2020
package springfox.documentation.schema
2121

22+
import com.google.common.collect.ImmutableSet
2223
import spock.lang.Shared
2324
import spock.lang.Specification
2425
import springfox.documentation.schema.mixins.ModelProviderSupport
@@ -35,8 +36,18 @@ class ComplexTypeSpec extends Specification {
3536
def "complex type properties are inferred correctly"() {
3637
given:
3738
def provider = defaultModelProvider()
38-
Model asInput = provider.modelFor(inputParam(complexType(), SWAGGER_12, alternateTypeProvider(), namingStrategy)).get()
39-
Model asReturn = provider.modelFor(returnValue(complexType(), SWAGGER_12, alternateTypeProvider(), namingStrategy)).get()
39+
Model asInput = provider.modelFor(inputParam(
40+
complexType(),
41+
SWAGGER_12,
42+
alternateTypeProvider(),
43+
namingStrategy,
44+
ImmutableSet.builder().build())).get()
45+
Model asReturn = provider.modelFor(returnValue(
46+
complexType(),
47+
SWAGGER_12,
48+
alternateTypeProvider(),
49+
namingStrategy,
50+
ImmutableSet.builder().build())).get()
4051

4152
expect:
4253
asInput.getName() == "ComplexType"
@@ -69,8 +80,18 @@ class ComplexTypeSpec extends Specification {
6980
given:
7081
def complexType = recursiveType()
7182
def provider = defaultModelProvider()
72-
Model asInput = provider.modelFor(inputParam(complexType, SWAGGER_12, alternateTypeProvider(), namingStrategy)).get()
73-
Model asReturn = provider.modelFor(returnValue(complexType, SWAGGER_12, alternateTypeProvider(), namingStrategy)).get()
83+
Model asInput = provider.modelFor(inputParam(
84+
complexType,
85+
SWAGGER_12,
86+
alternateTypeProvider(),
87+
namingStrategy,
88+
ImmutableSet.builder().build())).get()
89+
Model asReturn = provider.modelFor(returnValue(
90+
complexType,
91+
SWAGGER_12,
92+
alternateTypeProvider(),
93+
namingStrategy,
94+
ImmutableSet.builder().build())).get()
7495

7596
expect:
7697
asInput.getName() == "RecursiveType"
@@ -100,8 +121,18 @@ class ComplexTypeSpec extends Specification {
100121
given:
101122
def complexType = inheritedComplexType()
102123
def provider = defaultModelProvider()
103-
Model asInput = provider.modelFor(inputParam(complexType, SWAGGER_12, alternateTypeProvider(), namingStrategy)).get()
104-
Model asReturn = provider.modelFor(returnValue(complexType, SWAGGER_12, alternateTypeProvider(), namingStrategy)).get()
124+
Model asInput = provider.modelFor(inputParam(
125+
complexType,
126+
SWAGGER_12,
127+
alternateTypeProvider(),
128+
namingStrategy,
129+
ImmutableSet.builder().build())).get()
130+
Model asReturn = provider.modelFor(returnValue(
131+
complexType,
132+
SWAGGER_12,
133+
alternateTypeProvider(),
134+
namingStrategy,
135+
ImmutableSet.builder().build())).get()
105136

106137
expect:
107138
asInput.getName() == "InheritedComplexType"

0 commit comments

Comments
 (0)