FSharp.Data.JsonSchema icon indicating copy to clipboard operation
FSharp.Data.JsonSchema copied to clipboard

Question: How does one generate the JsonSchema "required" field

Open dergraf opened this issue 4 years ago • 3 comments

Hello

F# beginner here.. I was playing with generating a Json Schema from a simple record type. To my understand all record properties are required, but this isn't reflected in the generated JsonSchema using the "required" field (https://json-schema.org/understanding-json-schema/reference/object.html#required-properties) What I have seen the underlying Njsonschema should support this using DataAnnotations, but I am not sure if this is the way to go here. Anyways, I guess I am missing something, I would appreciate if you can point me towards the right direction. Thanks!

dergraf avatar Jan 07 '21 09:01 dergraf

I'm not sure. If you can test using data annotations and let me know, I'd appreciate it. I haven't needed that yet, so I hadn't made any tests for it. We should probably add tests for these kinds of things and then address them.

panesofglass avatar Jan 25 '21 16:01 panesofglass

I'm thinking of using the Option<'T> type as a means of determining what's required. What do you think? NJsonSchema attributes should also work as that is the underlying engine for generating the JSON Schema.

panesofglass avatar Mar 20 '21 15:03 panesofglass

@dergraf I haven't quite figured out how to force the required attribute, but do you find #12 to improve some of what you were seeing before?

panesofglass avatar Oct 22 '21 18:10 panesofglass