OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Dart-dio] AnyOf not processed correctly in query params

Open
#12,376 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

When generating Dart code with a schema that contains anyOf in the query params, the generated classes don't compile because of missing types in OpenAPI Generator CLI 6.0.0 (Snapshot 2022.05.13).

openapi-generator version

openapi-generator-cli-6.0.0-20220513.065916-158

OpenAPI declaration file content or url
"/my-endpoint": {
      "get": {
        "operationId": "list",
        "tags": ["My Endpoint"],
        "parameters": [
          {
            "in": "query",
            "name": "parentId",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "array",
                  "items": { "format": "uuid", "type": "string" }
                },
                { "format": "uuid", "type": "string" },
                { "type": "null" }
        ]}}],
}
Generation Details

The output that comes out is the following:

Future<Response<MyEndpointResponse>> list({ 
    AnyOfarrayUUIDnull? parentId,
    ...
    }) {}

The type AnyOfarrayUUIDnull? doesn't actually exist in the generated code, leading to code that doesn't compile.

Steps to reproduce
  1. Create a schema with anyOf in the query params
  2. Run java -cp openapi-generator-cli-6.0.0-20220513.065916-158.jar org.openapitools.codegen.OpenAPIGenerator generate -i <input_file.json> -g dart-io
  3. The resulting API file will have the incorrectly generated types in it
Related issues/PRs

I previously had this issue with bodies and enums as well. This was fixed in https://github.com/OpenAPITools/openapi-generator/issues/10930

Suggest a fix

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

Reproduce the issue with the OpenAPIGenerator entry point org.openapitools.codegen.OpenAPIGenerator and the documented dart-io command using the supplied schema. Inspect the Dart generator path responsible for query parameter types. Done means the generated API file no longer references the missing AnyOfarrayUUIDnull type and compiles successfully.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.