Skip to content

Commit 90de8dc

Browse files
sir4ur0nwing328
andauthored
[OCaml] Add key to each model field (#20766)
* Add key to each model field Add a `[@key "someField"]` annotation to each model field, to avoid mismatches when the JSON field is not in snake_case. Closes #20765 * update ocaml samples --------- Co-authored-by: William Cheng <[email protected]>
1 parent a018c10 commit 90de8dc

File tree

10 files changed

+31
-30
lines changed

10 files changed

+31
-30
lines changed
File renamed without changes.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ type t = {
1616
(* {{{.}}} *)
1717
{{/description}}
1818
{{#isEnum}}
19-
{{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}}{{^isContainer}}{{#required}}{{#defaultValue}}[@default {{{.}}}]{{/defaultValue}}{{/required}}{{/isContainer}}{{^isContainer}}{{#required}}{{#isNullable}} option [@default {{#defaultValue}}Some({{{.}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}]{{/isNullable}}{{/required}}{{/isContainer}}{{^isContainer}}{{^required}} option [@default {{#defaultValue}}Some({{{.}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}]{{/required}}{{/isContainer}};
19+
{{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}}{{^isContainer}}{{#required}}{{#defaultValue}}[@default {{{.}}}]{{/defaultValue}}{{/required}}{{/isContainer}}{{^isContainer}}{{#required}}{{#isNullable}} option [@default {{#defaultValue}}Some({{{.}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}]{{/isNullable}}{{/required}}{{/isContainer}}{{^isContainer}}{{^required}} option [@default {{#defaultValue}}Some({{{.}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}]{{/required}}{{/isContainer}}; [@key "{{{baseName}}}"]
2020
{{/isEnum}}
2121
{{^isEnum}}
22-
{{{name}}}: {{{datatypeWithEnum}}}{{^isContainer}}{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}{{/isContainer}}{{^isContainer}}{{^required}} option [@default None]{{/required}}{{/isContainer}};
22+
{{{name}}}: {{{datatypeWithEnum}}}{{^isContainer}}{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}{{/isContainer}}{{^isContainer}}{{^required}} option [@default None]{{/required}}{{/isContainer}}; [@key "{{{baseName}}}"]
2323
{{/isEnum}}
2424
{{/vars}}
2525
} [@@deriving yojson { strict = false }, show ];;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.0.1-SNAPSHOT
1+
7.13.0-SNAPSHOT

samples/client/petstore/ocaml/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This OCaml package is automatically generated by the [OpenAPI Generator](https:/
55

66
- API version: 1.0.0
77
- Package version: 1.0.0
8+
- Generator version: 7.13.0-SNAPSHOT
89
- Build package: org.openapitools.codegen.languages.OCamlClientCodegen
910

1011
## Requirements.

samples/client/petstore/ocaml/src/models/api_response.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*)
88

99
type t = {
10-
code: int32 option [@default None];
11-
_type: string option [@default None];
12-
message: string option [@default None];
10+
code: int32 option [@default None]; [@key "code"]
11+
_type: string option [@default None]; [@key "type"]
12+
message: string option [@default None]; [@key "message"]
1313
} [@@deriving yojson { strict = false }, show ];;
1414

1515
(** Describes the result of uploading an image resource *)

samples/client/petstore/ocaml/src/models/category.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*)
88

99
type t = {
10-
id: int64 option [@default None];
11-
name: string option [@default None];
10+
id: int64 option [@default None]; [@key "id"]
11+
name: string option [@default None]; [@key "name"]
1212
} [@@deriving yojson { strict = false }, show ];;
1313

1414
(** A category for a pet *)

samples/client/petstore/ocaml/src/models/order.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
*)
88

99
type t = {
10-
id: int64 option [@default None];
11-
pet_id: int64 option [@default None];
12-
quantity: int32 option [@default None];
13-
ship_date: string option [@default None];
10+
id: int64 option [@default None]; [@key "id"]
11+
pet_id: int64 option [@default None]; [@key "petId"]
12+
quantity: int32 option [@default None]; [@key "quantity"]
13+
ship_date: string option [@default None]; [@key "shipDate"]
1414
(* Order Status *)
15-
status: Enums.status option [@default None];
16-
complete: bool option [@default None];
15+
status: Enums.status option [@default None]; [@key "status"]
16+
complete: bool option [@default None]; [@key "complete"]
1717
} [@@deriving yojson { strict = false }, show ];;
1818

1919
(** An order for a pets from the pet store *)

samples/client/petstore/ocaml/src/models/pet.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
*)
88

99
type t = {
10-
id: int64 option [@default None];
11-
category: Category.t option [@default None];
12-
name: string;
13-
photo_urls: string list;
14-
tags: Tag.t list;
10+
id: int64 option [@default None]; [@key "id"]
11+
category: Category.t option [@default None]; [@key "category"]
12+
name: string; [@key "name"]
13+
photo_urls: string list; [@key "photoUrls"]
14+
tags: Tag.t list; [@key "tags"]
1515
(* pet status in the store *)
16-
status: Enums.pet_status option [@default None];
16+
status: Enums.pet_status option [@default None]; [@key "status"]
1717
} [@@deriving yojson { strict = false }, show ];;
1818

1919
(** A pet for sale in the pet store *)

samples/client/petstore/ocaml/src/models/tag.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*)
88

99
type t = {
10-
id: int64 option [@default None];
11-
name: string option [@default None];
10+
id: int64 option [@default None]; [@key "id"]
11+
name: string option [@default None]; [@key "name"]
1212
} [@@deriving yojson { strict = false }, show ];;
1313

1414
(** A tag for a pet *)

samples/client/petstore/ocaml/src/models/user.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
*)
88

99
type t = {
10-
id: int64 option [@default None];
11-
username: string option [@default None];
12-
first_name: string option [@default None];
13-
last_name: string option [@default None];
14-
email: string option [@default None];
15-
password: string option [@default None];
16-
phone: string option [@default None];
10+
id: int64 option [@default None]; [@key "id"]
11+
username: string option [@default None]; [@key "username"]
12+
first_name: string option [@default None]; [@key "firstName"]
13+
last_name: string option [@default None]; [@key "lastName"]
14+
email: string option [@default None]; [@key "email"]
15+
password: string option [@default None]; [@key "password"]
16+
phone: string option [@default None]; [@key "phone"]
1717
(* User Status *)
18-
user_status: int32 option [@default None];
18+
user_status: int32 option [@default None]; [@key "userStatus"]
1919
} [@@deriving yojson { strict = false }, show ];;
2020

2121
(** A User who is purchasing from the pet store *)

0 commit comments

Comments
 (0)