Skip to content

Commit 95ea08c

Browse files
committed
should not override named schema type with mapping
1 parent f21d26f commit 95ea08c

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/main/groovy/com/github/hauner/openapi/spring/model/DataTypes.groovy

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original authors
2+
* Copyright 2019-2020 the original authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package com.github.hauner.openapi.spring.model
1818

1919
import com.github.hauner.openapi.spring.model.datatypes.DataType
20+
import com.github.hauner.openapi.spring.model.datatypes.MappedDataType
2021
import com.github.hauner.openapi.spring.model.datatypes.ObjectDataType
2122
import com.github.hauner.openapi.spring.model.datatypes.StringEnumDataType
2223

@@ -28,6 +29,7 @@ import com.github.hauner.openapi.spring.model.datatypes.StringEnumDataType
2829
class DataTypes {
2930

3031
private Map<String, DataType> types = [:]
32+
private Map<String, MappedDataType> mappedTypes = [:]
3133

3234
/**
3335
* provides all named data types (including simple data types) used by the api endpoint.
@@ -74,7 +76,7 @@ class DataTypes {
7476
* @param dataType the source data type
7577
*/
7678
void add (DataType dataType) {
77-
types.put (dataType.name, dataType)
79+
add (dataType.name, dataType)
7880
}
7981

8082
/**
@@ -84,7 +86,11 @@ class DataTypes {
8486
* @param dataType the source data type
8587
*/
8688
void add (String name, DataType dataType) {
87-
types.put (name, dataType)
89+
if (dataType instanceof MappedDataType) {
90+
mappedTypes.put (name, dataType)
91+
} else {
92+
types.put (name, dataType)
93+
}
8894
}
8995

9096
/**
@@ -94,7 +100,12 @@ class DataTypes {
94100
* @return the data type or null if not found
95101
*/
96102
DataType find (String name) {
97-
types.get (name)
103+
def type = types.get (name)
104+
if (type) {
105+
return type
106+
} else {
107+
return mappedTypes.get (name)
108+
}
98109
}
99110

100111
/**

0 commit comments

Comments
 (0)