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

root_name does not affect subtypes or docstrings #468

Open
reweeden opened this issue May 10, 2023 · 1 comment
Open

root_name does not affect subtypes or docstrings #468

reweeden opened this issue May 10, 2023 · 1 comment

Comments

@reweeden
Copy link

When setting the root_name in the generation config, sub types of the root still get the original root name as their prefix. I would expect the prefixes of the sub types to match the provided root_name.

Example:

{
  "title": "MyObject",
  "type": "object",
  "required": ["child"],
  "properties": {
    "child": {
      "type": "object",
      "properties": {
        "foo": {"type": "string"},
      }
    }
  }
}

If we set the root_name to CustomRootName the generated code looks like this:

from typing import TypedDict
from typing_extensions import Required


class CustomRootName(TypedDict, total=False):
    """ MyObject. """

    child: Required["_MyobjectChild"]
    """ Required property """



class _MyobjectChild(TypedDict, total=False):
    foo: str

I was able to hack in a fix by adding this:

            if "root_name" in gen:
                schema_all["title"] = gen["root_name"]

Right before calling add_type on this line:

add_type(schema_all, gen.get("root_name", "Root"), force_name="root_name" in gen)

Then the resulting code looks as expected:

from typing import TypedDict
from typing_extensions import Required


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

    child: Required["_CustomRootNameChild"]
    """ Required property """



class _CustomRootNameChild(TypedDict, total=False):
    foo: str
@sbrunner
Copy link
Owner

Effectively, the goal of root_name is to affect only the main class name

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

No branches or pull requests

2 participants