forked from loafle/openapi-generator-original
[OCaml] Fix default optional list (#20789)
* Cleanup the existing model template * `{{^isContainer}}foobar{{/isContainer}}{{^isContainer}}` is equivalent to `{{^isContainer}}foobar` * Add indentations to make it easier to read the template. The generated code is uglier, but it is ok since users are encouraged to reformat anyway * Add a default value for non-required lists Closes https://github.com/OpenAPITools/openapi-generator/issues/20777
This commit is contained in:
parent
c96d3088c5
commit
0f13dfedb9
@ -16,10 +16,31 @@ type t = {
|
|||||||
(* {{{.}}} *)
|
(* {{{.}}} *)
|
||||||
{{/description}}
|
{{/description}}
|
||||||
{{#isEnum}}
|
{{#isEnum}}
|
||||||
{{{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}}}"]
|
{{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}}
|
||||||
|
{{^isContainer}}
|
||||||
|
{{#required}}
|
||||||
|
{{#defaultValue}}[@default {{{.}}}]{{/defaultValue}}
|
||||||
|
{{#isNullable}} option [@default
|
||||||
|
{{#defaultValue}}Some({{{.}}}){{/defaultValue}}
|
||||||
|
{{^defaultValue}}None{{/defaultValue}}
|
||||||
|
]
|
||||||
|
{{/isNullable}}
|
||||||
|
{{/required}}
|
||||||
|
{{^required}} option [@default
|
||||||
|
{{#defaultValue}}Some({{{.}}}){{/defaultValue}}
|
||||||
|
{{^defaultValue}}None{{/defaultValue}}
|
||||||
|
]
|
||||||
|
{{/required}}
|
||||||
|
{{/isContainer}}; [@key "{{{baseName}}}"]
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{^isEnum}}
|
{{^isEnum}}
|
||||||
{{{name}}}: {{{datatypeWithEnum}}}{{^isContainer}}{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}{{/isContainer}}{{^isContainer}}{{^required}} option [@default None]{{/required}}{{/isContainer}}; [@key "{{{baseName}}}"]
|
{{{name}}}: {{{datatypeWithEnum}}}
|
||||||
|
{{^isContainer}}
|
||||||
|
{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}
|
||||||
|
{{^required}} option [@default None]{{/required}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{#isArray}}{{^required}} [@default []]{{/required}}{{/isArray}}
|
||||||
|
; [@key "{{{baseName}}}"]
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
} [@@deriving yojson { strict = false }, show ];;
|
} [@@deriving yojson { strict = false }, show ];;
|
||||||
|
@ -7,9 +7,21 @@
|
|||||||
*)
|
*)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
code: int32 option [@default None]; [@key "code"]
|
code: int32
|
||||||
_type: string option [@default None]; [@key "type"]
|
|
||||||
message: string option [@default None]; [@key "message"]
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "code"]
|
||||||
|
_type: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "type"]
|
||||||
|
message: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "message"]
|
||||||
} [@@deriving yojson { strict = false }, show ];;
|
} [@@deriving yojson { strict = false }, show ];;
|
||||||
|
|
||||||
(** Describes the result of uploading an image resource *)
|
(** Describes the result of uploading an image resource *)
|
||||||
|
@ -7,8 +7,16 @@
|
|||||||
*)
|
*)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
id: int64 option [@default None]; [@key "id"]
|
id: int64
|
||||||
name: string option [@default None]; [@key "name"]
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "id"]
|
||||||
|
name: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "name"]
|
||||||
} [@@deriving yojson { strict = false }, show ];;
|
} [@@deriving yojson { strict = false }, show ];;
|
||||||
|
|
||||||
(** A category for a pet *)
|
(** A category for a pet *)
|
||||||
|
@ -7,13 +7,38 @@
|
|||||||
*)
|
*)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
id: int64 option [@default None]; [@key "id"]
|
id: int64
|
||||||
pet_id: int64 option [@default None]; [@key "petId"]
|
|
||||||
quantity: int32 option [@default None]; [@key "quantity"]
|
option [@default None]
|
||||||
ship_date: string option [@default None]; [@key "shipDate"]
|
|
||||||
|
; [@key "id"]
|
||||||
|
pet_id: int64
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "petId"]
|
||||||
|
quantity: int32
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "quantity"]
|
||||||
|
ship_date: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "shipDate"]
|
||||||
(* Order Status *)
|
(* Order Status *)
|
||||||
status: Enums.status option [@default None]; [@key "status"]
|
status: Enums.status
|
||||||
complete: bool option [@default None]; [@key "complete"]
|
option [@default
|
||||||
|
|
||||||
|
None
|
||||||
|
]
|
||||||
|
; [@key "status"]
|
||||||
|
complete: bool
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "complete"]
|
||||||
} [@@deriving yojson { strict = false }, show ];;
|
} [@@deriving yojson { strict = false }, show ];;
|
||||||
|
|
||||||
(** An order for a pets from the pet store *)
|
(** An order for a pets from the pet store *)
|
||||||
|
@ -7,13 +7,34 @@
|
|||||||
*)
|
*)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
id: int64 option [@default None]; [@key "id"]
|
id: int64
|
||||||
category: Category.t option [@default None]; [@key "category"]
|
|
||||||
name: string; [@key "name"]
|
option [@default None]
|
||||||
photo_urls: string list; [@key "photoUrls"]
|
|
||||||
tags: Tag.t list; [@key "tags"]
|
; [@key "id"]
|
||||||
|
category: Category.t
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "category"]
|
||||||
|
name: string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; [@key "name"]
|
||||||
|
photo_urls: string list
|
||||||
|
|
||||||
|
; [@key "photoUrls"]
|
||||||
|
tags: Tag.t list
|
||||||
|
[@default []]
|
||||||
|
; [@key "tags"]
|
||||||
(* pet status in the store *)
|
(* pet status in the store *)
|
||||||
status: Enums.pet_status option [@default None]; [@key "status"]
|
status: Enums.pet_status
|
||||||
|
option [@default
|
||||||
|
|
||||||
|
None
|
||||||
|
]
|
||||||
|
; [@key "status"]
|
||||||
} [@@deriving yojson { strict = false }, show ];;
|
} [@@deriving yojson { strict = false }, show ];;
|
||||||
|
|
||||||
(** A pet for sale in the pet store *)
|
(** A pet for sale in the pet store *)
|
||||||
|
@ -7,8 +7,16 @@
|
|||||||
*)
|
*)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
id: int64 option [@default None]; [@key "id"]
|
id: int64
|
||||||
name: string option [@default None]; [@key "name"]
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "id"]
|
||||||
|
name: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "name"]
|
||||||
} [@@deriving yojson { strict = false }, show ];;
|
} [@@deriving yojson { strict = false }, show ];;
|
||||||
|
|
||||||
(** A tag for a pet *)
|
(** A tag for a pet *)
|
||||||
|
@ -7,15 +7,47 @@
|
|||||||
*)
|
*)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
id: int64 option [@default None]; [@key "id"]
|
id: int64
|
||||||
username: string option [@default None]; [@key "username"]
|
|
||||||
first_name: string option [@default None]; [@key "firstName"]
|
option [@default None]
|
||||||
last_name: string option [@default None]; [@key "lastName"]
|
|
||||||
email: string option [@default None]; [@key "email"]
|
; [@key "id"]
|
||||||
password: string option [@default None]; [@key "password"]
|
username: string
|
||||||
phone: string option [@default None]; [@key "phone"]
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "username"]
|
||||||
|
first_name: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "firstName"]
|
||||||
|
last_name: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "lastName"]
|
||||||
|
email: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "email"]
|
||||||
|
password: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "password"]
|
||||||
|
phone: string
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "phone"]
|
||||||
(* User Status *)
|
(* User Status *)
|
||||||
user_status: int32 option [@default None]; [@key "userStatus"]
|
user_status: int32
|
||||||
|
|
||||||
|
option [@default None]
|
||||||
|
|
||||||
|
; [@key "userStatus"]
|
||||||
} [@@deriving yojson { strict = false }, show ];;
|
} [@@deriving yojson { strict = false }, show ];;
|
||||||
|
|
||||||
(** A User who is purchasing from the pet store *)
|
(** A User who is purchasing from the pet store *)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user