Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][OCaml] Incorrect support of JSON fields not in snake_case #20765

Closed
4 of 6 tasks
sir4ur0n opened this issue Feb 28, 2025 · 0 comments · Fixed by #20766
Closed
4 of 6 tasks

[BUG][OCaml] Incorrect support of JSON fields not in snake_case #20765

sir4ur0n opened this issue Feb 28, 2025 · 0 comments · Fixed by #20766

Comments

@sir4ur0n
Copy link
Contributor

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

When JSON fields are not in snake_case (e.g., someField), parsing fails because the field is expected to be named some_field).

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

The generator uses ppx_deriving_yojson which supports an annotation [@key "someField"].
See https://github.com/ocaml-ppx/ppx_deriving_yojson?tab=readme-ov-file#key

I think a simple solution is to add this annotation on every single field

sir4ur0n added a commit to sir4ur0n/openapi-generator that referenced this issue Feb 28, 2025
Add a `[@key "someField"]` annotation to each model field, to avoid mismatches when the JSON field is not in snake_case.

Closes OpenAPITools#20765
wing328 added a commit that referenced this issue Mar 4, 2025
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant