Skip to content

[BUG] [dart][dart-dio] generator doesn't supported nested schemas whose name contains the word "List" or "Map" #4865

@coreysprague

Description

@coreysprague

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? master
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

In my project's yaml we rely heavily on component schemas for re-using data structures. In our domain, we also use the term "Listing" as one of our primary entities.

When generating with the dart-dio generator, there is a string replace (introduced here: https://github.com/OpenAPITools/openapi-generator/pull/4018/files#diff-76962401fd8881ac1ddf6cb5e64909c5R206) that over-eagerly replaces all occurrences of "List" in the type name with "BuiltList". It unfortunately will do something like the following:

Instead of:
BuiltList<Listing>
we get
BuiltList<BuiltListing>

Thankfully, this is a compilation error and it is a trivial search/replace to post-process, but it is an unexpected trap.

openapi-generator version

dart-dio (tried 4.2.2 and master)

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Sample API
  version: 0.1.9
servers:
  - url: http://api.example.com/v1
    description: Optional server description, e.g. Main (production) server
paths:
  /listings:
    get:
      summary: Returns a collection of listings.
      responses:
        "200": # status code
          description: An array of listings
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ListingCollection"
components:
  schemas:
    ListingCollection:
      type: object
      properties:
        totalResults:
          type: number
        offset:
          type: number
        pageNumber:
          type: number
        listings:
          type: array
          items:
            $ref: "#/components/schemas/Listing"
    Listing:
      type: object
      properties:
        name:
          type: string
Command line used for generation

vanilla generation using the dart-dio template

Steps to reproduce

Your yaml must have a model class that contains a list of types who name contains the word List.

Note: I suspect the same issue can occur with Map/BuiltMap, but did not run into that use case

Suggest a fix

I think the replace may be able to be more targeted. Instead of replacing List, perhaps it could replace List<

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions