Skip to content

Commit deab753

Browse files
committed
improved grouping
1 parent 12d17ef commit deab753

2 files changed

Lines changed: 115 additions & 87 deletions

File tree

src/test/groovy/com/github/hauner/openapi/spring/converter/DataTypeConverterTypeMappingSpec.groovy renamed to src/test/groovy/com/github/hauner/openapi/spring/converter/DataTypeConverterResponseTypeMappingSpec.groovy

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import spock.lang.Unroll
2828
import static com.github.hauner.openapi.spring.support.OpenApiParser.parse
2929

3030

31-
class DataTypeConverterTypeMappingSpec extends Specification {
31+
class DataTypeConverterResponseTypeMappingSpec extends Specification {
3232

3333
@Unroll
3434
void "converts simple array schema to #responseTypeName set via global array mapping" () {
@@ -182,90 +182,4 @@ paths:
182182
ep.response.responseType.name == 'TargetClass'
183183
}
184184

185-
void "converts named schemas to java type via global type mapping" () {
186-
def openApi = parse ("""\
187-
openapi: 3.0.2
188-
info:
189-
title: API
190-
version: 1.0.0
191-
192-
paths:
193-
/page:
194-
get:
195-
parameters:
196-
- in: query
197-
name: pageable
198-
required: false
199-
schema:
200-
\$ref: '#/components/schemas/Pageable'
201-
responses:
202-
'200':
203-
description: none
204-
content:
205-
application/json:
206-
schema:
207-
\$ref: '#/components/schemas/StringPage'
208-
209-
components:
210-
schemas:
211-
212-
Pageable:
213-
description: minimal Pageable query parameters
214-
type: object
215-
properties:
216-
page:
217-
type: integer
218-
size:
219-
type: integer
220-
221-
Page:
222-
description: minimal Page response without content property
223-
type: object
224-
properties:
225-
number:
226-
type: integer
227-
size:
228-
type: integer
229-
230-
StringContent:
231-
description: specific content List of the Page response
232-
type: object
233-
properties:
234-
content:
235-
type: array
236-
items:
237-
type: string
238-
239-
StringPage:
240-
description: typed Page
241-
type: object
242-
allOf:
243-
- \$ref: '#/components/schemas/Page'
244-
- \$ref: '#/components/schemas/StringContent'
245-
""")
246-
247-
when:
248-
def options = new ApiOptions(
249-
packageName: 'pkg',
250-
typeMappings: [
251-
new TypeMapping (
252-
sourceTypeName: 'Pageable',
253-
targetTypeName: 'org.springframework.data.domain.Pageable'),
254-
new TypeMapping (
255-
sourceTypeName: 'StringPage',
256-
targetTypeName: 'org.springframework.data.domain.Page<String>')
257-
])
258-
Api api = new ApiConverter (options).convert (openApi)
259-
260-
then:
261-
def itf = api.interfaces.first ()
262-
def ep = itf.endpoints.first ()
263-
def parameter = ep.parameters.first ()
264-
def response = ep.response
265-
parameter.dataType.pkg == 'org.springframework.data.domain'
266-
parameter.dataType.name == 'Pageable'
267-
response.responseType.pkg == 'org.springframework.data.domain'
268-
response.responseType.name == 'Page<String>'
269-
}
270-
271185
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2019 the original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.hauner.openapi.spring.converter
18+
19+
import com.github.hauner.openapi.spring.generatr.ApiOptions
20+
import com.github.hauner.openapi.spring.generatr.mapping.TypeMapping
21+
import com.github.hauner.openapi.spring.model.Api
22+
import spock.lang.Specification
23+
24+
import static com.github.hauner.openapi.spring.support.OpenApiParser.parse
25+
26+
class DataTypesConverterGlobalTypeMappingSpec extends Specification {
27+
28+
void "converts named schemas to java type via global type mapping" () {
29+
def openApi = parse ("""\
30+
openapi: 3.0.2
31+
info:
32+
title: API
33+
version: 1.0.0
34+
35+
paths:
36+
/page:
37+
get:
38+
parameters:
39+
- in: query
40+
name: pageable
41+
required: false
42+
schema:
43+
\$ref: '#/components/schemas/Pageable'
44+
responses:
45+
'200':
46+
description: none
47+
content:
48+
application/json:
49+
schema:
50+
\$ref: '#/components/schemas/StringPage'
51+
52+
components:
53+
schemas:
54+
55+
Pageable:
56+
description: minimal Pageable query parameters
57+
type: object
58+
properties:
59+
page:
60+
type: integer
61+
size:
62+
type: integer
63+
64+
Page:
65+
description: minimal Page response without content property
66+
type: object
67+
properties:
68+
number:
69+
type: integer
70+
size:
71+
type: integer
72+
73+
StringContent:
74+
description: specific content List of the Page response
75+
type: object
76+
properties:
77+
content:
78+
type: array
79+
items:
80+
type: string
81+
82+
StringPage:
83+
description: typed Page
84+
type: object
85+
allOf:
86+
- \$ref: '#/components/schemas/Page'
87+
- \$ref: '#/components/schemas/StringContent'
88+
""")
89+
90+
when:
91+
def options = new ApiOptions(
92+
packageName: 'pkg',
93+
typeMappings: [
94+
new TypeMapping (
95+
sourceTypeName: 'Pageable',
96+
targetTypeName: 'org.springframework.data.domain.Pageable'),
97+
new TypeMapping (
98+
sourceTypeName: 'StringPage',
99+
targetTypeName: 'org.springframework.data.domain.Page<String>')
100+
])
101+
Api api = new ApiConverter (options).convert (openApi)
102+
103+
then:
104+
def itf = api.interfaces.first ()
105+
def ep = itf.endpoints.first ()
106+
def parameter = ep.parameters.first ()
107+
def response = ep.response
108+
parameter.dataType.pkg == 'org.springframework.data.domain'
109+
parameter.dataType.name == 'Pageable'
110+
response.responseType.pkg == 'org.springframework.data.domain'
111+
response.responseType.name == 'Page<String>'
112+
}
113+
114+
}

0 commit comments

Comments
 (0)