Skip to content

Commit c9568e2

Browse files
committed
use type mapping from yaml
1 parent 9c84329 commit c9568e2

24 files changed

+136
-92
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.github.hauner.openapi.spring.converter
1818

19-
import com.github.hauner.openapi.spring.generatr.ApiOptions
20-
import com.github.hauner.openapi.spring.generatr.DefaultApiOptions
2119
import com.github.hauner.openapi.spring.model.Api
2220
import com.github.hauner.openapi.spring.model.Endpoint
2321
import com.github.hauner.openapi.spring.model.parameters.QueryParameter

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.github.hauner.openapi.spring.generatr
17+
package com.github.hauner.openapi.spring.converter
1818

1919
/**
2020
* Options of the generatr.
@@ -43,19 +43,14 @@ class ApiOptions {
4343
*/
4444
String packageName
4545

46-
/**
47-
* show warnings from the open api parser.
48-
*/
49-
boolean showWarnings
50-
5146
/**
5247
* provide additional type mapping information to map OpenAPI types to java types. The list can
5348
* contain the following mappings:
5449
*
55-
* {@link com.github.hauner.openapi.spring.generatr.mapping.TypeMapping}: used to globally override
50+
* {@link com.github.hauner.openapi.spring.converter.mapping.TypeMapping}: used to globally override
5651
* the mapping of an OpenAPI schema to a specific java type.
5752
*
58-
* {@link com.github.hauner.openapi.spring.generatr.mapping.EndpointTypeMapping}: used to override
53+
* {@link com.github.hauner.openapi.spring.converter.mapping.EndpointTypeMapping}: used to override
5954
* parameter, response type mappings or to add additional parameters on a single endpoint.
6055
*/
6156
List<?> typeMappings

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616

1717
package com.github.hauner.openapi.spring.converter
1818

19-
import com.github.hauner.openapi.spring.generatr.ApiOptions
20-
import com.github.hauner.openapi.spring.generatr.mapping.EndpointTypeMapping
21-
import com.github.hauner.openapi.spring.generatr.mapping.ResponseTypeMapping
22-
import com.github.hauner.openapi.spring.generatr.mapping.TypeMapping
19+
import com.github.hauner.openapi.spring.converter.mapping.EndpointTypeMapping
20+
import com.github.hauner.openapi.spring.converter.mapping.ResponseTypeMapping
21+
import com.github.hauner.openapi.spring.converter.mapping.TypeMapping
2322
import com.github.hauner.openapi.spring.model.DataTypes
2423
import com.github.hauner.openapi.spring.model.datatypes.ArrayDataType
2524
import com.github.hauner.openapi.spring.model.datatypes.BooleanDataType

src/main/groovy/com/github/hauner/openapi/spring/generatr/DefaultApiOptions.groovy renamed to src/main/groovy/com/github/hauner/openapi/spring/converter/DefaultApiOptions.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.github.hauner.openapi.spring.generatr
17+
package com.github.hauner.openapi.spring.converter
1818

1919
/**
2020
* ApiOptions defaults.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.github.hauner.openapi.spring.converter
1818

19-
import com.github.hauner.openapi.spring.generatr.ApiOptions
2019
import com.github.hauner.openapi.spring.model.Interface
2120
import io.swagger.v3.oas.models.Operation
2221
import io.swagger.v3.oas.models.PathItem

src/main/groovy/com/github/hauner/openapi/spring/generatr/mapping/EndpointTypeMapping.groovy renamed to src/main/groovy/com/github/hauner/openapi/spring/converter/mapping/EndpointTypeMapping.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.github.hauner.openapi.spring.generatr.mapping
17+
package com.github.hauner.openapi.spring.converter.mapping
1818

1919
/**
20-
* Used with {@link com.github.hauner.openapi.spring.generatr.ApiOptions} to override parameter or
20+
* Used with {@link com.github.hauner.openapi.spring.converter.ApiOptions} to override parameter or
2121
* response type mappings on a single endpoint. It can also be used to add parameters that are not
2222
* defined in the api. For example to pass {@link javax.servlet.http.HttpServletRequest} to the
2323
* controller method.

src/main/groovy/com/github/hauner/openapi/spring/generatr/mapping/ParameterTypeMapping.groovy renamed to src/main/groovy/com/github/hauner/openapi/spring/converter/mapping/ParameterTypeMapping.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.github.hauner.openapi.spring.generatr.mapping
17+
package com.github.hauner.openapi.spring.converter.mapping
1818

1919
/**
2020
* Used with {@link EndpointTypeMapping} to configure the java type that represents the schema of

src/main/groovy/com/github/hauner/openapi/spring/generatr/mapping/ResponseTypeMapping.groovy renamed to src/main/groovy/com/github/hauner/openapi/spring/converter/mapping/ResponseTypeMapping.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.github.hauner.openapi.spring.generatr.mapping
17+
package com.github.hauner.openapi.spring.converter.mapping
1818

1919
/**
2020
* Used with {@link EndpointTypeMapping} to configure the java type that represents the response

src/main/groovy/com/github/hauner/openapi/spring/generatr/mapping/TypeMapping.groovy renamed to src/main/groovy/com/github/hauner/openapi/spring/converter/mapping/TypeMapping.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.github.hauner.openapi.spring.generatr.mapping
17+
package com.github.hauner.openapi.spring.converter.mapping
1818

1919
/**
20-
* Used with {@link com.github.hauner.openapi.spring.generatr.ApiOptions#typeMappings} to map an
20+
* Used with {@link com.github.hauner.openapi.spring.converter.ApiOptions#typeMappings} to map an
2121
* OpenAPI schema to a java type.
2222
*
2323
* To override the type mapping of the OpenAPI {@code array} from a simple java array to another

src/main/groovy/com/github/hauner/openapi/spring/generatr/SpringGeneratr.groovy

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.github.hauner.openapi.spring.generatr
1818

1919
import com.github.hauner.openapi.api.OpenApiGeneratr
2020
import com.github.hauner.openapi.spring.converter.ApiConverter
21+
import com.github.hauner.openapi.spring.converter.ApiOptions
2122
import com.github.hauner.openapi.spring.writer.ApiWriter
2223
import com.github.hauner.openapi.spring.writer.HeaderWriter
2324
import com.github.hauner.openapi.spring.writer.InterfaceWriter
@@ -31,33 +32,34 @@ import io.swagger.v3.parser.core.models.SwaggerParseResult
3132
*
3233
* @author Martin Hauner
3334
*/
34-
class SpringGeneratr implements OpenApiGeneratr<ApiOptions> {
35+
class SpringGeneratr implements OpenApiGeneratr<SpringGeneratrOptions> {
3536

3637
@Override
3738
String getName () {
3839
return 'spring'
3940
}
4041

4142
@Override
42-
Class<ApiOptions> getOptionsType () {
43-
return ApiOptions
43+
Class<SpringGeneratrOptions> getOptionsType () {
44+
return SpringGeneratrOptions
4445
}
4546

4647
@Override
47-
void run (ApiOptions options) {
48+
void run (SpringGeneratrOptions generatrOptions) {
4849
ParseOptions opts = new ParseOptions(
4950
// loads $refs to other files into #/components/schema and replaces the $refs to the
5051
// external files with $refs to #/components/schema.
5152
resolve: true
5253
)
5354

5455
SwaggerParseResult result = new OpenAPIV3Parser ()
55-
.readLocation (options.apiPath, null, opts)
56+
.readLocation (generatrOptions.apiPath, null, opts)
5657

57-
if (options.showWarnings) {
58+
if (generatrOptions.showWarnings) {
5859
printWarnings(result.messages)
5960
}
6061

62+
def options = convertOptions (generatrOptions)
6163
def cv = new ApiConverter(options)
6264
def api = cv.convert (result.openAPI)
6365

@@ -70,6 +72,16 @@ class SpringGeneratr implements OpenApiGeneratr<ApiOptions> {
7072
writer.write (api)
7173
}
7274

75+
private ApiOptions convertOptions (SpringGeneratrOptions generatrOptions) {
76+
def options = new ApiOptions()
77+
def reader = new TypeMappingReader ()
78+
options.apiPath = generatrOptions.apiPath
79+
options.targetDir = generatrOptions.targetDir
80+
options.packageName = generatrOptions.packageName
81+
options.typeMappings = reader.read (generatrOptions.typeMappings)
82+
options
83+
}
84+
7385
private static printWarnings(List<String> warnings) {
7486
if (warnings.empty) {
7587
return

0 commit comments

Comments
 (0)