Json Schema - Marking unique array from set

Hello all,

I’m working on moving json schema generation from GitHub - andyglow/scala-jsonschema: Scala JSON Schema to Tapir Json Schema generation.

Among some differences, I found one useful that could be added to Tapir Schema.
scala-jsonschema describes Set[_] with “uniqueItems”:

"SetWithEnums": {
    "default": [],
    "items": {
        "$ref": "#/definitions/MyEnum"
    },
    "type": "array",
    "uniqueItems": true
}

Tapir Json Schema is not adding “uniqueItems”

"SetWithEnums" : {
    "type" : "array",
    "items" : {
        "$ref" : "#/$defs/MyEnum"
    }
}

Maybe this would be useful to add “uniqueItems” to Tapir Json Schema generation?

True, we could probably do this via an attribute on the schema (and supporting this attribute appropriately in the interpreter). Can you create an issue to add that?

Thank you!
I created [FEATURE] Json Schema - Include uniqueItems when array is created from Set · Issue #3441 · softwaremill/tapir · GitHub

Also I have one more questions about other difference:
Is there a way to configure Tapir Schema generation to mark arrays as “required”?

I want to explicitly say that I will always return "myCollection": [],.

In scala-jsonschema not setting default value for collection will end up with having it in schema required list:

case class Test(myCollection: Seq[String])

Then schema includes:

"required": [
  "myCollection"
]

Adding default will remove that from required.
I’m not saying that this way of configuration is great in scala-jsonschema (I would say it’s rather surprising). But it’s possible.

Is there any way to add arrays as “required” in Tapir generated schema?

Yes, that issue was raised before, but there’s no simple solution (due to schema derivation being context-free). See: `asIterable` always creates optional properties · Issue #993 · softwaremill/tapir · GitHub - there are some work-arounds.