OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Swift6]: no preserving casing causes model overlaping

Open
#22,073 1 comment 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?
  • 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

Casing is causing some troubles when generating the Models. I tried many of the provided options but none worked.

The generator is pascalCasing everything, that means multiple casing could ends in the same property in the Model struct.

For example if the api respond with:

{
    "name": "book",
    "author": "the-id",
    "Author":{
        "id": "the-id",
        "name": "Good author"
    }
}

The model Book wont compile because it will generate a model with two "author" properties. Because

  1. author -> author
  2. Author -> author

And that forces to make backend changes, and sometimes that is not possible

openapi-generator version

according with version manager: 7.17
according with package.json: 2.23.4

Not sure how to check the generator version

OpenAPI declaration file content or url

Cant share due NDA

Generation Details

generatorName: swift6
inputSpec: swagger/openapi.yaml
outputDir: ./artifacts/MyAppbackendclient-swift
modelNameMappings:
Calendar: CalendarModel
ValidationError: APIValidationError
useJsonNamingConvention: false
additionalProperties:
projectName: MyAppBackendApi
swiftPackagePath: MyAppBackendApi
apiNamePrefix: MyApp
swiftUseApiNamespace: true
useSPMFileStructure: true

Suggest a fix

The problem is the casing, so if you add a flag to disable the forcing case it will be fine

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 swift6 generator entry point and the model generation path, using the reported generatorName, inputSpec path swagger/openapi.yaml, and useJsonNamingConvention setting as context. Reproduce with an OpenAPI schema containing both author and Author properties, then verify that generated Swift models compile without collapsing distinct property names.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, swift
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.