Skip to content

Commit db775ce

Browse files
committed
Merge branch 'master' into antora
Conflicts: README.md
2 parents 19f4ad0 + 8bcc7f6 commit db775ce

File tree

68 files changed

+1781
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1781
-440
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ See [here][oap-docs].
2020
[workflow-ci]: https://github.com/hauner/openapi-processor-json/actions?query=workflow%3Aci
2121
[oap-docs]: https://hauner.github.com/openapi-processor/spring/current/index.html
2222
[openapi]: https://www.openapis.org/
23+
[springboot]: https://spring.io/projects/spring-boot

build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
2+
id 'jacoco'
23
id 'groovy'
34
id 'java-library'
45
id 'maven-publish'
@@ -79,6 +80,21 @@ dependencies {
7980
// testIntRuntimeOnly 'org.slf4j:slf4j-nop:1.6.1'
8081
}
8182

83+
84+
tasks.withType(Test) {
85+
finalizedBy jacocoTestReport
86+
}
87+
88+
89+
jacoco {
90+
toolVersion = "0.8.5"
91+
}
92+
93+
project.jacocoTestReport {
94+
getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec"))
95+
}
96+
97+
8298
task sourcesJar(type: Jar, dependsOn: classes) {
8399
archiveClassifier.set ('sources')
84100
from sourceSets.main.allSource
@@ -103,6 +119,7 @@ dokka {
103119
outputDirectory = "$buildDir/docs/kotlin"
104120
}
105121

122+
106123
bintray {
107124
user = bintrayUser
108125
key = bintrayKey
@@ -121,6 +138,7 @@ bintray {
121138
}
122139
}
123140

141+
124142
publishing {
125143
publications {
126144
processor (MavenPublication) {

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

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@
1717
package com.github.hauner.openapi.spring.converter
1818

1919
import com.github.hauner.openapi.spring.converter.mapping.AddParameterTypeMapping
20-
import com.github.hauner.openapi.spring.converter.mapping.AmbiguousTypeMappingException
21-
import com.github.hauner.openapi.spring.converter.mapping.EndpointTypeMapping
2220
import com.github.hauner.openapi.spring.converter.mapping.Mapping
23-
import com.github.hauner.openapi.spring.converter.mapping.MappingSchema
2421
import com.github.hauner.openapi.spring.converter.mapping.TargetType
2522
import com.github.hauner.openapi.spring.converter.mapping.TypeMapping
26-
import com.github.hauner.openapi.spring.converter.schema.SchemaInfo
2723
import com.github.hauner.openapi.spring.model.Api
2824
import com.github.hauner.openapi.spring.model.DataTypes
2925
import com.github.hauner.openapi.spring.model.Endpoint
3026
import com.github.hauner.openapi.spring.model.Interface
3127
import com.github.hauner.openapi.spring.model.RequestBody as ModelRequestBody
3228
import com.github.hauner.openapi.spring.model.datatypes.MappedDataType
29+
import com.github.hauner.openapi.spring.model.datatypes.NoneDataType
3330
import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
3431
import com.github.hauner.openapi.spring.model.parameters.AdditionalParameter
3532
import com.github.hauner.openapi.spring.model.parameters.CookieParameter
@@ -63,27 +60,12 @@ class ApiConverter {
6360
public static final String INTERFACE_DEFAULT_NAME = ''
6461

6562
private DataTypeConverter dataTypeConverter
63+
private ResultDataTypeWrapper dataTypeWrapper
64+
private SingleDataTypeWrapper singleDataTypeWrapper
65+
private MultiDataTypeWrapper multiDataTypeWrapper
66+
private MappingFinder mappingFinder
6667
private ApiOptions options
6768

68-
class MappingSchemaEndpoint implements MappingSchema {
69-
String path
70-
71-
@Override
72-
String getPath () {
73-
path
74-
}
75-
76-
@Override
77-
String getName () {
78-
null
79-
}
80-
81-
@Override
82-
String getContentType () {
83-
null
84-
}
85-
}
86-
8769
ApiConverter(ApiOptions options) {
8870
this.options = options
8971

@@ -92,6 +74,10 @@ class ApiConverter {
9274
}
9375

9476
dataTypeConverter = new DataTypeConverter(this.options)
77+
dataTypeWrapper = new ResultDataTypeWrapper(this.options)
78+
singleDataTypeWrapper = new SingleDataTypeWrapper(this.options)
79+
multiDataTypeWrapper = new MultiDataTypeWrapper(this.options)
80+
mappingFinder = new MappingFinder (typeMappings: this.options.typeMappings)
9581
}
9682

9783
/**
@@ -164,7 +150,7 @@ class ApiConverter {
164150
ep.parameters.add (createParameter (ep.path, parameter, dataTypes, resolver))
165151
}
166152

167-
List<Mapping> addMappings = findAdditionalParameter (ep)
153+
List<Mapping> addMappings = mappingFinder.findAdditionalEndpointParameter (ep.path)
168154
addMappings.each {
169155
ep.parameters.add (createAdditionalParameter (ep.path, it as AddParameterTypeMapping, dataTypes, resolver))
170156
}
@@ -200,18 +186,14 @@ class ApiConverter {
200186
def httpStatus = responseEntry.key
201187
def httpResponse = responseEntry.value
202188

203-
if (!httpResponse.content) {
204-
ep.addResponses (httpStatus, [ModelResponse.EMPTY])
205-
} else {
206-
List<ModelResponse> results = createResponses (
207-
ep.path,
208-
httpStatus,
209-
httpResponse,
210-
dataTypes,
211-
resolver)
212-
213-
ep.addResponses (httpStatus, results)
214-
}
189+
List<ModelResponse> results = createResponses (
190+
ep.path,
191+
httpStatus,
192+
httpResponse,
193+
dataTypes,
194+
resolver)
195+
196+
ep.addResponses (httpStatus, results)
215197
}
216198

217199
}
@@ -255,10 +237,16 @@ class ApiConverter {
255237

256238
private ModelRequestBody createRequestBody (String contentType, SchemaInfo info, boolean required, DataTypes dataTypes) {
257239
DataType dataType = dataTypeConverter.convert (info, dataTypes)
240+
DataType changedType
241+
if (!info.isArray ()) {
242+
changedType = singleDataTypeWrapper.wrap (dataType, info)
243+
} else {
244+
changedType = multiDataTypeWrapper.wrap (dataType, info)
245+
}
258246

259247
new ModelRequestBody(
260248
contentType: contentType,
261-
requestBodyType: dataType,
249+
requestBodyType: changedType,
262250
required: required)
263251
}
264252

@@ -274,8 +262,20 @@ class ApiConverter {
274262
}
275263

276264
private List<ModelResponse> createResponses (String path, String httpStatus, Response response, DataTypes dataTypes, RefResolver resolver) {
277-
def responses = []
265+
if (!response.content) {
266+
def info = new SchemaInfo (path: path)
278267

268+
DataType dataType = new NoneDataType()
269+
DataType singleDataType = singleDataTypeWrapper.wrap (dataType, info)
270+
DataType resultDataType = dataTypeWrapper.wrap (singleDataType, info)
271+
272+
def resp = new ModelResponse (
273+
responseType: resultDataType)
274+
275+
return [resp]
276+
}
277+
278+
def responses = []
279279
response.content.each { Map.Entry<String, MediaType> contentEntry ->
280280
def contentType = contentEntry.key
281281
def mediaType = contentEntry.value
@@ -289,28 +289,24 @@ class ApiConverter {
289289
resolver: resolver)
290290

291291
DataType dataType = dataTypeConverter.convert (info, dataTypes)
292+
DataType changedType
293+
if (!info.isArray ()) {
294+
changedType = singleDataTypeWrapper.wrap (dataType, info)
295+
} else {
296+
changedType = multiDataTypeWrapper.wrap (dataType, info)
297+
}
298+
DataType resultDataType = dataTypeWrapper.wrap (changedType, info)
292299

293300
def resp = new ModelResponse (
294301
contentType: contentType,
295-
responseType: dataType)
302+
responseType: resultDataType)
296303

297304
responses.add (resp)
298305
}
299306

300307
responses
301308
}
302309

303-
private List<Mapping> findAdditionalParameter (Endpoint ep) {
304-
def addMappings = options.typeMappings.findAll {
305-
it.matches (Mapping.Level.ENDPOINT, new MappingSchemaEndpoint (path: ep.path))
306-
}.collectMany {
307-
it.childMappings
308-
}.findAll {
309-
it.matches (Mapping.Level.ADD, null as MappingSchema)
310-
}
311-
addMappings as List<Mapping>
312-
}
313-
314310
private String getInlineRequestBodyName (String path) {
315311
Identifier.toClass (path) + 'RequestBody'
316312
}
@@ -319,22 +315,8 @@ class ApiConverter {
319315
Identifier.toClass (path) + 'Response' + httpStatus
320316
}
321317

322-
323318
private boolean isExcluded (String path) {
324-
def endpointMatches = options.typeMappings.findAll {
325-
it.matches (Mapping.Level.ENDPOINT, new MappingSchemaEndpoint(path: path))
326-
}
327-
328-
if (!endpointMatches.empty) {
329-
if (endpointMatches.size () != 1) {
330-
throw new AmbiguousTypeMappingException (endpointMatches)
331-
}
332-
333-
def match = endpointMatches.first () as EndpointTypeMapping
334-
return match.exclude
335-
}
336-
337-
false
319+
mappingFinder.isExcludedEndpoint (path)
338320
}
339321

340322
private String getInterfaceName (def op, boolean excluded) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ApiOptions {
4444
* - interfaces => "${packageName}.api"
4545
* - models => "${packageName}.model"
4646
*/
47-
String packageName = 'generatr'
47+
String packageName = 'processor'
4848

4949
/**
5050
* provide enabling Bean Validation (JSR303) annotations. Default is false (disabled)

0 commit comments

Comments
 (0)