Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: JSON Schema missing title in subschemas #332

Merged

Conversation

dblanchette
Copy link
Contributor

The name attribute of Schema is used for the JSON Schema's title attribute, but it does not work on schemas used as reference or used as elements of Or, And , etc.

Example:

Schema(
    {
        "test": Or(
            Schema(
                "option1", name="Option 1", description="This is the first option"
            ),
            Schema(
                "option2",
                name="Option 2",
                description="This is the second option",
            ),
        )
    }
)

Before:

{
      "$schema": "http://json-schema.org/draft-07/schema#",
      "$id": "my-id",
      "properties": {
          "test": {
              "anyOf": [
                  {
                      "const": "option1",
                      "description": "This is the first option",
                  },
                  {
                      "const": "option2",
                      "description": "This is the second option",
                  },
              ]
          }
      },
      "required": ["test"],
      "additionalProperties": false,
      "type": "object",
  }

After:

{
      "$schema": "http://json-schema.org/draft-07/schema#",
      "$id": "my-id",
      "properties": {
          "test": {
              "anyOf": [
                  {
                      "const": "option1",
                      "title": "Option 1",
                      "description": "This is the first option",
                  },
                  {
                      "const": "option2",
                      "title": "Option 2",
                      "description": "This is the second option",
                  },
              ]
          }
      },
      "required": ["test"],
      "additionalProperties": false,
      "type": "object",
  }

@skorokithakis skorokithakis merged commit 3e06d37 into keleshev:master Feb 27, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants