@@ -51,8 +51,6 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
5151
5252 static final String X_MODEL_MODULE = "x-model-module" ;
5353
54- public static final String CO_HTTP = "cohttp" ;
55-
5654 @ Setter protected String packageName = "openapi" ;
5755 @ Setter protected String packageVersion = "1.0.0" ;
5856 protected String apiDocPath = "docs/" ;
@@ -97,12 +95,15 @@ public OCamlClientCodegen() {
9795 .excludeSchemaSupportFeatures (
9896 SchemaSupportFeature .Polymorphism
9997 )
98+ .includeSchemaSupportFeatures (
99+ SchemaSupportFeature .oneOf ,
100+ SchemaSupportFeature .anyOf
101+ )
100102 .includeClientModificationFeatures (
101103 ClientModificationFeature .BasePath
102104 )
103105 );
104106
105-
106107 outputFolder = "generated-code/ocaml" ;
107108 modelTemplateFiles .put ("model.mustache" , ".ml" );
108109
@@ -133,6 +134,7 @@ public OCamlClientCodegen() {
133134 supportingFiles .add (new SupportingFile ("dune.mustache" , "" , "dune" ));
134135 supportingFiles .add (new SupportingFile ("dune-project.mustache" , "" , "dune-project" ));
135136 supportingFiles .add (new SupportingFile ("readme.mustache" , "" , "README.md" ));
137+ supportingFiles .add (new SupportingFile ("ocamlformat.mustache" , "" , ".ocamlformat" ));
136138
137139 defaultIncludes = new HashSet <>(
138140 Arrays .asList (
@@ -171,6 +173,7 @@ public OCamlClientCodegen() {
171173 typeMapping .put ("short" , "int" );
172174 typeMapping .put ("char" , "char" );
173175 typeMapping .put ("float" , "float" );
176+ typeMapping .put ("decimal" , "string" );
174177 typeMapping .put ("double" , "float" );
175178 typeMapping .put ("integer" , "int32" );
176179 typeMapping .put ("number" , "float" );
@@ -179,36 +182,27 @@ public OCamlClientCodegen() {
179182 typeMapping .put ("any" , "Yojson.Safe.t" );
180183 typeMapping .put ("file" , "string" );
181184 typeMapping .put ("ByteArray" , "string" );
185+ typeMapping .put ("AnyType" , "Yojson.Safe.t" );
182186 // lib
183187 typeMapping .put ("string" , "string" );
184188 typeMapping .put ("UUID" , "string" );
185189 typeMapping .put ("URI" , "string" );
186190 typeMapping .put ("set" , "`Set" );
187191 typeMapping .put ("password" , "string" );
188192 typeMapping .put ("DateTime" , "string" );
189-
190- // supportedLibraries.put(CO_HTTP, "HTTP client: CoHttp.");
191- //
192- // CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use.");
193- // libraryOption.setEnum(supportedLibraries);
194- // // set hyper as the default
195- // libraryOption.setDefault(CO_HTTP);
196- // cliOptions.add(libraryOption);
197- // setLibrary(CO_HTTP);
198193 }
199194
200195 @ Override
201196 public Map <String , ModelsMap > postProcessAllModels (Map <String , ModelsMap > superobjs ) {
202197 List <String > toRemove = new ArrayList <>();
203198
204199 for (Map .Entry <String , ModelsMap > modelEntry : superobjs .entrySet ()) {
205- // process enum in models
206200 List <ModelMap > models = modelEntry .getValue ().getModels ();
207201 for (ModelMap mo : models ) {
208202 CodegenModel cm = mo .getModel ();
209203
210204 // for enum model
211- if (Boolean . TRUE . equals ( cm .isEnum ) && cm .allowableValues != null ) {
205+ if (cm .isEnum && cm .allowableValues != null ) {
212206 toRemove .add (modelEntry .getKey ());
213207 } else {
214208 enrichPropertiesWithEnumDefaultValues (cm .getAllVars ());
@@ -219,6 +213,15 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> supero
219213 enrichPropertiesWithEnumDefaultValues (cm .getVars ());
220214 enrichPropertiesWithEnumDefaultValues (cm .getParentVars ());
221215 }
216+
217+ if (!cm .oneOf .isEmpty ()) {
218+ // Add a boolean if it is a `oneOf`, because Mustache does not let us check if a list is non-empty
219+ cm .getVendorExtensions ().put ("x-ocaml-isOneOf" , true );
220+ }
221+ if (!cm .anyOf .isEmpty ()) {
222+ // Add a boolean if it is a `anyOf`, because Mustache does not let us check if a list is non-empty
223+ cm .getVendorExtensions ().put ("x-ocaml-isAnyOf" , true );
224+ }
222225 }
223226 }
224227
@@ -242,8 +245,7 @@ private void enrichPropertiesWithEnumDefaultValues(List<CodegenProperty> propert
242245 @ Override
243246 protected void updateDataTypeWithEnumForMap (CodegenProperty property ) {
244247 CodegenProperty baseItem = property .items ;
245- while (baseItem != null && (Boolean .TRUE .equals (baseItem .isMap )
246- || Boolean .TRUE .equals (baseItem .isArray ))) {
248+ while (baseItem != null && (baseItem .isMap || baseItem .isArray )) {
247249 baseItem = baseItem .items ;
248250 }
249251
@@ -260,8 +262,7 @@ protected void updateDataTypeWithEnumForMap(CodegenProperty property) {
260262 @ Override
261263 protected void updateDataTypeWithEnumForArray (CodegenProperty property ) {
262264 CodegenProperty baseItem = property .items ;
263- while (baseItem != null && (Boolean .TRUE .equals (baseItem .isMap )
264- || Boolean .TRUE .equals (baseItem .isArray ))) {
265+ while (baseItem != null && (baseItem .isMap || baseItem .isArray )) {
265266 baseItem = baseItem .items ;
266267 }
267268 if (baseItem != null ) {
@@ -312,19 +313,17 @@ private void collectEnumSchemas(String parentName, Map<String, Schema> schemas)
312313
313314 collectEnumSchemas (parentName , sName , schema );
314315
316+ String pName = parentName != null ? parentName + "_" + sName : sName ;
315317 if (schema .getProperties () != null ) {
316- String pName = parentName != null ? parentName + "_" + sName : sName ;
317318 collectEnumSchemas (pName , schema .getProperties ());
318319 }
319320
320321 if (schema .getAdditionalProperties () != null && schema .getAdditionalProperties () instanceof Schema ) {
321- String pName = parentName != null ? parentName + "_" + sName : sName ;
322322 collectEnumSchemas (pName , (Schema ) schema .getAdditionalProperties ());
323323 }
324324
325325 if (ModelUtils .isArraySchema (schema )) {
326326 if (ModelUtils .getSchemaItems (schema ) != null ) {
327- String pName = parentName != null ? parentName + "_" + sName : sName ;
328327 collectEnumSchemas (pName , ModelUtils .getSchemaItems (schema ));
329328 }
330329 }
@@ -677,7 +676,7 @@ private List<Map<String, Object>> buildEnumValues(String valueString) {
677676 public String toEnumValueName (String name ) {
678677 if (reservedWords .contains (name )) {
679678 return escapeReservedWord (name );
680- } else if ((( CharSequence ) name ) .chars ().anyMatch (character -> specialCharReplacements .keySet (). contains (String .valueOf ((char ) character )))) {
679+ } else if (name .chars ().anyMatch (character -> specialCharReplacements .containsKey (String .valueOf ((char ) character )))) {
681680 return escape (name , specialCharReplacements , Collections .singletonList ("_" ), null );
682681 } else {
683682 return name ;
@@ -723,8 +722,6 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
723722 List <CodegenOperation > operations = objectMap .getOperation ();
724723
725724 for (CodegenOperation operation : operations ) {
726- // http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put)
727- //if (CO_HTTP.equals(getLibrary())) {
728725 for (CodegenParameter param : operation .bodyParams ) {
729726 if (param .isModel && param .dataType .endsWith (".t" )) {
730727 param .vendorExtensions .put (X_MODEL_MODULE , param .dataType .substring (0 , param .dataType .lastIndexOf ('.' )));
0 commit comments