Neoteroi / essentials-openapi

Functions to handle OpenAPI Documentation.
MIT License
21 stars 9 forks source link

Add patternProperties to Schema object #42

Closed tyzhnenko closed 5 months ago

tyzhnenko commented 5 months ago

It will help to support Dict[str, Any] types in the OpenAPI schema.

It is useful to return some grouped data

@dataclass
class User:
    id: str
    name: str

Example for Dict[str, list[User]]

{
  "type": "object",
  "patternProperties": {
    "^[a-zA-Z0-9_]+$": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" }
        },
        "required": ["id", "name"]
      }
    }
  }
}
tyzhnenko commented 5 months ago

It works fine in the properties attribute.