OpenAPITools / OpenAPITools/openapi-generator

[BUG][dart-dio]: EnumClass conflict when using 'name' in a enum component

Open
#20,910 2 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

We encountered a conflict in a class where a static member and an instance member are defined with the same name ('name'). Dart does not allow a class to define a static member 'name' and have an instance member 'EnumClass.name' with the same name.

Class 'OrderBy' can't define static member 'name' and have instance member 'EnumClass.name' with the same name.
Try renaming the member to a name that doesn't conflict.dart(conflicting_static_and_instance)
openapi-generator version

v7.12.0

OpenAPI declaration file content or url
---
openapi: 3.0.3
info:
  title: Test
  version: 1.0.0-SNAPSHOT
paths:
  /test:
    get:
      parameters:
        - name: order_by
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/OrderBy'
      responses:
        "200":
          description: OK
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                name:
                  type: string
              required:
                - username
                - name
      responses:
        "200":
          description: OK
        "400":
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'

components:
  schemas:
    OrderBy:
      type: string
      enum:
        - name
        - username
    ValidationErrorResponse:
      type: object
      properties:
        attr:
          enum:
          - name
          - username
          type: string
          description: The attribute that caused the validation error

Generation Details

docker run --rm -v ./test_code:/local openapitools/openapi-generator-cli:v7.12.0 generate -i ${OPENAPI_YML} -g dart-dio -o /local/

Steps to reproduce
Related issues/PRs
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

Start by running the provided docker generation command with the OpenAPI YAML and inspect the generated dart-dio OrderBy enum. Trace the generator entry point for Dart enum components; done means the generated Dart code no longer defines conflicting static and instance members for the name enum value and remains valid for the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.