Skip to content
Next Next commit
removed useless SchemaInfo subclasses
  • Loading branch information
hauner committed Jan 9, 2020
commit 6e4d1ec71d9eb5bca140c65cb694771dc73d3a7c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

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

import com.github.hauner.openapi.spring.converter.schema.ParameterSchemaInfo
import com.github.hauner.openapi.spring.converter.schema.RefResolver
import com.github.hauner.openapi.spring.converter.schema.ResponseSchemaInfo
import com.github.hauner.openapi.spring.converter.schema.SchemaInfo
import com.github.hauner.openapi.spring.model.Api
import com.github.hauner.openapi.spring.model.DataTypes
Expand Down Expand Up @@ -161,8 +159,11 @@ class ApiConverter {
}

private ModelParameter createParameter (String path, Parameter parameter, DataTypes dataTypes, resolver) {
def info = new ParameterSchemaInfo (path, parameter.schema, parameter.name)
info.resolver = resolver
def info = new SchemaInfo (
path: path,
name: parameter.name,
schema: parameter.schema,
resolver: resolver)

DataType dataType = dataTypeConverter.convert (info, dataTypes)

Expand Down Expand Up @@ -209,12 +210,12 @@ class ApiConverter {
def mediaType = contentEntry.value
def schema = mediaType.schema

def info = new ResponseSchemaInfo (
path,
contentType,
schema,
inlineName)
info.resolver = resolver
def info = new SchemaInfo (
path: path,
contentType: contentType,
name: inlineName,
schema: schema,
resolver: resolver)

DataType dataType = dataTypeConverter.convert (info, dataTypes)

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 @@ -16,7 +16,7 @@

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

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

/**
* Used with {@link com.github.hauner.openapi.spring.converter.ApiOptions} to override parameter or
Expand Down Expand Up @@ -47,12 +47,12 @@ class EndpointTypeMapping implements TypeMappingX {
/**
* Checks if this endpoint mapping applies to the given schema info.
*
* @param info the schema info
* @param match the match info
* @return true, if path is equal, false if not
*/
@Override
boolean matches (SchemaInfo info) {
path == info.path
boolean matches (MatchValues match) {
path == match.matchPath
}

@Override
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 @@ -16,8 +16,7 @@

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

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

/**
* Used with {@link EndpointTypeMapping} to configure the java type that should represent the schema
Expand All @@ -40,16 +39,12 @@ class ParameterTypeMapping implements TypeMappingX {
/**
* Checks if this is a mapping for the given parameter schema info
*
* @param info a parameter schema info
* @param match the match info
* @return true if it is a mapping for info, else false
*/
@Override
boolean matches (SchemaInfo info) {
if (! (info instanceof ParameterSchemaInfo)) {
return false
}

parameterName == info.name
boolean matches (MatchValues match) {
parameterName == match.matchName
}

@Override
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 @@ -16,8 +16,7 @@

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

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

/**
* Used with {@link EndpointTypeMapping} to configure the java type that should represent the response
Expand All @@ -40,16 +39,12 @@ class ResponseTypeMapping implements TypeMappingX {
/**
* Checks if it is a mapping for the given response schema info
*
* @param info a response schema info
* @param match the match info
* @return true if it is a mapping for info, else false
*/
@Override
boolean matches (SchemaInfo info) {
if (! (info instanceof ResponseSchemaInfo)) {
return false
}

contentType == info.contentType
boolean matches (MatchValues match) {
contentType == match.matchContentType
}

@Override
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 @@ -16,6 +16,7 @@

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

/**
Expand Down Expand Up @@ -64,12 +65,12 @@ class TypeMapping implements TypeMappingX {
/**
* Checks if it is a mapping for the given schema info
*
* @param info a schema info
* @param match the match info
* @return true if it is a mapping for info, else false
*/
@Override
boolean matches (SchemaInfo info) {
sourceTypeName == info.name
boolean matches (MatchValues match) {
sourceTypeName == match.matchName
}

@Override
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 @@ -16,7 +16,7 @@

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

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

/**
* Type mapping levels
Expand All @@ -29,7 +29,7 @@ enum MappingLevel {
* Common interface for type mappings.
*/
interface TypeMappingX {
boolean matches (SchemaInfo info)
boolean matches (MatchValues match)
boolean isLevel (MappingLevel level)
List<TypeMappingX> getChildMappings ()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.hauner.openapi.spring.converter.schema

interface MatchValues {

String getMatchPath ()
String getMatchName ()
String getMatchContentType ()

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import groovy.transform.stc.ClosureParams
import io.swagger.v3.oas.models.media.Schema

/**
* Helper for {@link DataTypeConverter}. Holds an OpenAPI schema and context information, i.e. name
* and if this is an inline type with a generated name.
* Helper for {@link com.github.hauner.openapi.spring.converter.DataTypeConverter}. Holds an OpenAPI
* schema with context information, i.e. name and if this is an inline type with a generated name.
*
* @author Martin Hauner
*/
class SchemaInfo {
class SchemaInfo implements MatchValues {

/**
* Endpoint path.
Expand Down Expand Up @@ -96,7 +96,7 @@ class SchemaInfo {
SchemaInfo buildForItem () {
new SchemaInfo (
path: path,
name: name,
name: schema.items.type,
schema: schema.items,
resolver: resolver)
}
Expand Down Expand Up @@ -184,4 +184,18 @@ class SchemaInfo {
name + propName.capitalize ()
}

@Override
String getMatchPath () {
path
}

@Override
String getMatchName () {
name
}

@Override
String getMatchContentType () {
contentType
}
}