[Swift3] Array Model Error in Generated Code (v2.3.0)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 65/100
Direzione di ricerca
Inizia da modules/swagger-codegen/src/main/resources/swift3/Models.mustache e ispeziona la sezione del decoder controllata da isArrayModel. Genera codice Swift 3 da un’API contenente un modello array, quindi compila il modello risultante in Xcode. Il lavoro è completato quando il file generato del modello array viene compilato senza errori dovuti a ritorni anticipati e la normale generazione dei modelli rimane intatta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Mustache
- Stelle
- 17.8k
- Fork
- 6k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di swagger-api/swagger-codegen
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
swagger-api/swagger-codegen#12755 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
swagger-api/swagger-codegen#11942 ·
-
[JAVA] Non compilable enums generated with property errorOnUnknownEnum=trueForse già presa @HiagoW l’ha presa 1450 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
swagger-api/swagger-codegen#11812 · 1 reazione ·
-
security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
swagger-api/swagger-codegen#11594 ·
Tutte le issue di swagger-api/swagger-codegen
Issue simili
-
dx hacktoberfest help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
sync-en
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 3 giorni
-
enhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
helidon-io/helidon#12721 ·
I maintainer di solito rispondono entro 1 giorno
-
status: team-only type: dependency-upgrade
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
spring-projects/spring-boot#51966 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement needs-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno