Skip to content

json schema: propertyNames only shows up under specific conditions #866

Closed

Description

@bimac

Description

I found a weird inconsistency when generating JSON schema:

Variant 1

import msgspec
from typing import Annotated
import json

key_type = Annotated[str, msgspec.Meta(pattern=r'^A$')]
value_type = Annotated[str, msgspec.Meta(pattern=r'^B$')]
dict_type = Annotated[dict[key_type, value_type], msgspec.Meta(min_length=1)]

schema = msgspec.json.schema(dict_type)
print(json.dumps(schema, indent=2))

results in:

{
  "type": "object",
  "propertyNames": {
    "pattern": "^A$"
  },
  "additionalProperties": {
    "type": "string",
    "pattern": "^B$"
  },
  "minProperties": 1
}

✔️ works as expected

Variant 2

import msgspec
from typing import Annotated
import json

key_type = Annotated[str, msgspec.Meta(title='key', pattern=r'^A$')]
value_type = Annotated[str, msgspec.Meta(pattern=r'^B$')]
dict_type = Annotated[dict[key_type, value_type], msgspec.Meta(min_length=1)]

schema = msgspec.json.schema(dict_type)
print(json.dumps(schema, indent=2))

results in:

{
  "type": "object",
  "additionalProperties": {
    "type": "string",
    "pattern": "^B$"
  },
  "minProperties": 1
}

❌ Merely adding the title kwarg to key_type results in the propertyNames section being dropped entirely.

Activity

  1. changed the title [-]json schema: propertyNames only show up under specific conditions[/-] [+]json schema: propertyNames only shows up under specific conditions[/+] on Aug 21, 2025
  2. added a commit that references this issue on Sep 13, 2026
    9bec541
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions