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

Setting up "Models" section #12

Closed
SerVB opened this issue Mar 1, 2020 · 8 comments
Closed

Setting up "Models" section #12

SerVB opened this issue Mar 1, 2020 · 8 comments
Labels
bug Something isn't working

Comments

@SerVB
Copy link
Contributor

SerVB commented Mar 1, 2020

Hi! Is there an opportunity to change the "Models" section?

Currently, I have the following one (on this commit):

image

I'm not an experienced Swagger user but I think the issues are:

  1. The T model should not be presented.
  2. minimum: null/maximum: null for string and boolean seem redundant.
  3. minimum: -2147483648 for id: int32 isn't appropriate, I want it to start with 0.
  4. kotlin.collections.List is strange, it's a simple JSON array...
  5. io.github.servb.eShop.util.OptionalResult<io.github.servb.eShop.route.product.v1.ProductUsable> has the data: T field, but data: io.github.servb.eShop.route.product.v1.ProductUsable is more logical here.

I've briefly checked the annotations but haven't found suitable ones.

@Wicpar
Copy link
Collaborator

Wicpar commented Mar 2, 2020

Hi, Generics classes are unsupported.
Reflection is used during initialization, and generic types are erased. See JVM type erasure. This is one of the biggest caveats of JVM languages...
One way around it is to wrap your generic types like this:

class NotGeneric: GenericClass<Generic>()

This should allow the reflection to find the appropriate types.

@Wicpar
Copy link
Collaborator

Wicpar commented Mar 2, 2020

As for the nulls, the library currently relies on ktor to serialize the model into json. The mapper.setSerializationInclusion(Include.NON_NULL) should be activated for Jackson.

@Wicpar
Copy link
Collaborator

Wicpar commented Mar 2, 2020

Although thinking about it, the KType information seems to have the generic information... Maybe there is a way to handle it.

@Wicpar
Copy link
Collaborator

Wicpar commented Mar 2, 2020

Also, there is a hook in the configuration that allows you to properly rename the classes to be digestible by the standard.

@Wicpar
Copy link
Collaborator

Wicpar commented Mar 4, 2020

@SerVB I changed the model acquisition system in the new release. Please verify if your issue persists or not.

@Wicpar Wicpar added the bug Something isn't working label Mar 4, 2020
@Wicpar
Copy link
Collaborator

Wicpar commented Mar 10, 2020

@Wicpar Wicpar closed this as completed Mar 10, 2020
@SerVB
Copy link
Contributor Author

SerVB commented Mar 13, 2020

@Wicpar, thank you! I see many changes, for example, T and kotlin.collections.List have disappeared.

However, there are things that I still don't understand:

  1. minimum: null/maximum: null for string and boolean seem redundant.

If I do mapper.setSerializationInclusion(Include.NON_NULL), these redundant lines disappear but it's not a solution, because also my server stops sending fields with null values. I want it to continue sending objects like {"data": null}.

  1. minimum: -2147483648 for id: int32 isn't appropriate, I want it to start with 0.

So is there a way to annotate it?

@Wicpar
Copy link
Collaborator

Wicpar commented Mar 13, 2020

these are separate issues...
Currently the model is made with data classes and serialised from it. I'll have to change the whole model system to make it work like that. This can be quick fixed with a separate object mapper that serialises it to string in the openapi.json endpoint.
Also, currently there are no @min @max annotations. Though it can be added quite rapidly iirc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants