Skip to content

[Kotlin][Spring] use flag delegatePattern together with skipDefaultInterface#19212

Merged
wing328 merged 5 commits intoOpenAPITools:masterfrom
pstorch:kotlin_delegate_nodefaults_19211
Jul 23, 2024
Merged

[Kotlin][Spring] use flag delegatePattern together with skipDefaultInterface#19212
wing328 merged 5 commits intoOpenAPITools:masterfrom
pstorch:kotlin_delegate_nodefaults_19211

Conversation

@pstorch
Copy link
Contributor

@pstorch pstorch commented Jul 21, 2024

fix #19211 kotlin-spring flag delegatePattern together with skipDefaultInterface generates broken code

It internally splits the skipDefaultInterface into skipDefaultApiInterface and skipDefaultDelegateInterface depending on the delegatePattern option.

This way, if the delegatePattern is used, it keeps the Api interface complete (to be able to be used by the Controller class) and removes the default implementations on the Delegate interface instead.

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/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. @jimschubert, @dr4ke616, @karismann, @Zomzog, @andrewemery, @4brunu, @yutaka0m, @stefankoppier

…th skipDefaultInterface generates broken code
@@ -0,0 +1,14 @@
generatorName: kotlin-spring
outputDir: samples/server/petstore/kotlin-springboot-delegate-nodefaults
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i ran gradle build in this folder but got

wing3@MSI MINGW64 ~/Code/openapi-generator/samples/server/petstore/kotlin-springboot-delegate-nodefaults (pstorch-kotlin_delegate_nodefaults_19211)
$ gradle build
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :compileKotlin
e: C:\Users\wing3\Code\openapi-generator\samples\server\petstore\kotlin-springboot-delegate-nodefaults\src\main\kotlin\org\openapitools\api\PetApiController.kt: (10, 9): Platform declaration clash: The following declarations have the same JVM signature (getDelegate()Lorg/openapitools/api/PetApiDelegate;):
    fun `<get-delegate>`(): PetApiDelegate defined in org.openapitools.api.PetApiController
    fun getDelegate(): PetApiDelegate defined in org.openapitools.api.PetApiController
e: C:\Users\wing3\Code\openapi-generator\samples\server\petstore\kotlin-springboot-delegate-nodefaults\src\main\kotlin\org\openapitools\api\PetApiController.kt: (14, 5): Platform declaration clash: The following declarations have the same JVM signature (getDelegate()Lorg/openapitools/api/PetApiDelegate;):
    fun `<get-delegate>`(): PetApiDelegate defined in org.openapitools.api.PetApiController
    fun getDelegate(): PetApiDelegate defined in org.openapitools.api.PetApiController
e: C:\Users\wing3\Code\openapi-generator\samples\server\petstore\kotlin-springboot-delegate-nodefaults\src\main\kotlin\org\openapitools\api\StoreApiController.kt: (10, 9): Platform declaration clash: The following declarations have the same JVM signature (getDelegate()Lorg/openapitools/api/StoreApiDelegate;):
    fun `<get-delegate>`(): StoreApiDelegate defined in org.openapitools.api.StoreApiController
    fun getDelegate(): StoreApiDelegate defined in org.openapitools.api.StoreApiController
e: C:\Users\wing3\Code\openapi-generator\samples\server\petstore\kotlin-springboot-delegate-nodefaults\src\main\kotlin\org\openapitools\api\StoreApiController.kt: (14, 5): Platform declaration clash: The following declarations have the same JVM signature (getDelegate()Lorg/openapitools/api/StoreApiDelegate;):
    fun `<get-delegate>`(): StoreApiDelegate defined in org.openapitools.api.StoreApiController
    fun getDelegate(): StoreApiDelegate defined in org.openapitools.api.StoreApiController
e: C:\Users\wing3\Code\openapi-generator\samples\server\petstore\kotlin-springboot-delegate-nodefaults\src\main\kotlin\org\openapitools\api\UserApiController.kt: (10, 9): Platform declaration clash: The following declarations have the same JVM signature (getDelegate()Lorg/openapitools/api/UserApiDelegate;):
    fun `<get-delegate>`(): UserApiDelegate defined in org.openapitools.api.UserApiController
    fun getDelegate(): UserApiDelegate defined in org.openapitools.api.UserApiController
e: C:\Users\wing3\Code\openapi-generator\samples\server\petstore\kotlin-springboot-delegate-nodefaults\src\main\kotlin\org\openapitools\api\UserApiController.kt: (14, 5): Platform declaration clash: The following declarations have the same JVM signature (getDelegate()Lorg/openapitools/api/UserApiDelegate;):
    fun `<get-delegate>`(): UserApiDelegate defined in org.openapitools.api.UserApiController
    fun getDelegate(): UserApiDelegate defined in org.openapitools.api.UserApiController

can you please take a look when you've time?

can you also add the new folder to the workflow file: https://github.com/OpenAPITools/openapi-generator/blob/master/.github/workflows/samples-kotlin-server.yaml#L34 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I've fixed it.

@pstorch pstorch requested a review from jimschubert as a code owner July 22, 2024 08:14
class {{classname}}Controller(
@org.springframework.beans.factory.annotation.Autowired(required = false) delegate: {{classname}}Delegate?
{{#skipDefaultDelegateInterface}}private val delegate: {{classname}}Delegate{{/skipDefaultDelegateInterface}}
{{^skipDefaultDelegateInterface}}delegate: {{classname}}Delegate?{{/skipDefaultDelegateInterface}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please refactor to

        {{#skipDefaultDelegateInterface}}
        private val delegate: {{classname}}Delegate
        {{/skipDefaultDelegateInterface}}
        {{^skipDefaultDelegateInterface}}
        delegate: {{classname}}Delegate?
        {{/skipDefaultDelegateInterface}}

to avoid empty line break

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@wing328 wing328 merged commit 0e70d1f into OpenAPITools:master Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][Kotlin][Spring] Use flag delegatePattern together with skipDefaultInterface generates broken code

2 participants