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

@Nullable properties are required in strict mode #155

Closed
jGleitz opened this issue Mar 18, 2025 · 0 comments · Fixed by #156
Closed

@Nullable properties are required in strict mode #155

jGleitz opened this issue Mar 18, 2025 · 0 comments · Fixed by #156
Labels
component: jsonschema processor Issue relating to processor that creates schemas from types

Comments

@jGleitz
Copy link
Contributor

jGleitz commented Mar 18, 2025

Expected Behavior

When enabling strict mode and annotating a bean property with @jakarta.annotation.Nullable, the corresponding json property should not be added to the list of "required" properties in the JSON schema.

This behaviour would be in line with the documented behaviour (emphasis mine):

Whether to generate schemas in strict mode. In strict mode unresolved properties in JSON will cause an error. All the properties that are not annotated as nullable must be non-null.

Actual Behaviour

There seems to be no way to exclude a property from the "required" array in the generated schema.

Steps To Reproduce

  1. Set up JSON schema generation as explained in the docs
  2. Include a Java record as shown below in the project.
  3. Run the Java compiler to get the output shown below.

Input: Example.java

package com.example;

import io.micronaut.jsonschema.JsonSchema;

@JsonSchema
public record Example(String isRequired, @jakarta.annotation.Nullable String shouldnBeRequiredButIs) {
}

Output: example.schema.json

{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"http://localhost:8080/example.schema.json","title":"Example","type":["object"],"properties":{"isRequired":{"type":["string"]},"shouldnBeRequiredButIs":{"type":["string"]}},"required":["isRequired","shouldnBeRequiredButIs"],"additionalProperties":false}

Environment Information

No response

Example Application

No response

Version

4.7.6

@jGleitz jGleitz changed the title @Nullable properties are not ignored in strict mode @Nullable properties are required in strict mode Mar 18, 2025
@andriy-dmytruk andriy-dmytruk added the component: jsonschema processor Issue relating to processor that creates schemas from types label Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: jsonschema processor Issue relating to processor that creates schemas from types
Projects
None yet
2 participants