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

Support inheritance #147

Closed
VladDrakul1986 opened this issue Jan 23, 2023 · 3 comments
Closed

Support inheritance #147

VladDrakul1986 opened this issue Jan 23, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@VladDrakul1986
Copy link

VladDrakul1986 commented Jan 23, 2023

Hi i figured out a problem when using:

...
requestBody = @OpenApiRequestBody(...
               @OpenApiContent(from = MyRequestClass.class, type = ContentType.JSON)),

The MyRequestClass extends from MyBaseRequest since all Request should have a common set of fields.
public class MyRequestClass extends MyBaseRequest implements Serializable{....}

i just get all fields having a getter in myRequestClass but not the fields defined in MyBaseRequest.
This functionality was present in Javalin 4 (but need the setter and not getters).

Is this a Bug(enhancement) or I made it wrong?

I tested the behaviour for @OpenApiReponse as well, it behaves the same as @OpenApiRequestBody so it seems the @OpenApiContent doesn't process the inheritance.

@dzikoysk
Copy link
Member

By default OpenApi only includes properties exposed by getters, not fields as fields are rarely exposed in api. You can enforce fields resolution with @OpenApiByFields on MyRequestClass class tho.

@dzikoysk dzikoysk added the question Further information is requested label Jan 23, 2023
@VladDrakul1986
Copy link
Author

my example was bad the @OpenApiByFields is a nice function but not solving my problem.
More detailed example:

public class MyBaseRequest {
private String name;
private String description;
...
// getter for all
...
}
public class MyRequestClass extends MyBaseRequest implements Serializable{
private String someAdditonalField;
...
// getter for all
...
}
requestBody = @OpenApiRequestBody(...
               @OpenApiContent(from = MyRequestClass.class, type = ContentType.JSON)),

when open the swagger site only someAdditonalField is shown in the json at requestbody but not as expected name and description as well.
actual json result:

{
"someAdditonalField": "string",
}

expected json result:

{
"someAdditonalField": "string",
"name": "string",
"description": "string"
}

The same behaviour can be observed for the @OpenApiReponse providing a class with inheritance.

I just mentioned the setters because in Javalin 4 the setters were needed, just as hint for people try to migrate from 4 to 5.

@dzikoysk dzikoysk added enhancement New feature or request and removed question Further information is requested labels Jan 23, 2023
@dzikoysk dzikoysk changed the title Problem using @OpenApiRequestBody Support inheritance Jan 23, 2023
@dzikoysk
Copy link
Member

I see, this is slightly associated with #87 as there's no heritage analysis atm. I'll include all properties for now and we'll see how it evolves

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

No branches or pull requests

2 participants