@@ -29,6 +29,7 @@ import com.github.hauner.openapi.spring.model.DataTypes
2929import com.github.hauner.openapi.spring.model.datatypes.ArrayDataType
3030import com.github.hauner.openapi.spring.model.datatypes.BooleanDataType
3131import com.github.hauner.openapi.spring.model.datatypes.CollectionDataType
32+ import com.github.hauner.openapi.spring.model.datatypes.DataTypeConstraints
3233import com.github.hauner.openapi.spring.model.datatypes.ListDataType
3334import com.github.hauner.openapi.spring.model.datatypes.LocalDateDataType
3435import com.github.hauner.openapi.spring.model.datatypes.MapDataType
@@ -171,27 +172,30 @@ class DataTypeConverter {
171172 typeFormat + = ' /' + schemaInfo. format
172173 }
173174
175+ def defaultValue = schemaInfo. defaultValue
176+ def constraints = defaultValue != null ? new DataTypeConstraints (defaultValue : defaultValue) : null
177+
174178 def simpleType
175179 switch (typeFormat) {
176180 case ' integer' :
177181 case ' integer/int32' :
178- simpleType = new IntegerDataType ()
182+ simpleType = new IntegerDataType (constraints : constraints )
179183 break
180184 case ' integer/int64' :
181- simpleType = new LongDataType ()
185+ simpleType = new LongDataType (constraints : constraints )
182186 break
183187 case ' number' :
184188 case ' number/float' :
185- simpleType = new FloatDataType ()
189+ simpleType = new FloatDataType (constraints : constraints )
186190 break
187191 case ' number/double' :
188- simpleType = new DoubleDataType ()
192+ simpleType = new DoubleDataType (constraints : constraints )
189193 break
190194 case ' boolean' :
191- simpleType = new BooleanDataType ()
195+ simpleType = new BooleanDataType (constraints : constraints )
192196 break
193197 case ' string' :
194- simpleType = createStringDataType (schemaInfo, dataTypes)
198+ simpleType = createStringDataType (schemaInfo, constraints, dataTypes)
195199 break
196200 case ' string/date' :
197201 simpleType = new LocalDateDataType ()
@@ -206,17 +210,18 @@ class DataTypeConverter {
206210 simpleType
207211 }
208212
209- private DataType createStringDataType (SchemaInfo info , DataTypes dataTypes ) {
213+ private DataType createStringDataType (SchemaInfo info , DataTypeConstraints constraints , DataTypes dataTypes ) {
210214 if (! info. isEnum()) {
211- return new StringDataType ()
215+ return new StringDataType (constraints : constraints )
212216 }
213217
214218 // in case of an inline definition the name may be lowercase, make sure the enum
215219 // class gets an uppercase name!
216220 def enumType = new StringEnumDataType (
217221 type : info. name. capitalize (),
218222 pkg : [options. packageName, ' model' ]. join (' .' ),
219- values : info. enumValues)
223+ values : info. enumValues,
224+ constraints : constraints)
220225
221226 dataTypes. add (enumType)
222227 enumType
0 commit comments