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

Preserving case when generating $ref classes #843

Open
eupharis opened this issue Jan 29, 2024 · 5 comments
Open

Preserving case when generating $ref classes #843

eupharis opened this issue Jan 29, 2024 · 5 comments

Comments

@eupharis
Copy link
Contributor

eupharis commented Jan 29, 2024

Using Python 3.10.12 and version jsonschema-gentypes 2.4.0

So for this schema:

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "definitions": {
    "SubresourceUris": {
      "type": "object",
      "properties": {
        "feedback": {
          "type": "string"
        }
      },
      "required": ["feedback"],
      "title": "SubresourceUris"
    }
  },
  "type": "object",
  "properties": {
    "subresource_uris": {
      "$ref": "#/definitions/SubresourceUris"
    }
  },
  "required": [
    "subresource_uris"
  ],
  "title": "ResponseType"
}

when I run:

from jsonschema_gentypes.cli import process_config


config = {
    "python_version": None,
    "generate": [
      {
            "source": "./input.json",
            "destination": "./output.py",
        }
    ],
}
process_config(config)  # type: ignore

I get back the following:

from typing import TypedDict
from typing_extensions import Required


class Responsetype(TypedDict, total=False):
    """ ResponseType. """

    subresource_uris: Required["Subresourceuris"]
    """
    SubresourceUris.

    Required property
    """



class Subresourceuris(TypedDict, total=False):
    """ SubresourceUris. """

    feedback: Required[str]
    """ Required property """

Is there any way to have the output match the case of the input, and have the class be named SubresourceUris instead?

Love the library by the way! It's very nice.

@sbrunner
Copy link
Owner

Yon can modify the schema SubresourceUris => Subresource_Uris
Currently, there is no way to change the method that creates the name, we can imagine having a singleton that provides the get_name function.

@eupharis
Copy link
Contributor Author

@sbrunner so like a custom_get_name config option?

looks like if we provided it as part of config in the api_arguments, it would already get passed to class API

api_args = gen.get("api_arguments", {})

then if API called self.get_name it could use self.custom_get_name if defined then fallback to the normal get_name

seems like it could be a pretty minimal code change to support it!

@eupharis
Copy link
Contributor Author

eupharis commented Mar 4, 2024

@sbrunner any interest in the change I proposed above? I'd be happy to work on a PR if you like the feature

@sbrunner
Copy link
Owner

sbrunner commented Mar 5, 2024

@eupharis I didn't catch every detail of your proposal, then I propose that you create a pull request, then we talk about it, does it look like ok to you?

@eupharis
Copy link
Contributor Author

eupharis commented Mar 5, 2024

@sbrunner sounds good! will do!

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