Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: OpenAPI generator for kotlin #1254

Merged
merged 18 commits into from
Nov 2, 2023

Conversation

altro3
Copy link
Collaborator

@altro3 altro3 commented Oct 15, 2023

No description provided.

# Conflicts:
#	openapi-generator/src/main/java/io/micronaut/openapi/generator/JavaAbstractMicronautCodegen.java
#	openapi-generator/src/test/java/io/micronaut/openapi/generator/MicronautClientCodegenTest.java
# Conflicts:
#	openapi-generator/src/main/java/io/micronaut/openapi/generator/JavaAbstractMicronautCodegen.java
#	openapi-generator/src/test/java/io/micronaut/openapi/generator/MicronautClientCodegenTest.java
@altro3 altro3 changed the title New feature: OpaenAPI generator for kotlin New feature: OpenAPI generator for kotlin Oct 15, 2023
@altro3
Copy link
Collaborator Author

altro3 commented Oct 15, 2023

@graemerocher don't know how to fix binary comatibility problems. Also I found bug with micronaut-core for kotlin - optional QueryValues are always required. And validation doesn't work for controller parameters

# Conflicts:
#	openapi-generator/src/main/java/io/micronaut/openapi/generator/AbstractMicronautJavaCodegen.java
#	openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java
@altro3
Copy link
Collaborator Author

altro3 commented Oct 19, 2023

@andriy-dmytruk @graemerocher please, look to this. Generator wotks fine, but some tests with validation now disabled, because this is a bug of core or validation library. But code generator for kotlin works fine

{{#model}}
{{^vendorExtensions.x-is-one-of-interface}}
{{^isEnum}}
val model: {{classname}}? = null
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is injected would be better as a constructor argument

Copy link
Collaborator Author

@altro3 altro3 Oct 21, 2023

Choose a reason for hiding this comment

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

Can' t do it

Initialization exception. Must be single constructor, but we have 2 constructors

изображение

{{>common/generatedAnnotation}}
{{/generatedAnnotation}}
@EachProperty("security.basic-auth")
open class HttpBasicAuthConfiguration @ConfigurationInject constructor(
Copy link
Contributor

Choose a reason for hiding this comment

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

can be made a data class in which case @ConfigurationInject is not needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@Target(FUNCTION)
@Bindable
@Repeatable
annotation class Authorization(
Copy link
Contributor

Choose a reason for hiding this comment

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

in general I am wondering why we don't upstream more of this annotation/filter logic

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know, that's what was in the java generator. I just converted this to kotlin

@altro3
Copy link
Collaborator Author

altro3 commented Oct 21, 2023

@graemerocher about you question: I don’t see any problems with generating code in Kotlin, but implementing interfaces in Java. I fixed what you didn't like - now all tests for Kotlin are written in Kotlin.

But! Thanks to the fact that I initially wrote tests in Java, I was able to find validation bugs if I mixed Java and Kotlin in one project. I’m not sure if this is popular, but I don’t understand why some of the methods work correctly, while others give errors in this case

@andriy-dmytruk
Copy link
Contributor

I feel like there is too much duplication between Kotlin & Java.
I want to take a look at whether we can avoid that and will try to get back to you some day this week.

@altro3
Copy link
Collaborator Author

altro3 commented Oct 24, 2023

@andriy-dmytruk I did this on purpose for a specific reason:

I don’t want the generator code for Kotlin to affect an already existing generator for Java (the same is done in the openapi generator itself). Yes, there are duplicates, but you can be sure that if you correct the logic for Kotlin, you will not change the logic for Java and vice versa.

Unfortunately, no solution will be perfect. Excessive unification always leads to more complex code and potential problems in the future.

@altro3
Copy link
Collaborator Author

altro3 commented Oct 31, 2023

@andriy-dmytruk @graemerocher Could you merge it?

@graemerocher graemerocher added the type: enhancement New feature or request label Nov 2, 2023
@graemerocher graemerocher merged commit bca51f3 into micronaut-projects:master Nov 2, 2023
6 checks passed
@graemerocher
Copy link
Contributor

@altro3 Thanks for the contribution again. I think you can probably do a release, you don't need to wait for 4.2

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants