Metadata-Version: 2.4
Name: bfg-schemautil
Version: 0.1.3
Summary: A set of utilities to generate JSON Schema from simple JSON objects
Author-email: Lei Zhao <8961794+leizha@users.noreply.github.com>
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# schemautil

A set of utilities to generate JSON Schema from simple JSON objects.

## Example

### Basic Object Schema

Given the following object schema:

```json
{
  "type": "object",
  "properties": {
    "a": { "type": "string" },
    "b": { "type": "string" }
  },
  "required": ["a", "b"],
  "additionalProperties": false
}
```

You can generate this schema using:

```python
object_schema({"a": "string", "b": "string"})
```

### Enum Example

For an enum field:

```python
object_schema({"status": ["enum", "pending", "approved", "rejected"]})
```

Generates:

```json
{
  "type": "object",
  "properties": {
    "status": {
      "type": "string",
      "enum": ["pending", "approved", "rejected"]
    }
  },
  "required": ["status"],
  "additionalProperties": false
}
```

## Rules

- **All fields are required** and `additionalProperties` is always set to `false`.
- To make a field nullable, add a `?` to the end of its name.
  Example: `{"a": "string", "b?": "string"}` (`b` is nullable)
- To define an array, wrap the type in brackets.
  Example: `{"a": "string", "b": ["string"]}` (`b` is an array of strings)
  _Note: There should be only one type in the array._
- To define a field that can be one of multiple types, list the types in brackets.
  Example: `{"a": "string", "b": ["string", "number"]}` (`b` can be a string or a number)
- To define an enum (restricted set of string values), use `["enum", ...values]`.
  Example: `{"status": ["enum", "pending", "approved", "rejected"]}` (`status` must be one of these specific strings)

  **Note:** The library distinguishes between type unions and enums:
  - `["string", "number"]` → Type union (can be any string or any number)
  - `["enum", "pending", "approved"]` → String enum (must be exactly one of these values)
