jsonschema-gentypes icon indicating copy to clipboard operation
jsonschema-gentypes copied to clipboard

Generate Python types without docstring

Open Nifacy opened this issue 1 month ago • 2 comments

Description

Current;y, the jsonschema-gentypes tool generates Python types from JSON schemas with included docstrings in the output files. This creates difficulties when users want to keep generated files minimal or want to control documentation separately. For example, if follow schema.json file defined:

{
  "title": "Person",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer" }
  },
  "required": ["name", "age"]
}

When we try to build Python types using follow command:

jsonschema-gentypes --json-schema=schema.json --python=person_types.py

We will get follow content in person_types.py file:

from typing import Required, TypedDict


class Person(TypedDict, total=False):
    """ Person. """

    name: Required[str]
    """ Required property """

    age: Required[int]
    """ Required property """

Request

Add the options to specify in tool's configuration to omit docstrings from the generated Python type files. As the result user will get follow content in person_types.py file:

from typing import Required, TypedDict


class Person(TypedDict, total=False):
    name: Required[str]
    age: Required[int]

Nifacy avatar Oct 19 '25 10:10 Nifacy

Some of possible solutions:

  • The configuration parameter generate_docstrings, which will store a boolean value. If this parameter stores false, the documentation lines will be omitted.
  • A command-line flag to omit docstrings from the generated Python type files.

Nifacy avatar Oct 19 '25 10:10 Nifacy

I don't need that, but I have no issue with that, then if a clean pull request is proposed I will merge it :-)

sbrunner avatar Oct 22 '25 07:10 sbrunner