OpenAPITools / OpenAPITools/openapi-generator

[BUG][Swift] type-mappings with a dot doesn't work without modelNamePrefix

Open
#15,927 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

I'm trying to use a reference to a shared external module with the type-mappings option. Unfortunately, dot character seems to be discarded except if modelNamePrefix is also defined.
It might be an expected behaviour, but I couldn't figure it out from the documentation, so I'm assuming this is rather an issue.

openapi-generator version

6.6.0

OpenAPI declaration file content or url

https://gist.github.com/jrmybrault/838da0557d6851bea3fb672e4384e342

Generation Details

WITH a modelNamePrefix

openapi-generator generate \
-g swift5 \
-i Contracts/get-user.yml \
-o ../Generated/GetUser/ \
-c openapi-generator-config.yml \
-t custom-templates \
--global-property models,apis,supportingFiles=false,apiDocs=false,modelDocs=false,apiTests=false,modelTests=false \
--additional-properties=projectName=GetUserAPI,modelNamePrefix=GetUserAPI \
--type-mappings=GetUserAPIIdentity=BackendServices.Identity
import BackendServices

public struct GetUserAPIUserInformation: Equatable, Codable {

    public let identity: BackendServices.Identity

    public init(identity: BackendServices.Identity) {
        self.identity = identity
    }
}

Now, WITHOUT a modelNamePrefix:

openapi-generator generate \
-g swift5 \
-i Contracts/get-user.yml \
-o ../Generated/GetUser/ \
-c openapi-generator-config.yml \
-t custom-templates \
--global-property models,apis,supportingFiles=false,apiDocs=false,modelDocs=false,apiTests=false,modelTests=false \
--additional-properties=projectName=GetUserAPI \
--type-mappings=Identity=BackendServices.Identity
import BackendServices

public struct UserInformation: Equatable, Codable {

    public let identity: BackendServicesIdentity

    public init(identity: BackendServicesIdentity) {
        self.identity = identity
    }
}

Notice the dot character has been discarded, thus making the compiler search for a BackendServicesIdentity type that doesn't exist, instead of looking for an Identity type within the BackendServices module.
Adding quotes or an escape character doesn't seem to make a difference.

Steps to reproduce

Just use commands mentioned above.

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 reproducing the two swift5 generation commands using Contracts/get-user.yml, openapi-generator-config.yml, and the custom-templates directory. Compare generated Swift output with and without modelNamePrefix, then trace the type-mappings handling. Done means a dotted mapping such as BackendServices.Identity remains qualified without modelNamePrefix.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
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.