Skip to content

Commit 9c11fcf

Browse files
authored
[Fix][OCaml] Incorrect encoding/decoding for required free-form objects; Odoc for record fields (#21819)
* [OCaml] Fix inconsistent oneOf primitive sample name * [OCaml] Fix encoding/decoding for free-form required fields * [OCaml] Change field comment to Odoc, move it after the field As per Odoc documentation, record field documentation should be *after* the field, not before. See https://ocaml.github.io/odoc/odoc/odoc_for_authors.html#special_comments type `my_record` * [OCaml] Cleanup non-generated files for ocaml sample
1 parent 6215e6e commit 9c11fcf

File tree

87 files changed

+571
-169
lines changed

Some content is hidden

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

87 files changed

+571
-169
lines changed

.github/workflows/samples-ocaml.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ on:
55
paths:
66
- 'samples/client/petstore/ocaml/**'
77
- 'samples/client/petstore/ocaml-fake-petstore/**'
8-
- 'samples/client/petstore/ocaml-oneOf/**'
8+
- 'samples/client/petstore/ocaml-oneOf-primitive/**'
9+
- 'samples/client/petstore/ocaml-additional-properties/**'
910
pull_request:
1011
paths:
1112
- 'samples/client/petstore/ocaml/**'
1213
- 'samples/client/petstore/ocaml-fake-petstore/**'
13-
- 'samples/client/petstore/ocaml-oneOf/**'
14+
- 'samples/client/petstore/ocaml-oneOf-primitive/**'
15+
- 'samples/client/petstore/ocaml-additional-properties/**'
1416

1517
jobs:
1618
build:
@@ -22,7 +24,8 @@ jobs:
2224
sample:
2325
- 'samples/client/petstore/ocaml/'
2426
- 'samples/client/petstore/ocaml-fake-petstore/'
25-
- 'samples/client/petstore/ocaml-oneOf/'
27+
- 'samples/client/petstore/ocaml-oneOf-primitive/'
28+
- 'samples/client/petstore/ocaml-additional-properties/'
2629
steps:
2730
- uses: actions/checkout@v5
2831
- name: Set-up OCaml

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ samples/openapi3/client/petstore/go/privatekey.pem
297297
## OCaml
298298
samples/client/petstore/ocaml/_build/
299299
samples/client/petstore/ocaml-fake-petstore/_build/
300-
samples/client/petstore/ocaml-oneOf/_build/
300+
samples/client/petstore/ocaml-oneOf-primitive/_build/
301+
samples/client/petstore/ocaml-additional-properties/_build/
301302

302303
# jetbrain http client
303304
samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json
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

bin/configs/ocaml-oneOf.yaml renamed to bin/configs/ocaml-oneOf-primitive.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
generatorName: ocaml
2-
outputDir: samples/client/petstore/ocaml-oneOf
2+
outputDir: samples/client/petstore/ocaml-oneOf-primitive
33
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_primitive.yaml
44
templateDir: modules/openapi-generator/src/main/resources/ocaml
55
additionalProperties:

modules/openapi-generator/src/main/resources/ocaml/model-record.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
type t = {
22
{{#vars}}
3-
{{#description}}
4-
(* {{{.}}} *)
5-
{{/description}}
63
{{#isEnum}}
74
{{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}}
85
{{^isContainer}}
@@ -28,9 +25,12 @@ type t = {
2825
{{^required}} option [@default None]{{/required}}
2926
{{/isContainer}}
3027
{{#isArray}}{{^required}} [@default []]{{/required}}{{/isArray}}
31-
{{#isMap}}{{^required}} [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: {{{items.datatypeWithEnum}}}]] [@of_yojson JsonSupport.to_map_of [%of_yojson: {{{items.datatypeWithEnum}}}]] {{/required}}{{/isMap}}
28+
{{#isMap}}{{^required}} [@default []]{{/required}} [@to_yojson JsonSupport.of_map_of [%to_yojson: {{{items.datatypeWithEnum}}}]] [@of_yojson JsonSupport.to_map_of [%of_yojson: {{{items.datatypeWithEnum}}}]]{{/isMap}}
3229
; [@key "{{{baseName}}}"]
3330
{{/isEnum}}
31+
{{#description}}
32+
(** {{{.}}} *)
33+
{{/description}}
3434
{{/vars}}
3535
} [@@deriving yojson { strict = false }, show, eq ];;
3636

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Test various flavors of additionalProperties
2+
openapi: 3.0.0
3+
info:
4+
title: Test
5+
version: 1.0.0
6+
paths: {}
7+
components:
8+
schemas:
9+
SomeObject:
10+
required:
11+
- required_field1
12+
- required_field2
13+
- required_field3
14+
properties:
15+
required_field1:
16+
type: object
17+
description: Required, free-form
18+
additionalProperties: {}
19+
required_field2:
20+
type: object
21+
description: Required, dictionary of strings
22+
additionalProperties:
23+
type: string
24+
required_field3:
25+
type: object
26+
description: Required, dictionary of objects
27+
additionalProperties:
28+
type: object
29+
properties:
30+
sub_field1:
31+
type: number
32+
sub_field2:
33+
type: boolean
34+
optional_field1:
35+
type: object
36+
description: Optional, free-form
37+
additionalProperties: {}
38+
optional_field2:
39+
type: object
40+
description: Optional, dictionary of strings
41+
additionalProperties:
42+
type: string
43+
optional_field3:
44+
type: object
45+
description: Optional, dictionary of objects
46+
additionalProperties:
47+
type: object
48+
properties:
49+
sub_field1:
50+
type: number
51+
sub_field2:
52+
type: boolean
File renamed without changes.
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.ocamlformat
2+
README.md
3+
dune
4+
dune-project
5+
petstore_client.opam
6+
src/models/some_object.ml
7+
src/models/some_object_required_field3_value.ml
8+
src/support/enums.ml
9+
src/support/jsonSupport.ml
10+
src/support/request.ml
File renamed without changes.

0 commit comments

Comments
 (0)