Skip to content
Prev Previous commit
Next Next commit
improved naming
  • Loading branch information
hauner committed Jan 9, 2020
commit a3ebe6a67c144d0feebacad18adb62c13067aeab
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 the original authors
* Copyright 2019-2020 the original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@

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

import com.github.hauner.openapi.spring.converter.mapping.TypeMappingX
import com.github.hauner.openapi.spring.converter.mapping.Mapping

/**
* Options of the generatr.
Expand Down Expand Up @@ -49,12 +49,13 @@ class ApiOptions {
* provide additional type mapping information to map OpenAPI types to java types. The list can
* contain the following mappings:
*
* {@link com.github.hauner.openapi.spring.converter.mapping.TypeMapping}: used to globally override
* the mapping of an OpenAPI schema to a specific java type.
* {@link com.github.hauner.openapi.spring.converter.mapping.TypeMapping}: used to globally
* override the mapping of an OpenAPI schema to a specific java type.
*
* {@link com.github.hauner.openapi.spring.converter.mapping.EndpointTypeMapping}: used to override
* parameter, response type mappings or to add additional parameters on a single endpoint.
* {@link com.github.hauner.openapi.spring.converter.mapping.EndpointTypeMapping}: used to
* override parameter/response type mappings or to add additional parameters on a single
* endpoint.
*/
List<TypeMappingX> typeMappings
List<Mapping> typeMappings

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 the original authors
* Copyright 2019-2020 the original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@ package com.github.hauner.openapi.spring.converter
import com.github.hauner.openapi.spring.converter.mapping.AmbiguousTypeMappingException
import com.github.hauner.openapi.spring.converter.mapping.TargetType
import com.github.hauner.openapi.spring.converter.mapping.TypeMapping
import com.github.hauner.openapi.spring.converter.mapping.TypeMappingX
import com.github.hauner.openapi.spring.converter.mapping.Mapping
import com.github.hauner.openapi.spring.converter.schema.ArraySchemaType
import com.github.hauner.openapi.spring.converter.schema.ObjectSchemaType
import com.github.hauner.openapi.spring.converter.schema.PrimitiveSchemaType
Expand Down Expand Up @@ -229,7 +229,7 @@ class DataTypeConverter {

TargetType getMappedDataType (SchemaType schemaType) {
// check endpoint mappings
List<TypeMappingX> endpointMatches = schemaType.matchEndpointMapping (options.typeMappings)
List<Mapping> endpointMatches = schemaType.matchEndpointMapping (options.typeMappings)
if (!endpointMatches.empty) {

if (endpointMatches.size () != 1) {
Expand All @@ -243,7 +243,7 @@ class DataTypeConverter {
}

// check global io (parameter & response) mappings
List<TypeMappingX> ioMatches = schemaType.matchIoMapping (options.typeMappings)
List<Mapping> ioMatches = schemaType.matchIoMapping (options.typeMappings)
if (!ioMatches.empty) {

if (ioMatches.size () != 1) {
Expand All @@ -257,7 +257,7 @@ class DataTypeConverter {
}

// check global type mapping
List<TypeMappingX> typeMatches = schemaType.matchTypeMapping (options.typeMappings)
List<Mapping> typeMatches = schemaType.matchTypeMapping (options.typeMappings)
if (typeMatches.isEmpty ()) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.github.hauner.openapi.spring.converter.schema.MatchValues
*
* @author Martin Hauner
*/
class EndpointTypeMapping implements TypeMappingX {
class EndpointTypeMapping implements Mapping {

/**
* Full path of the endpoint that is configured by this object.
Expand Down Expand Up @@ -61,7 +61,7 @@ class EndpointTypeMapping implements TypeMappingX {
}

@Override
List<TypeMappingX> getChildMappings () {
List<Mapping> getChildMappings () {
typeMappings
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ enum MappingLevel {
/**
* Common interface for type mappings.
*/
interface TypeMappingX {
interface Mapping {
boolean matches (MatchValues match)
boolean isLevel (MappingLevel level)
List<TypeMappingX> getChildMappings ()
List<Mapping> getChildMappings ()
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.github.hauner.openapi.spring.converter.schema.MatchValues
*
* @author Martin Hauner
*/
class ParameterTypeMapping implements TypeMappingX {
class ParameterTypeMapping implements Mapping {

/**
* The parameter name of this mapping. Must match 1:1 with what is written in the api.
Expand Down Expand Up @@ -53,7 +53,7 @@ class ParameterTypeMapping implements TypeMappingX {
}

@Override
List<TypeMappingX> getChildMappings () {
List<Mapping> getChildMappings () {
[mapping]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.github.hauner.openapi.spring.converter.schema.MatchValues
*
* @author Martin Hauner
*/
class ResponseTypeMapping implements TypeMappingX {
class ResponseTypeMapping implements Mapping {

/**
* The content type of this mapping. Must match 1:1 with what is written in the api.
Expand Down Expand Up @@ -53,7 +53,7 @@ class ResponseTypeMapping implements TypeMappingX {
}

@Override
List<TypeMappingX> getChildMappings () {
List<Mapping> getChildMappings () {
[mapping]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.github.hauner.openapi.spring.converter.mapping

import com.github.hauner.openapi.spring.converter.schema.MatchValues
import com.github.hauner.openapi.spring.converter.schema.SchemaInfo

/**
* Used with {@link com.github.hauner.openapi.spring.converter.ApiOptions#typeMappings} to map an
Expand All @@ -28,7 +27,7 @@ import com.github.hauner.openapi.spring.converter.schema.SchemaInfo
*
* @author Martin Hauner
*/
class TypeMapping implements TypeMappingX {
class TypeMapping implements Mapping {

/**
* The OpenAPI schema type that should be mapped to the {@link #targetTypeName} java type.
Expand Down Expand Up @@ -79,7 +78,7 @@ class TypeMapping implements TypeMappingX {
}

@Override
List<TypeMappingX> getChildMappings () {
List<Mapping> getChildMappings () {
[this]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package com.github.hauner.openapi.spring.converter.schema

import com.github.hauner.openapi.spring.converter.mapping.MappingLevel
import com.github.hauner.openapi.spring.converter.mapping.TypeMappingX
import com.github.hauner.openapi.spring.converter.mapping.Mapping


interface SchemaType {

List<TypeMappingX> matchEndpointMapping (List<TypeMappingX> typeMappings)
List<TypeMappingX> matchIoMapping (List<TypeMappingX> typeMappings)
List<TypeMappingX> matchTypeMapping (List<TypeMappingX> typeMappings)
List<Mapping> matchEndpointMapping (List<Mapping> typeMappings)
List<Mapping> matchIoMapping (List<Mapping> typeMappings)
List<Mapping> matchTypeMapping (List<Mapping> typeMappings)

}

Expand All @@ -37,20 +37,20 @@ abstract class BaseSchemaType implements SchemaType {
}

@Override
List<TypeMappingX> matchEndpointMapping (List<TypeMappingX> typeMappings) {
List<Mapping> matchEndpointMapping (List<Mapping> typeMappings) {
// mappings matching by path
List<TypeMappingX> endpoint = typeMappings.findAll {
List<Mapping> endpoint = typeMappings.findAll {
it.isLevel (MappingLevel.ENDPOINT) && it.matches (info)
}.collect {
it.childMappings
}.flatten () as List<TypeMappingX>
}.flatten () as List<Mapping>

// io mappings
List<TypeMappingX> io = endpoint.findAll {
List<Mapping> io = endpoint.findAll {
it.isLevel (MappingLevel.IO) && it.matches (info)
}.collect {
it.childMappings
}.flatten () as List<TypeMappingX>
}.flatten () as List<Mapping>

if (!io.empty) {
return io
Expand All @@ -60,13 +60,13 @@ abstract class BaseSchemaType implements SchemaType {
matchTypeMapping (endpoint)
}

List<TypeMappingX> matchIoMapping (List<TypeMappingX> typeMappings) {
List<Mapping> matchIoMapping (List<Mapping> typeMappings) {
// io mappings
typeMappings.findAll {
it.isLevel (MappingLevel.IO) && it.matches (info)
}.collect {
it.childMappings
}.flatten () as List<TypeMappingX>
}.flatten () as List<Mapping>
}

}
Expand All @@ -78,7 +78,7 @@ class ObjectSchemaType extends BaseSchemaType {
}

@Override
List<TypeMappingX> matchTypeMapping (List<TypeMappingX> typeMappings) {
List<Mapping> matchTypeMapping (List<Mapping> typeMappings) {
typeMappings.findAll {
it.isLevel (MappingLevel.TYPE) && it.matches (info)
}
Expand All @@ -93,7 +93,7 @@ class ArraySchemaType extends BaseSchemaType {
}

@Override
List<TypeMappingX> matchTypeMapping (List<TypeMappingX> typeMappings) {
List<Mapping> matchTypeMapping (List<Mapping> typeMappings) {
def array = new SchemaInfo (name: 'array')
typeMappings.findAll () {
it.isLevel (MappingLevel.TYPE) && it.matches (array)
Expand All @@ -109,7 +109,7 @@ class PrimitiveSchemaType extends BaseSchemaType {
}

@Override
List<TypeMappingX> matchTypeMapping (List<TypeMappingX> typeMappings) {
List<Mapping> matchTypeMapping (List<Mapping> typeMappings) {
typeMappings.findAll () {
(it.isLevel (MappingLevel.TYPE)
// simple but ignores the interface!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 the original authors
* Copyright 2019-2020 the original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@ import com.github.hauner.openapi.spring.converter.mapping.EndpointTypeMapping
import com.github.hauner.openapi.spring.converter.mapping.ParameterTypeMapping
import com.github.hauner.openapi.spring.converter.mapping.ResponseTypeMapping
import com.github.hauner.openapi.spring.converter.mapping.TypeMapping
import com.github.hauner.openapi.spring.converter.mapping.TypeMappingX
import com.github.hauner.openapi.spring.converter.mapping.Mapping
import org.yaml.snakeyaml.Yaml

import java.util.regex.Matcher
Expand All @@ -34,7 +34,7 @@ import java.util.regex.Pattern
class TypeMappingReader {
private Pattern GENERIC_INLINE = ~/(.+?)<(.+?)>/

List<TypeMappingX> read (String typeMappings) {
List<Mapping> read (String typeMappings) {
if (typeMappings == null) {
return []
}
Expand Down