Created by: parachutemind
PR checklist
- [x ] Read the contribution guidelines.
- [ - ] Ran the shell script under
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/kotlin-client-petstore.sh
,./bin/openapi3/kotlin-client-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first. - [ x] Filed the PR against the correct branch:
master
,4.1.x
,5.0.x
. Default:master
. - [ x] Copied the technical committee to review the pull request if your PR is targeting a particular programming language. -
@jimschubert
@dr4ke616
@karismann @Zomzog
Description of the PR
Summary of changes:
- Added a new 'serializationEngine' option for config.json with 2 valid values: "moshi" (default) and "gson"
- updated to kotlin-client mustache templates to support gson's @SerializedName annotation - this also helps with proguard which can break JSON binding to object in release code
- removed empty {} in the data class body when there is no enums - this fixes annoying visual indicators of empty body in Android Studio IDE when looking at data classes without enums.
Testing:
Test 1
mvn clean install ./bin/kotlin-client-petstore.sh cd samples/client/petstore/kotlin gradle wrapper; ./gradlew check assemble test success
Test 2
./bin/kotlin-client-petstore.sh --additional-properties serializationEngine=gson cd samples/client/petstore/kotlin gradle wrapper; ./gradlew check assemble test success
Test 3
./bin/kotlin-client-petstore.sh --additional-properties serializationEngine=foobar verified proper error message is displayed:
Exception in thread "main" java.lang.RuntimeException: foobar is an invalid enum property naming option. Please choose from:
moshi
gson
at org.openapitools.codegen.languages.AbstractKotlinCodegen.setSerializationEngine(AbstractKotlinCodegen.java:286)
at org.openapitools.codegen.languages.AbstractKotlinCodegen.processOpts(AbstractKotlinCodegen.java:360)
at org.openapitools.codegen.languages.KotlinClientCodegen.processOpts(KotlinClientCodegen.java:122)
at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:194)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:910)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:400)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Test 4
./bin/openapi3/kotlin-client-petstore.sh cd samples/openapi3/client/petstore/kotlin/ gradle wrapper; ./gradlew check assemble test
Unfortunately, I run into the following error when running the tests above against openapi3. I don't believe this is due to my changes. It seems to be broken in master as well...
> Task :compileKotlin FAILED
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt: (338, 114): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Array<String>?
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt: (339, 150): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Array<String>?
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/FakeApi.kt: (339, 176): Unresolved reference: collectionDelimiter
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumArrays.kt: (44, 1): Expecting a top level declaration
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumArrays.kt: (44, 1): Conflicting overloads: public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumArrays.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file InlineObject2.kt
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumArrays.kt: (44, 1): Function declaration must have a name
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumArrays.kt: (27, 44): Unresolved reference: ArrayEnum
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumArrays.kt: (49, 5): Modifier 'enum' is not applicable to 'local class'
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (74, 1): Expecting a top level declaration
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (74, 1): Conflicting overloads: public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumArrays.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file InlineObject2.kt
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (74, 1): Function declaration must have a name
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (90, 1): Expecting a top level declaration
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (90, 1): Conflicting overloads: public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumArrays.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file InlineObject2.kt
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (90, 1): Function declaration must have a name
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (104, 1): Expecting a top level declaration
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (104, 1): Conflicting overloads: public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumArrays.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file InlineObject2.kt
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (104, 1): Function declaration must have a name
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (34, 38): Unresolved reference: EnumStringRequired
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (40, 31): Unresolved reference: EnumInteger
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (43, 30): Unresolved reference: EnumNumber
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (79, 5): Modifier 'enum' is not applicable to 'local class'
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (95, 5): Modifier 'enum' is not applicable to 'local class'
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (97, 22): The integer literal does not conform to the expected type String
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (99, 22): Type mismatch: inferred type is Int but String was expected
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (109, 5): Modifier 'enum' is not applicable to 'local class'
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (111, 22): The floating-point literal does not conform to the expected type String
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/EnumTest.kt: (113, 22): Type mismatch: inferred type is Double but String was expected
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/InlineObject2.kt: (46, 1): Expecting a top level declaration
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/InlineObject2.kt: (46, 1): Conflicting overloads: public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumArrays.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file EnumTest.kt, public fun <no name provided>(): Unit defined in org.openapitools.client.models in file InlineObject2.kt
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/InlineObject2.kt: (46, 1): Function declaration must have a name
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/InlineObject2.kt: (29, 39): Unresolved reference: EnumFormString
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/InlineObject2.kt: (51, 5): Modifier 'enum' is not applicable to 'local class'
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/MapTest.kt: (45, 37): Type mismatch: inferred type is String but Map<String, String> was expected
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/MapTest.kt: (47, 37): Type mismatch: inferred type is String but Map<String, String> was expected
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/SpecialModelname.kt: (21, 18): An annotation argument must be a compile-time constant
e: .../openapi-generator/samples/openapi3/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/models/SpecialModelname.kt: (21, 20): Unresolved reference: special
Fixes #3414 (closed)