Skip to content

Commit 10890a9

Browse files
committed
[OCaml] Fix encoding/decoding for free-form required fields
1 parent 65d0329 commit 10890a9

23 files changed

Lines changed: 446 additions & 11 deletions

File tree

.github/workflows/samples-ocaml.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ on:
66
- 'samples/client/petstore/ocaml/**'
77
- 'samples/client/petstore/ocaml-fake-petstore/**'
88
- '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/**'
1314
- 'samples/client/petstore/ocaml-oneOf-primitive/**'
15+
- 'samples/client/petstore/ocaml-additional-properties/**'
1416

1517
jobs:
1618
build:
@@ -23,6 +25,7 @@ jobs:
2325
- 'samples/client/petstore/ocaml/'
2426
- 'samples/client/petstore/ocaml-fake-petstore/'
2527
- '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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ samples/openapi3/client/petstore/go/privatekey.pem
298298
samples/client/petstore/ocaml/_build/
299299
samples/client/petstore/ocaml-fake-petstore/_build/
300300
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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type t = {
2828
{{^required}} option [@default None]{{/required}}
2929
{{/isContainer}}
3030
{{#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}}
31+
{{#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}}
3232
; [@key "{{{baseName}}}"]
3333
{{/isEnum}}
3434
{{/vars}}
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
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version=0.27.0
2+
ocaml-version=4.14.0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.16.0-SNAPSHOT
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
3+
4+
This OCaml package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
5+
6+
- API version: 1.0.0
7+
- Package version: 1.0.0
8+
- Generator version: 7.16.0-SNAPSHOT
9+
- Build package: org.openapitools.codegen.languages.OCamlClientCodegen
10+
11+
## Requirements.
12+
13+
OCaml 5.x
14+
15+
## Installation
16+
17+
Please run the following commands to build the package `petstore_client`:
18+
19+
```sh
20+
opam install . --deps-only --with-test
21+
eval $(opam env)
22+
dune build
23+
```
24+
25+
## Getting Started
26+
27+
The generated directory structure is:
28+
- `src/apis`: contains several modules, each with several functions. Each function is an API endpoint.
29+
- `src/models`: contains several modules. Each module contains:
30+
- a type `t` representing an input and/or output schema of the OpenAPI spec
31+
- a smart constructor `create` for this type
32+
- `src/support`: various modules used by the generated APIs and Models
33+

0 commit comments

Comments
 (0)