-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add test for process KSP Json subtypes. See #768 #875
Conversation
@dstepanov Are you planned to fix it? I still have some tests disabled in micronaut openapi for KSP because of this bug :-( |
9755656
to
f3de53d
Compare
f3de53d
to
bd5c79a
Compare
@altro3 It works correctly, you need to have |
@dstepanov Then I have a question: why does this code work correctly with KAPT and java, but not only with KSP? |
@dstepanov You are wrong. The |
@dstepanov Tets should pass exactly with the configuration as I wrote. I think that KSP does not see the property |
Needs |
Well, that's a bug. Why do all other annotations work fine without the "field:" prefix, but only in this case does it not work without the prefix? |
@dstepanov As you see, in case withou prefix But why does the processing continue incorrectly? |
I think I understand what the problem is and it is clearly in the lkotlin introspection, that is, in the core module. In this case, the annotations specified in the superclass construct - Animal are ignored, but these annotations are also valid for fields. This was, among other things, the point of the KSP, to get rid of these stupid "field:" prefixes. |
In short, it is necessary that the annotations specified in the superconstructor are added to the annotations of the fields. Otherwise, you get a hodgepodge - in one case you can omit the "field" prefix, and in others - not. |
Good question, I think the annotation in the default variant is only added to the constructor and we only take field, getter and setter annotations to the final annotation metadata. You can debug and see. Kapt probably is putting in everywere in the stub |
Yes, I understand what the problem is. Question for you: can this be fixed, or should we just give in and shut up? :-) |
@dstepanov I decided to test another case: if we do not redefine class attributes, but simply pass arguments of parent constructors in all child constructors. This way we are guaranteed to always use a constructor, and not setters for individual attributes. Look at the test structure: @Serdeable
@JsonIgnoreProperties(
value = ["myType"], // ignore manually set type, it will be automatically generated by Jackson during serialization
allowSetters = true, // allows the type to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "myType", visible = true)
@JsonSubTypes(
JsonSubTypes.Type(value = BasicBookInfo::class, name = "BASIC"),
JsonSubTypes.Type(value = DetailedBookInfo::class, name = "DETAILED"),
)
open class BookInfo(
var name: String,
@JsonProperty("myType")
var type: BookInfoType? = null,
)
@Serdeable
open class BasicBookInfo(
@NotNull
@Size(min = 3)
var author: String,
name: String,
type: BookInfoType? = null,
) : BookInfo(name, type)
@Serdeable
class DetailedBookInfo(
@Pattern(regexp = "[0-9]{13}")
var isbn: String,
author: String,
name: String,
type: BookInfoType? = null,
) : BasicBookInfo(author, name, type) As you can see, the type attribute has the So, why is this annotation ignored when introspection occurs? Yes, of course, I can specify the I believe this is a bug |
Well, Looking at |
Well, look what I got:
After these changes, the tests in this PR began to pass correctly Now let's get back to the test in micronaut-openapi. And the test still doesn't pass! And here's the problem: in the "class" field it writes the class name (!!!!!), although there should be a discriminator value!!! But it looks like the problem is not in the micronaut-serde library, but in the http client! Can you help me figure out this problem? It only occurs when using KSP and the problem is definitely not in the annotations, since they are now guaranteed to be set correctly This is a screenshot showing the problem. Look at the value of the propertyClass field - the class name is |
What do the bean's definitions look like? |
Look, the problem is NOT in the HTTP client, but in the controller!!! It looks like there is a serialization and deserialization error somewhere, and the real class name is automatically substituted into the discriminator value field! I really don't understand where the "substitution" of the discriminator value for the class name occurs... In the test in the current PR, I specifically made a similar model, as in my test - but in this PR everything works correctly... It turns out that the problem is in micronaut http Get sources fro mthis branch: https://github.com/altro3/micronaut-openapi/tree/reactive-tests Run test in module
As you see in |
With java and KAPT this test works fine |
@dstepanov I started debugging the process of sending a request in the test. This is what I see
It is also clear that in the object itself this field is empty, that is, it is injected by micronaut-serde . I suspect that everything is connected with the name of the field - So, look at the screenshot with KSP: The same checkpoint with KAPT: Look, the |
@dstepanov I think, found it. Looks to |
@dstepanov Added correct test to reproduce this problem: Please, help to fix it! |
The main problem is that KSP doesn't allow fetching the annotation model from a string and reading the annotations. We need to get the repeatable container. micronaut-projects/micronaut-core#11408 I can make the build pass if I add:
in |
@dstepanov This fix doesn't seem to help :-( |
b9b86fc
to
29b9331
Compare
See #768