OpenAPITools / OpenAPITools/openapi-generator

[BUG] [dart-dio] _id is generated as id

Open
#14,482 5 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 a model a property _id is transformed and becomes id in the resulting dart class. In the provided example this breaks the class as it already has another id property.

I tested this on latest master with this command (hosting the yml on a public gist):

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
        -i https://gist.githubusercontent.com/flodaniel/65ffdf1e803773606dc42dccd58ba021/raw/7ce9e4e7721e1df9bb28c7d2de94581351f387ad/gistfile1.txt -g dart-dio -o /local/out/bad_id_generation
openapi-generator version

openapi-generator-cli 6.2.1
commit : b0ce532
built : 2022-11-01T09:40:00Z
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/

OpenAPI declaration file content or url

https://gist.github.com/flodaniel/65ffdf1e803773606dc42dccd58ba021

openapi: 3.0.0
info:
  title: Bad _id generation
  version: 0.0.1
paths: {}
tags: []
servers: []
components: 
  schemas:
    ConflictingIdProperty:
      type: object
      properties:
        id:
          type: string
        _id:
          type: string

Generation Details

openapi-generator generate -i ./bad_id_generation.yml -g dart-dio -o ./bad_id_generation

Steps to reproduce
  1. Run the generation
  2. review the resulting conflicting_id_property.dart file with the conflicting id properties.
Related issues/PRs
Suggest a fix

The issue is probably within class.mustache (https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class.mustache). baseName is correct but name is missing the _.

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 modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class.mustache, then reproduce the issue using the provided OpenAPI gist and dart-dio generation command. Review the generated conflicting_id_property.dart file; done means the _id and id properties remain distinct in the generated Dart class.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.