@@ -50,6 +50,7 @@ import com.github.hauner.openapi.spring.model.datatypes.StringEnumDataType
5050 * Converter to map OpenAPI schemas to Java data types.
5151 *
5252 * @author Martin Hauner
53+ * @author Bastian Wilhelm
5354 */
5455class DataTypeConverter {
5556
@@ -94,18 +95,26 @@ class DataTypeConverter {
9495
9596 def arrayType
9697 TargetType targetType = getMappedDataType (new ArraySchemaType (schemaInfo))
98+
99+ def constraints = new DataTypeConstraints (
100+ defaultValue : schemaInfo. defaultValue,
101+ nullable : schemaInfo. nullable,
102+ minItems : schemaInfo. minItems,
103+ maxItems : schemaInfo. maxItems,
104+ )
105+
97106 switch (targetType?. typeName) {
98107 case Collection . name:
99- arrayType = new CollectionDataType (item : item)
108+ arrayType = new CollectionDataType (item : item, constraints : constraints )
100109 break
101110 case List . name:
102- arrayType = new ListDataType (item : item)
111+ arrayType = new ListDataType (item : item, constraints : constraints )
103112 break
104113 case Set . name:
105- arrayType = new SetDataType (item : item)
114+ arrayType = new SetDataType (item : item, constraints : constraints )
106115 break
107116 default :
108- arrayType = new ArrayDataType (item : item)
117+ arrayType = new ArrayDataType (item : item, constraints : constraints )
109118 }
110119
111120 arrayType
@@ -142,9 +151,14 @@ class DataTypeConverter {
142151 }
143152 }
144153
154+ def constraints = new DataTypeConstraints (
155+ nullable : schemaInfo. nullable,
156+ )
157+
145158 objectType = new ObjectDataType (
146159 type : schemaInfo. name,
147- pkg : [options. packageName, ' model' ]. join (' .' )
160+ pkg : [options. packageName, ' model' ]. join (' .' ),
161+ constraints : constraints
148162 )
149163
150164 schemaInfo. eachProperty { String propName , SchemaInfo propDataTypeInfo ->
@@ -173,8 +187,16 @@ class DataTypeConverter {
173187 typeFormat + = ' /' + schemaInfo. format
174188 }
175189
176- def defaultValue = schemaInfo. defaultValue
177- def constraints = defaultValue != null ? new DataTypeConstraints (defaultValue : defaultValue) : null
190+ def constraints = new DataTypeConstraints (
191+ defaultValue : schemaInfo. defaultValue,
192+ nullable : schemaInfo. nullable,
193+ minLength : schemaInfo. minLength,
194+ maxLength : schemaInfo. maxLength,
195+ maximum : schemaInfo. maximum,
196+ exclusiveMaximum : schemaInfo. exclusiveMaximum,
197+ minimum : schemaInfo. minimum,
198+ exclusiveMinimum : schemaInfo. exclusiveMinimum,
199+ )
178200
179201 def simpleType
180202 switch (typeFormat) {
0 commit comments