Skip to content

Commit 3234b2f

Browse files
authored
Merge branch 'OpenAPITools:master' into httplib-server-codegen
2 parents d220c6e + 9c11fcf commit 3234b2f

File tree

142 files changed

+5710
-355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+5710
-355
lines changed

.github/workflows/samples-ocaml.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ on:
44
push:
55
paths:
66
- 'samples/client/petstore/ocaml/**'
7+
- 'samples/client/petstore/ocaml-fake-petstore/**'
8+
- 'samples/client/petstore/ocaml-oneOf-primitive/**'
9+
- 'samples/client/petstore/ocaml-additional-properties/**'
710
pull_request:
811
paths:
912
- 'samples/client/petstore/ocaml/**'
13+
- 'samples/client/petstore/ocaml-fake-petstore/**'
14+
- 'samples/client/petstore/ocaml-oneOf-primitive/**'
15+
- 'samples/client/petstore/ocaml-additional-properties/**'
1016

1117
jobs:
1218
build:
@@ -17,6 +23,9 @@ jobs:
1723
matrix:
1824
sample:
1925
- 'samples/client/petstore/ocaml/'
26+
- 'samples/client/petstore/ocaml-fake-petstore/'
27+
- 'samples/client/petstore/ocaml-oneOf-primitive/'
28+
- 'samples/client/petstore/ocaml-additional-properties/'
2029
steps:
2130
- uses: actions/checkout@v5
2231
- name: Set-up OCaml

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ samples/openapi3/client/petstore/go/privatekey.pem
296296

297297
## OCaml
298298
samples/client/petstore/ocaml/_build/
299+
samples/client/petstore/ocaml-fake-petstore/_build/
300+
samples/client/petstore/ocaml-oneOf-primitive/_build/
301+
samples/client/petstore/ocaml-additional-properties/_build/
299302

300303
# jetbrain http client
301304
samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ If you want to join the committee, please kindly apply by sending an email to te
12641264
| Nim | |
12651265
| NodeJS/Javascript | @CodeNinjai (2017/07) @frol (2017/07) @cliffano (2017/07) |
12661266
| ObjC | |
1267-
| OCaml | @cgensoul (2019/08) |
1267+
| OCaml | @cgensoul (2019/08), @sir4ur0n (2025/08) |
12681268
| Perl | @wing328 (2017/07) [:heart:](https://www.patreon.com/wing328) @yue9944882 (2019/06) |
12691269
| PHP | @jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), [@ybelenko](https://github.com/ybelenko) (2018/07), @renepardon (2018/12) |
12701270
| PowerShell | @wing328 (2020/05) |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: ocaml
2+
outputDir: samples/client/petstore/ocaml-additional-properties
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/ocaml/additional-properties.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/ocaml
5+
additionalProperties:
6+
packageName: petstore_client
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: ocaml
2+
outputDir: samples/client/petstore/ocaml-fake-petstore
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/ocaml
5+
additionalProperties:
6+
packageName: petstore_client
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
generatorName: ocaml
2+
outputDir: samples/client/petstore/ocaml-oneOf-primitive
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_primitive.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/ocaml
5+
additionalProperties:
6+
packageName: petstore_client

docs/generators/ocaml.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
209209
|Polymorphism|✗|OAS2,OAS3
210210
|Union|✗|OAS3
211211
|allOf|✗|OAS2,OAS3
212-
|anyOf||OAS3
213-
|oneOf||OAS3
212+
|anyOf||OAS3
213+
|oneOf||OAS3
214214
|not|✗|OAS3
215215

216216
### Security Feature

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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('.')));

modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,20 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
389389
* @param accessToken the access token
390390
*/
391391
public void setAccessToken(String accessToken) {
392+
setAccessToken(() -> accessToken);
393+
}
394+
395+
/**
396+
* Helper method to set the supplier of access tokens for OAuth2 authentication.
397+
*
398+
* @param tokenSupplier The supplier of access tokens
399+
* @return ApiClient this client
400+
*/
401+
public ApiClient setAccessToken(Supplier<String> tokenSupplier) {
392402
for (Authentication auth : authentications.values()) {
393403
if (auth instanceof OAuth) {
394-
((OAuth) auth).setAccessToken(accessToken);
395-
return;
404+
((OAuth) auth).setAccessToken(tokenSupplier);
405+
return this;
396406
}
397407
}
398408
throw new RuntimeException("No OAuth2 authentication configured!");

modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}}
3030
let uri = Request.{{> to_optional_prefix}}replace_path_param uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in
3131
{{/pathParams}}
3232
{{#queryParams}}
33-
let uri = Request.{{> to_optional_prefix}}add_query_param{{#isArray}}_list{{/isArray}} uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in
33+
let uri = Request.{{> to_optional_prefix}}add_query_param{{#isArray}}_list{{/isArray}}{{#isExplode}}{{#isFormStyle}}{{#isMap}}_exploded_form_object{{/isMap}}{{/isFormStyle}}{{/isExplode}} uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in
3434
{{/queryParams}}
3535
{{#hasAuthMethods}}
3636
{{#authMethods}}
@@ -42,7 +42,10 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}}
4242
{{/authMethods}}
4343
{{/hasAuthMethods}}
4444
{{#bodyParams}}
45-
let body = Request.{{#isFreeFormObject}}write_json_body{{/isFreeFormObject}}{{#isByteArray}}write_string_body{{/isByteArray}}{{^isFreeFormObject}}{{^isByteArray}}write_as_json_body{{/isByteArray}}{{/isFreeFormObject}} {{> to_json}} {{{paramName}}} in
45+
let body = Request.
46+
{{#isByteArray}}write_string_body {{{paramName}}}{{/isByteArray}}
47+
{{^isByteArray}}write_as_json_body {{> to_json}} {{{paramName}}}{{/isByteArray}}
48+
in
4649
{{/bodyParams}}
4750
{{^hasBodyParam}}
4851
{{#hasFormParams}}

0 commit comments

Comments
 (0)