mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-24 01:39:08 +00:00
[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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user