OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Haskell-http-client] `anyOf` generates bad type names

Open
#10,352 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

The haskell-http-client generator doesn't handle the use of anyOf in an OpenAPI v3 spec properly. Trying to use anyOf will lead to malformed code which uses type name that don't exist, and will fail to compile.

openapi-generator version

Found on latest master: 2239ca36fdcedd865a3d9ccd3381f5031cdf8dbe.

OpenAPI declaration file content or url

Gist here: https://gist.github.com/ivanbakel/cbf8a00b30cbe71ca0fe86a5c9c44a18

Generation Details

I ran

generate -i ... -o ... -g haskell-http-client

with the above file (in the gist).

Steps to reproduce
  1. Generate the Haskell HTTP client code from the above file.
  2. Try to compile it.
  3. Get an error that AnyOfFooBar is not a type
Related issues/PRs

May be related to #2968, which is a similar issue where a Haskell-based code generator produces malformed type names when using anyOf.

Suggest a fix

It looks like AnyOf simply isn't supported in the haskell-http-client schema at the moment. That would be very hard to fix, but ideally the above case, where there's an anyOf with a single child, could be simplified to just use that child type. So AnyOfFooBar in the above generated code would become just FooBar, since that's the only type in the anyOf.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the OpenAPI declaration in the linked Gist and run the reported generate -i ... -o ... -g haskell-http-client command. Inspect the generated Haskell client and its compilation error for the anyOf case, then verify that the resulting type names match the available types and the generated client compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.