9
9
import io .swagger .codegen .CodegenType ;
10
10
import io .swagger .codegen .DefaultCodegen ;
11
11
import io .swagger .codegen .SupportingFile ;
12
+ import io .swagger .models .ArrayModel ;
13
+ import io .swagger .models .Model ;
12
14
import io .swagger .models .Response ;
13
15
import io .swagger .models .parameters .Parameter ;
14
16
import io .swagger .models .properties .ArrayProperty ;
@@ -103,6 +105,7 @@ public ElmClientCodegen() {
103
105
);
104
106
105
107
instantiationTypes .clear ();
108
+ instantiationTypes .put ("array" , "List" );
106
109
107
110
typeMapping .clear ();
108
111
typeMapping .put ("integer" , "Int" );
@@ -181,6 +184,17 @@ public String toEnumVarName(String value, String datatype) {
181
184
return camelized ;
182
185
}
183
186
187
+ @ Override
188
+ public String toInstantiationType (Property p ) {
189
+ if (p instanceof ArrayProperty ) {
190
+ ArrayProperty ap = (ArrayProperty ) p ;
191
+ String inner = getSwaggerType (ap .getItems ());
192
+ return instantiationTypes .get ("array" ) + " " + inner ;
193
+ } else {
194
+ return null ;
195
+ }
196
+ }
197
+
184
198
@ Override
185
199
public String escapeReservedWord (String name ) {
186
200
return name + "_" ;
@@ -196,6 +210,20 @@ public String modelFileFolder() {
196
210
return outputFolder + "/src/Data/" + modelPackage ().replace ('.' , File .separatorChar );
197
211
}
198
212
213
+ @ Override
214
+ public CodegenModel fromModel (String name , Model model , Map <String , Model > allDefinitions ) {
215
+ CodegenModel m = super .fromModel (name , model , allDefinitions );
216
+
217
+ if (model instanceof ArrayModel ) {
218
+ ArrayModel am = (ArrayModel ) model ;
219
+ ArrayProperty arrayProperty = new ArrayProperty (am .getItems ());
220
+ CodegenProperty codegenProperty = fromProperty (name , arrayProperty );
221
+ m .vendorExtensions .putAll (codegenProperty .vendorExtensions );
222
+ }
223
+
224
+ return m ;
225
+ }
226
+
199
227
@ SuppressWarnings ({ "static-method" , "unchecked" })
200
228
public Map <String , Object > postProcessAllModels (Map <String , Object > objs ) {
201
229
// Index all CodegenModels by model name.
@@ -245,6 +273,20 @@ public int compare(CodegenModel cm1, CodegenModel cm2) {
245
273
elmImports .add (createPropertyImport (property ));
246
274
}
247
275
}
276
+ if (cm .isArrayModel ) {
277
+ if (cm .arrayModelType != null ) {
278
+ // add type imports
279
+ final ElmImport elmImport = new ElmImport ();
280
+ final String modulePrefix = customPrimitives .contains (cm .arrayModelType ) ? "" : "Data." ;
281
+ elmImport .moduleName = modulePrefix + cm .arrayModelType ;
282
+ elmImport .exposures = new TreeSet <>();
283
+ elmImport .exposures .add (cm .arrayModelType );
284
+ elmImport .exposures .add (camelize (cm .arrayModelType , true ) + "Decoder" );
285
+ elmImport .exposures .add (camelize (cm .arrayModelType , true ) + "Encoder" );
286
+ elmImport .hasExposures = true ;
287
+ elmImports .add (elmImport );
288
+ }
289
+ }
248
290
if (cm .discriminator != null ) {
249
291
for (CodegenModel child : cm .children ) {
250
292
// add child imports
@@ -418,7 +460,7 @@ public String toDefaultValue(Property p) {
418
460
return toOptionalValue (null );
419
461
}
420
462
}
421
-
463
+
422
464
private String toOptionalValue (String value ) {
423
465
if (value == null ) {
424
466
return "Nothing" ;
@@ -508,4 +550,4 @@ private static class ElmImport {
508
550
public Set <String > exposures ;
509
551
public Boolean hasExposures ;
510
552
}
511
- }
553
+ }
0 commit comments