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}}
|
||||
{{#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}}
|
||||
{{{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}}
|
||||
{{/vars}}
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
@ -7,9 +7,21 @@
|
||||
*)
|
||||
|
||||
type t = {
|
||||
code: int32 option [@default None]; [@key "code"]
|
||||
_type: string option [@default None]; [@key "type"]
|
||||
message: string option [@default None]; [@key "message"]
|
||||
code: int32
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "code"]
|
||||
_type: string
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "type"]
|
||||
message: string
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "message"]
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** Describes the result of uploading an image resource *)
|
||||
|
@ -7,8 +7,16 @@
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None]; [@key "id"]
|
||||
name: string option [@default None]; [@key "name"]
|
||||
id: int64
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "id"]
|
||||
name: string
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "name"]
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** A category for a pet *)
|
||||
|
@ -7,13 +7,38 @@
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None]; [@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"]
|
||||
id: int64
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@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 *)
|
||||
status: Enums.status option [@default None]; [@key "status"]
|
||||
complete: bool option [@default None]; [@key "complete"]
|
||||
status: Enums.status
|
||||
option [@default
|
||||
|
||||
None
|
||||
]
|
||||
; [@key "status"]
|
||||
complete: bool
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "complete"]
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** An order for a pets from the pet store *)
|
||||
|
@ -7,13 +7,34 @@
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None]; [@key "id"]
|
||||
category: Category.t option [@default None]; [@key "category"]
|
||||
name: string; [@key "name"]
|
||||
photo_urls: string list; [@key "photoUrls"]
|
||||
tags: Tag.t list; [@key "tags"]
|
||||
id: int64
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@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 *)
|
||||
status: Enums.pet_status option [@default None]; [@key "status"]
|
||||
status: Enums.pet_status
|
||||
option [@default
|
||||
|
||||
None
|
||||
]
|
||||
; [@key "status"]
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** A pet for sale in the pet store *)
|
||||
|
@ -7,8 +7,16 @@
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None]; [@key "id"]
|
||||
name: string option [@default None]; [@key "name"]
|
||||
id: int64
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "id"]
|
||||
name: string
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "name"]
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** A tag for a pet *)
|
||||
|
@ -7,15 +7,47 @@
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None]; [@key "id"]
|
||||
username: string 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"]
|
||||
id: int64
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "id"]
|
||||
username: string
|
||||
|
||||
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: int32 option [@default None]; [@key "userStatus"]
|
||||
user_status: int32
|
||||
|
||||
option [@default None]
|
||||
|
||||
; [@key "userStatus"]
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** A User who is purchasing from the pet store *)
|
||||
|
Loading…
x
Reference in New Issue
Block a user