Created by: kvn-stgl
This is almost the same PR as #9159 but it also adds support for sealed classes together with moshi. It will also resolve the issue #8059. I created a separate PR because the changes of my old PR are mostly in the templates (and straight forward). I think this one is a bit more complex, so it make sense to merge the other one first.
Currently it's not possible to use Kotlin and Moshi with the oneOf-Keyword. I tried to implement the PolymorphicJsonAdapterFactory
to support this feature.
The reason why I set the target branch to master
is because the current strategy will fail during runtime (it's not allowed with moshi to serialize a interface directly).
I tested it with the following config:
generatorName: kotlin
outputDir: samples/client/3_0/kotlin-retrofit2-moshi-polymorphic
library: jvm-retrofit2
inputSpec: modules/openapi-generator/src/test/resources/3_0/allOf.yaml
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
additionalProperties:
serializationLibrary: moshi
artifactId: kotlin-retrofit2-moshi-polymorphic
moshiCodeGen: true
useSealedClass: true
Saddly in the current petstore samples are no discriminator, that's why I didn't add a sample.
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
,5.1.x
,6.0.x
-
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
technical committee : @jimschubert @dr4ke616 @karismann @Zomzog @andrewemery @4brunu @yutaka0m