[OCaml] Added optional params support in API operations (#3568)

* Added handling of api keys in headers.

* Added handling of optional arguments in api functions.

* Optional header params.

* Fixed a bug in path param replacement.

* Relaxed deserializing of model records with @@deriving yojson { strict = false }. It allows receiving more fields in the JSon payload than declared in the OCaml record, fields not matching any record field are ignored.

* Reformatted api-impl.mustache.

* Generate shorter enum value names by allowing underscore character.

* Cleanup of optional params generation.

* Updated the OCaml samples with the latest version of the generator.

* Corrected a bug encountered when generating default value for optional enum fields.

* Added v3 version of the samples for the OCaml generator.
This commit is contained in:
cgensoul
2019-08-07 05:25:32 +02:00
committed by William Cheng
parent 4478f42927
commit 411199bc99
87 changed files with 1962 additions and 90 deletions

View File

@@ -33,6 +33,7 @@ import java.util.*;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.capitalize;
import static org.openapitools.codegen.utils.StringUtils.escape;
import static org.openapitools.codegen.utils.StringUtils.underscore;
public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig {
@@ -631,9 +632,19 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
return result;
}
public String toEnumValueName(String name) {
if (reservedWords.contains(name)) {
return escapeReservedWord(name);
} else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains("" + ((char) character)))) {
return escape(name, specialCharReplacements, Collections.singletonList("_"), null);
} else {
return name;
}
}
private String ocamlizeEnumValue(String value) {
String sanitizedValue =
super.toVarName(value.isEmpty() ? "empty" : value)
toEnumValueName(value.isEmpty() ? "empty" : value)
.replace(" ", "_");
if (!sanitizedValue.matches("^[a-zA-Z_].*")) {
@@ -735,6 +746,9 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
@Override
public String toDefaultValue(Schema p) {
if (p.getDefault() != null) {
if (p.getEnum() != null) {
return ocamlizeEnumValue(p.getDefault().toString());
}
return p.getDefault().toString();
} else {
return null;