OpenAPITools / OpenAPITools/openapi-generator

[BUG] Unable to set `podSource` for Swift clients

Open
#5,479 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Swift 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)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

This issue impacts the Podspec template for the following generators:

  • Swift
  • Swift2
  • Swift3
  • Swift4
  • Swift5

Clients are unable to set the podspec source. This renders the generated Pod unusable by any Cocoapod consumers for two reasons:

  1. The generated spec file has invalid syntax when the podSource is provided
  2. If the podSource is not provided, the client location is set to the OpenAPITools repository, which is obviously incorrect since these are the generated clients and not part of the OpenAPITools project.

This issue is caused by issue #3874. I am opening a new bug report because this particular version of the issue can be remedied without fixing #3874 (which can be very complicated to address, and would impact all users).

openapi-generator version

Impacts v4 and the v5 branch

OpenAPI declaration file content or url
{"openapi":"3.0.0","info":{"title":"API","version":"0"}, "paths": {}}

This issue can occur with any OpenAPI declaration file.

Command line used for generation

java -jar openapi-generator-cli.jar generate -g swift4 -i empty.json -p "podSource={ :git => 'git@github.com:adamkaplan/myclient.git', :tag => 'v0' }"

Steps to reproduce

Using the command above, the generated output in OpenAPIClient.podspec is:

Pod::Spec.new do |s|
  s.name = 'OpenAPIClient'
  s.ios.deployment_target = '9.0'
  s.osx.deployment_target = '10.11'
  s.tvos.deployment_target = '9.0'
  s.version = '0'
  s.source = { :git => 'git@github.com:adamkaplan/myclient.git'
  s.authors = 'OpenAPI Generator'
  s.license = 'Proprietary'
  s.homepage = 'https://github.com/OpenAPITools/openapi-generator'
  s.summary = 'OpenAPIClient Swift SDK'
  s.source_files = 'OpenAPIClient/Classes/**/*.swift'
  s.dependency 'Alamofire', '~> 4.9.0'
end

In particular, the issue is on the source line:

Observed:
s.source = { :git => 'git@github.com:adamkaplan/myclient.git'
Expected:
s.source = { :git => 'git@github.com:adamkaplan/myclient.git', : tag => 'v0' }

The observed Podspec file is not parsable.

Related issues/PRs

The underlying problem is caused by Issue #3874

Suggest a fix

Fixing issue 3874 would suffice. However that issue is complicated. In practice, it is rare to need to override the entire podSource. Most Podspecs out there use a common syntax which varies only in the git repository URL:

s.source = { :git => 'git@github.com:MyOrg/MyProj.git', :tag => s.version.to_s }

The tag is typically set to s.version.to_s which is Ruby for "use the tag that matches the Pod version". Therefore, I suggest adding a template option named podSourceRepo which is a git-compatible specified like the one shown above. This would avoid the comma parsing issue and actually make using the Swift generators a bit easier for the majority of people.

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 provided openapi-generator CLI command and inspect the generated OpenAPIClient.podspec for the Swift, Swift2, Swift3, Swift4, and Swift5 generators. Compare the rendered s.source line with the expected git-and-tag syntax; done means the generated Podspec is valid and preserves both podSource values.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby, swift
Domain
mobile-dev, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.