[Swift3] Array Model Error in Generated Code (v2.3.0)
まだ誰も着手していません。
評価
調査の方向性
modules/swagger-codegen/src/main/resources/swift3/Models.mustache から始め、isArrayModel によって制御されるデコーダーセクションを調べます。配列モデルを含む API から Swift 3 コードを生成し、生成されたモデルを Xcode でコンパイルします。完了条件は、生成された配列モデルのファイルが早期 return エラーなしでコンパイルでき、通常のモデル生成もそのまま維持されることです。
索引モデルが issue の本文から書いたものです。
説明
Description
There seems to be an error in generated Swift 3 code being created in version 2.3.0 due to the placement of a return statement at the beginning of the "isArrayModel" section in the default Swift 3 Models.mustache file.
The effect of this is that generated Swift 3 model code does not correctly compile when an array model is being used. I noticed this while generating Swift code for an in-house API using the version 2.3.0 branch. Our API does use an array model, hence the triggering of this error.
Swagger-codegen version
2.3.0
Steps to reproduce
To reproduce this, run Swagger Codegen V2.3.0 against an API which uses an array model. The resulting Swift model file will not compile in Xcode due to early return statements.
Suggest a Fix
It looks like the fix for this should be fairly simple and to edit the following section of the default Swift 3 Models.mustache file to edit the following section:
{{^isArrayModel}}
// Decoder for [{{{classname}}}]
return Decoders.decode(clazz: [{{{classname}}}].self, source: source, instance: instance)
}
// Decoder for {{{classname}}}
Decoders.addDecoder(clazz: {{{classname}}}.self) { (source: AnyObject, instance: AnyObject?) -> Decoded<{{{classname}}}> in
{{#isEnum}}
...
To add the decoder declaration for an array type as follows (giving the return statement a closure to return from):
{{^isArrayModel}}
// Decoder for [{{{classname}}}]
Decoders.addDecoder(clazz: [{{{classname}}}].self) { (source: AnyObject, instance: AnyObject?) -> Decoded<[{{{classname}}}]> in
return Decoders.decode(clazz: [{{{classname}}}].self, source: source, instance: instance)
}
// Decoder for {{{classname}}}
Decoders.addDecoder(clazz: {{{classname}}}.self) { (source: AnyObject, instance: AnyObject?) -> Decoded<{{{classname}}}> in
{{#isEnum}}
...
I have trialled this within the app I am working on and this seems to fix the issue. I can raise a PR for this if it would be useful. It would be useful to know if this change has a wider impact, or if this is simply a bug in the template. The same issue does not appear in the current master version of swagger-codegen, but it does seem as if there have been some changes made to the Swift template for the 2.3.0 version.
I am using the 2.3.0 version as it supports the ability to retrieve data payloads from API errors via the ErrorResponse enum, and therefore fixing this issue is pretty important for our project (we are currently using a branched version with the fix outlined above in place.
- 主要言語
- Mustache
- スター
- 17.8k
- フォーク
- 6k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
swagger-api/swagger-codegen のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
swagger-api/swagger-codegen#12755 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
swagger-api/swagger-codegen#11942 ·
-
[JAVA] Non compilable enums generated with property errorOnUnknownEnum=true対応中かも @HiagoW が 1450 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
swagger-api/swagger-codegen#11812 · リアクション 1 件 ·
-
security vulnerability
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
swagger-api/swagger-codegen#11594 ·
swagger-api/swagger-codegen の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
mksglu/context-mode#1268 ·
メンテナーはふだん 5 日以内に返信
-
[bug] Setup fails with "Cannot find matching keyid" when an older Node's corepack is on PATH対応中かも @EyalPoly が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
feedback simulation workshop
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
githubnext/gh-aw-workshop#4249 ·
メンテナーはふだん 1 日以内に返信
-
Area/Debugger Priority/High Team/DevTools Type/Bug
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
ballerina-platform/ballerina-lang#44778 ·
メンテナーはふだん 1 日以内に返信
-
dx hacktoberfest help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信