Skip to content

Commit 1f9cd34

Browse files
authored
Merge pull request #38 from hauner/#37
resolves #37
2 parents cc6a4d1 + 7423f5e commit 1f9cd34

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

src/main/groovy/com/github/hauner/openapi/spring/converter/DataTypeConverter.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ class DataTypeConverter {
263263
)
264264
}
265265
}
266+
267+
// check global parameter mapping
268+
List<ParameterTypeMapping> parameters = getParameterMappings (options.typeMappings)
269+
def parameter = parameters.find { it.parameterName == pn && it.mapping.sourceTypeName == 'object' }
270+
if (parameter) {
271+
return new TargetType (
272+
typeName: parameter.mapping.targetTypeName,
273+
genericNames: parameter.mapping.genericTypeNames
274+
)
275+
}
266276
}
267277

268278
// check global mapping

src/test/groovy/com/github/hauner/openapi/spring/converter/DataTypeConverterParameterTypeMappingSpec.groovy

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import com.github.hauner.openapi.spring.converter.mapping.ParameterTypeMapping
2121
import com.github.hauner.openapi.spring.converter.mapping.TypeMapping
2222
import com.github.hauner.openapi.spring.model.Api
2323
import spock.lang.Specification
24+
import spock.lang.Unroll
2425

2526
import static com.github.hauner.openapi.spring.support.OpenApiParser.parse
2627

2728
class DataTypeConverterParameterTypeMappingSpec extends Specification {
2829

29-
void "converts object parameter schema to java type via endpoint mapping" () {
30+
@Unroll
31+
void "converts object parameter schema to java type via #type" () {
3032
def openApi = parse ("""\
3133
openapi: 3.0.2
3234
info:
@@ -53,25 +55,40 @@ paths:
5355
""")
5456

5557
when:
56-
def options = new ApiOptions(
57-
packageName: 'pkg',
58-
typeMappings: [
59-
new EndpointTypeMapping (path: '/foobar',
60-
typeMappings: [
61-
new ParameterTypeMapping (
62-
parameterName: 'foobar',
63-
mapping: new TypeMapping(
64-
sourceTypeName: 'object',
65-
targetTypeName: 'pkg.TargetClass')
66-
)
67-
])
68-
])
58+
def options = new ApiOptions(packageName: 'pkg', typeMappings: mappings)
6959
Api api = new ApiConverter (options).convert (openApi)
7060

7161
then:
7262
def itf = api.interfaces.first ()
7363
def ep = itf.endpoints.first ()
7464
ep.parameters.first ().dataType.name == 'TargetClass'
65+
66+
where:
67+
type << [
68+
'endpoint parameter mapping',
69+
'global parameter mapping'
70+
]
71+
72+
mappings << [
73+
[
74+
new EndpointTypeMapping (path: '/foobar',
75+
typeMappings: [
76+
new ParameterTypeMapping (
77+
parameterName: 'foobar',
78+
mapping: new TypeMapping (
79+
sourceTypeName: 'object',
80+
targetTypeName: 'pkg.TargetClass')
81+
)
82+
])
83+
], [
84+
new ParameterTypeMapping (
85+
parameterName: 'foobar',
86+
mapping: new TypeMapping (
87+
sourceTypeName: 'object',
88+
targetTypeName: 'pkg.TargetClass')
89+
)
90+
]
91+
]
7592
}
7693

7794
}

0 commit comments

Comments
 (0)