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

Add custom_get_name config option #889

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eupharis
Copy link

@eupharis eupharis commented Mar 7, 2024

Attached is what I'm thinking for a way to allow individual users of the library to pass their own get_name method.

In case they want to have generated python class types like SubresourceUri instead of just the default .title() version of Subresourceuri

#843

NOTE: we'll need to swap get_name to self.get_name on all subclasses of API before we can merge this repo. I only did API and APIv4 so far.

.gitignore Outdated
@@ -7,3 +7,4 @@ __pycache__
/dist
/.github/changelog-generator-cache
/tests/recursion.py
/.vscode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be on your own ~/.gitignore file...

Comment on lines 7 to 19
GetNameFunction = Callable[
[
Optional[
Union[
jsonschema_draft_04.JSONSchemaD4,
jsonschema_draft_2019_09_meta_data.JSONSchemaItemD2019,
]
],
Optional[str],
bool,
],
str,
]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this copy?

@@ -2,10 +2,12 @@
Automatically generated file from a JSON schema.
"""

from typing import Any, Literal, TypedDict, Union
from typing import Any, Callable, Literal, Optional, TypedDict, Union
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is generated from jsonschema_gentypes/schema.json and describes the schema of the configurations file.

Then if we want to be able to configure it only with python code we should get the function definition out of this file :-)

But in fact, I didn't see well how you plan to use it?
Like in the test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbrunner ok! I fixed the two other issues you pointed out.

I can totally get the definition out and instead put it in the configuration file.

what's the command to generate the schema.json from the configuration file?

I plan to use this exactly how I use it in the test.

Without the custom_get_name, you wind up with the .title version like Subresourceuri as the name and the test fails. I need the only-first-letter-capitalized version like SubresourceUri.

I also invoke this by importing the process_config function from a Python script, not from the cli.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbrunner want me to pull that definition out of the configuration file? any other changes?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the command to generate the schema.json from the configuration file?

It's the inverse, this file is generated from this schema https://github.com/sbrunner/jsonschema-gentypes/blob/7c7fe0d6f5539c13334580762bfacef292c6edba/jsonschema_gentypes/schema.json

It's done by pre-commit :-)

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

Successfully merging this pull request may close these issues.

None yet

2 participants