Skip to content

[BUG][OCaml] Optional list fields are wrongly required #20777

@sir4ur0n

Description

@sir4ur0n

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Fields of type array which are not required fail to parse when absent.
E.g., the type IntegrationDto has an optional field dependencies:

          "dependencies": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },

The generated OCaml field is

dependencies : Yojson.Safe.t list;

Thus, when parsing a JSON without this field, it fails.

openapi-generator version

7.10.0

OpenAPI declaration file content or url

https://api.integration.app/docs-json

Generation Details
$ openapi-generator-cli generate \
  --generator-name ocaml \
  --input-spec docs-json
Steps to reproduce
$ openapi-generator-cli generate \
  --generator-name ocaml \
  --input-spec docs-json
Related issues/PRs

N/a.

Suggest a fix

I think when the field is optional and of type 'a list, there should be a default value of [].
E.g.,

dependencies : Yojson.Safe.t list; [@default []]

Note that the create function already honors this optionality: the field dependencies is not an argument to this function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions