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

Primitive types should automatically be required #2044

Open
tobiberger opened this issue Oct 28, 2024 · 2 comments
Open

Primitive types should automatically be required #2044

tobiberger opened this issue Oct 28, 2024 · 2 comments

Comments

@tobiberger
Copy link

I just noticed that when adding properties with primitive types (boolean, int, etc.) to a class, they don't get marked as required, although they will definitely always have a value.
I notice this especially because I'm working with Kotlin and for non-primitive types, the Kotlin nullability is automatically and correctly applied. But when I use non-nullable Booleans or Ints, they're still optional in the api docs. I verified that the same thing happens for primitives in Java classes.

My expectation would be that primitives are always required. I understand that this would be a breaking change and that some people might prefer this behavior for input types, as primitive types have implicit default values. Therefore I'd be fine with it being an opt-in feature that I need to enable via config.

Does this feature already exist somehow (I might have just missed it)? Could it be implemented?
If someone can point me at the right part of the code, I could also have a go at an implementation myself.

@danielbobbert
Copy link

You can annotate your property with
@org.eclipse.microprofile.openapi.annotations.media.Schema(required=true)
to achieve that.

@tobiberger
Copy link
Author

I know I can do it manually, but I'd much prefer to have it done automatically, so it works like other, non primitive types (at least in Kotlin, where the type system holds nullability information) and I don't have to add boilerplate code for something that should be obvious.

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

No branches or pull requests

2 participants