Swagger-codegen: [Kotlin] Improve client generator functionality

Created on 29 May 2017  路  5Comments  路  Source: swagger-api/swagger-codegen

Description

This is a tracking issue for adding functionality to the Kotlin client generator.

  • [ ] Support "default" responses. Currently 200 OK isn't handled, for example, in PetApi#addPet. Revisit this. It appears to be an issue with the petstore.yaml used by most generators, which doesn't define a 200 or "default" response for PetApi#addPet.
  • [x] Support enum type generation (see #5769)
  • [x] Support inline/embedded enums (see #5769)
  • [ ] Add model tests for top-level enums and inline/embedded enums
  • [x] Support collectionFormat (multi) (see #5792)
  • [ ] Test/Implement arrays of maps, arrays, objects
  • [ ] Test/Implement maps of arrays/maps, objects
  • [ ] Support allOf via composition
  • [ ] Support allOf via inheritance
  • [ ] (optional?) Per-request modification of headers,authorization

    • NOTE: ApiClient.defaultHeaders can be modified once to globally set headers for auth, user-agent, etc.

    • [ ] Test, or better implement basic auth support

    • [ ] Test, or better implement OAuth support

    • [ ] Test, or better implement apiKey auth

  • [ ] Generate Api tests
  • [ ] Generate Model tests
  • [x] Generate Api docs (see #5731)
  • [x] Generate Model docs (see #5731)
  • [x] Update README.md to be more project-specific rather than generic information about the generator/template (see ##5731)
  • [ ] Consider an option for android targeting (--additional-properties=android=true), to use built-in serialization and other features
  • [ ] Add support for Retrofit library (Ref: https://github.com/swagger-api/swagger-codegen/issues/6368)
  • [ ] Add an option to select date library (Ref: #6892)
Related issues

  • #5071
Kotlin General help wanted

Most helpful comment

Any plans for using async ?

All 5 comments

+1 set defaultHeaders

Any plans for using async ?

Add support for Retrofit library

+1

supposedly this branch has successfully spat out kotlin + retrofit
https://github.com/kroegerama/kotlin-retrofit-generated/blob/master/petstore/src/main/java/com/kroegerama/petstore/RetrofitHolder.kt

using this branch https://github.com/kroegerama/openapi-generator/tree/kotlin-retrofit
@kroegerama

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate  \
   -i openapi.json \
   -g kotlin  --library=retrofit \
   -o kotlin_client
Exception in thread "main" java.lang.RuntimeException: Unknown library: retrofit
Available libraries:
  NONE
    at org.openapitools.codegen.DefaultCodegen.setLibrary(DefaultCodegen.java:3802)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:566)
    at org.openapitools.codegen.cmd.Generate.run(Generate.java:395)
    at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)

but I'm not clear which parameters were invoked to get retrofit library working.

UPDATE - working!


git clone https://github.com/kroegerama/openapi-generator 
git checkout kotlin-retrofit 
mvn clean install

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate  \
   -i openapi.json \
   -g kotlin-retrofit \
   -o kotlin_retro

For those coming for kotlin basic auth, I made my kotlin client authenticate adding an interceptor globally:

        ApiClient.builder.addInterceptor {
            val request = it.request()
            val authenticatedRequest = request
                .newBuilder()
                .header("Authorization", Credentials.basic(user, pass)).build()
            it.proceed(authenticatedRequest)
        }

It's not as straightforward as the java client where you just have to call setUser and setPass methods.
Also this method allows to set just the interceptors once and then you can never changed them again.

Was this page helpful?
0 / 5 - 0 ratings