jsonschema-gentypes
jsonschema-gentypes copied to clipboard
Preserving case when generating $ref classes
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.
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.
@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
https://github.com/sbrunner/jsonschema-gentypes/blob/df680536403ec8e7fd4e1afce5b14f690bad9e0b/jsonschema_gentypes/cli.py#L197
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!
@sbrunner any interest in the change I proposed above? I'd be happy to work on a PR if you like the feature
@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?
@sbrunner sounds good! will do!