-
Notifications
You must be signed in to change notification settings - Fork 8k
[admin-v2] Enable client generators to create proper class hierarchies with inheritance #46180
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
base: main
Are you sure you want to change the base?
Conversation
|
@michalvavrik @vmuzikar @robson90 Could you please check this PR? Thanks! |
|
Looking. |
| * Detects classes with @JsonAnyGetter and sets additionalProperties on their schemas. | ||
| * This reflects that the class accepts arbitrary additional JSON properties at runtime. | ||
| */ | ||
| private void addAdditionalPropertiesToSchemas(OpenAPI openAPI) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with doing this for any JsonAnyGetter provided they are missing from the generated OpenAPI document (which they are, I checked). But you explicitly speak about additonalProperties, so either:
- you are dead certain there never will be any other such getter with different name
- tweak javadoc or method name to clarify that this propagates any such a getter into openapi specs
- filter method infos to only those with names
getAdditionalFields
It is a nitpick...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually don't want anything to show up in the schema for JsonAnyGetter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I didn't know. Also looking at the entry.getValue().setAdditionalPropertiesSchema(OASFactory.createSchema()); I think if it were to be present in the definition, you need to filter methods by name to do not include accidentally future getters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention behind bringing back the additionalProperties was to try, whether it could solve issues with Kiota generator (reportedly it did). But I might've misunderstood the goal. Also I did not test this with Kiota myself - thus it is in a separate commit, which we can easily remove.
@michalvavrik can you confirm that this additionalProperties is what fixes the failures even for you and whether it is really what we need here?
Another approach would be adding the @Schema(additionalProperties = Schema.True.class), which I actually tried at first, but I decided not to use it, because it was syntactically different (generated just additionalProperties: true, not sure whether it poses some problem or not).
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalvavrik can you confirm that this additionalProperties is what fixes the failures even for you and whether it is really what we need here?
it doesn't; gosh I need to make myself clearer in the future, sorry
So the issue with the kiota generator is that BaseRepresentation is empty in the generated OpenAPI document. But that is still the case, as currently, BaseRepresentation isn't augmented by the addAdditionalPropertiesToSchemas. Are there 2 ways I know about how to deal with it:
- @edewit just removed
@Schemaand obviously unusedBaseRepresentationdisappeared, that is fine if we add comment that once the representation contains any properties, we would like to have it in the OpenAPI document - we can add dummy readonly property, e.g. A="1", but I looked into OpenAPI specs and I can't see how to instruct generators to never include it in clients. it is not nice, I'd not use it
Another approach would be adding the @Schema(additionalProperties = Schema.True.class), which I actually tried at first, but I decided not to use it, because it was syntactically different (generated just additionalProperties: true, not sure whether it poses some problem or not).
If there is no function for having the additionalProperties in the response, e.g. client doesn't need it, let's not do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for your time if you did it only because of my previous comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalvavrik no worries, it's misunderstanding on my end, partially caused by the fact that OpenAPI generator's behaviour was different. I just read your comment under Erik's PR and hopefully got the context. Now it should copy Erik's approach.
322fd00 to
dd30861
Compare
|
For me the generation is failing, because of the non existent Logs: As said on Slack, my fix would be this part added to the openapi: Just for testing I did change locally: Outcome: After compiling and pasting it in, Kiota is running without any complaints, the calls with an OIDCRep is working. Now the part where I don't know, how fix. When calling get on a Client it has the type Only way right now, as an easy fix and also a nice usable api on the Java side could be to support all of this: /clients -> will return Type Depending on the UseCase I would then use the respective function for updating resources. WDYT? For reference here are my testings: robson90/keycloak-client#3 |
|
@Pepo48 the last time I read this PR it seemed fine and I didn't expect you to deal with |
|
@michalvavrik OpenAPI generator didn't require any changes with regards to the base rep. Everything that is needed on top of my original PoC is just an attempt to help you guys, to stabilize Kiota. That was the reason of the first attempt actually - I read the comment made by @robson90 from our offline conversation and tried to bring But if I understand it correctly, then And as a next step I can try to add the return types that Robin suggested, if we agree on it. |
|
Regardless, feel free to bring your own adjustments at any point of time or anybody can take over this PR, if needed. My initial intention was just provide you with some basis that I already had, I don't have to necessarily drive this to the finish line (as I don't work with Kiota anyway, so you know better what you exactly need). |
…s with inheritance Closes: keycloak#46158 Signed-off-by: Peter Zaoral <[email protected]>
dd30861 to
7c6252d
Compare
Frankly, I had no idea that was the intention. I thought that you are fixing the class hierarchy, which seems helpful. Knowing this will help.
IMO it would work if the additional properties were on
Well, let see how much time I have tomorrow. I don't want your work to go waste, we can finish this one. |
Yeah, thanks for your investigation, this is now working "as expected". Regrading my massive comments from above, we can also discuss the next steps on Monday. PR itself LGTM, except CI is complaining about spotless...
@michalvavrik what is the exact use case for this attribute ? |
I don't know yet. It is not relevant because I don't want to include it. |
* add additionalFileds to base representation Closes: keycloak#46158 Signed-off-by: Peter Zaoral <[email protected]>
7c6252d to
b8acc5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
I had a look again and here is my conclusion.
- ATM this PR resolves Kiota generation issue and LGTM
- I lack knowledge about
additionalFields, but IIUC @shawkins mentioned that we don't want them in the OpenApi document. In which case I can see only 2 options how to solve the "empty BaseRepresentation" issue:- add discriminator to the
BaseRepresentationas I assume we are going to need it eventually to determine if it is a client or realm, user, or ...? - just bring back
@JsonIgnoreand drop@Schemaas it has no function in regards to OpenAPI ATM
- add discriminator to the
Thanks @Pepo48 for your work. You will have to decide what to do with your PR.
Closes: #46158