[Swift3] Array Model Error in Generated Code (v2.3.0)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 65/100
Línea de trabajo
Comience con modules/swagger-codegen/src/main/resources/swift3/Models.mustache e inspeccione la sección del decodificador controlada por isArrayModel. Genere código Swift 3 a partir de una API que contenga un modelo de array y, después, compile el modelo resultante en Xcode. Se considera terminado cuando el archivo generado del modelo de array compila sin errores de retorno anticipado y la generación normal de modelos sigue intacta.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Mustache
- Estrellas
- 17.8k
- Forks
- 6k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de swagger-api/swagger-codegen
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
swagger-api/swagger-codegen#12755 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
swagger-api/swagger-codegen#11942 ·
-
[JAVA] Non compilable enums generated with property errorOnUnknownEnum=truePosiblemente ocupada @HiagoW la tomó hace 1450 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
swagger-api/swagger-codegen#11812 · 1 reacción ·
-
security vulnerability
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
swagger-api/swagger-codegen#11594 ·
Todos los issues de swagger-api/swagger-codegen
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
mksglu/context-mode#1268 ·
Los mantenedores suelen responder en 5 días
-
[bug] Setup fails with "Cannot find matching keyid" when an older Node's corepack is on PATHPosiblemente ocupada @EyalPoly la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
feedback simulation workshop
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
githubnext/gh-aw-workshop#4249 ·
Los mantenedores suelen responder en 1 día
-
Area/Debugger Priority/High Team/DevTools Type/Bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
ballerina-platform/ballerina-lang#44778 ·
Los mantenedores suelen responder en 1 día
-
dx hacktoberfest help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día