Closed vincentburesi-es closed 3 months ago
The only way to identify default values I know of is to find which constructor parameters are marked as isOptional which could be complex to implement in a way that handles every edge case. Another way I could imagine this being solved is through an annotation that could be easily checked in the commented condition in buildObjectSchema()
Hi, thanks for the suggestion,
i added an automatic detection of optional properties (for reflection only for properties declared via constructor). By default, they are still handled as required during schema-generation, though this can be changed via the config at the generation step:
val result = typeOf<MyExampleClass>()
.processReflection()
.generateJsonSchema {
optionalHandling = OptionalHandling.NON_REQUIRED // same for swagger-schema
}
.compileInlining()
Since this works only for constructor parameters, i added two annotations "Optional" and "Required" that are handled in the "handleCoreAnnotations"-step (and overwrite any other behavior, e.g. from nullability or optional from constructor).
The changes will be included in the next version.
I hope these changes make sence. If you have any other idea, please let me know :)
As said in the title, I have looked into the code up to io.github.smiley4.schemakenerator.reflection.steps.ReflectionTypeProcessingStep#parseProperty
and its usage in io.github.smiley4.schemakenerator.swagger.steps.SwaggerSchemaGenerationStep#buildObjectSchema
So there seem to be no distinction between the notions of "nullable" and "required" in the PropertyData class. It would be great to have a distinct "required" boolean field that takes into account non-nullable fields with default values such as :