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:
- The generated spec file has invalid syntax when the podSource is provided
- 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.