-
-
Notifications
You must be signed in to change notification settings - Fork 228
Improvements to schema and enum naming #31
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
Improvements to schema and enum naming #31
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you! A couple comments to address then some exciting improvements to merge 🥳
if "properties" in d: | ||
for key, value in d["properties"].items(): | ||
required = key in required_set | ||
p = property_from_dict(name=key, required=required, data=value) | ||
if required: | ||
required_properties.append(p) | ||
else: | ||
optional_properties.append(p) | ||
if isinstance(p, (ReferenceListProperty, EnumListProperty, RefProperty, EnumProperty)) and p.reference: | ||
# don't add an import for self-referencing schemas | ||
if p.reference.class_name != ref.class_name: | ||
relative_imports.add(import_string_from_reference(p.reference)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a personal preference, I try to avoid multiple layers as much as possible. Something about "cognitive complexity" I read in a book 🧠🤓. Feel free to disagree and leave as is.
if "properties" in d: | |
for key, value in d["properties"].items(): | |
required = key in required_set | |
p = property_from_dict(name=key, required=required, data=value) | |
if required: | |
required_properties.append(p) | |
else: | |
optional_properties.append(p) | |
if isinstance(p, (ReferenceListProperty, EnumListProperty, RefProperty, EnumProperty)) and p.reference: | |
# don't add an import for self-referencing schemas | |
if p.reference.class_name != ref.class_name: | |
relative_imports.add(import_string_from_reference(p.reference)) | |
for key, value in d.get("properties", {}).items(): | |
required = key in required_set | |
p = property_from_dict(name=key, required=required, data=value) | |
if required: | |
required_properties.append(p) | |
else: | |
optional_properties.append(p) | |
if ( | |
isinstance(p, (ReferenceListProperty, EnumListProperty, RefProperty, EnumProperty)) | |
and p.reference | |
and p.reference.class_name != ref.class_name # don't add an import for self-referencing schemas | |
): | |
relative_imports.add(import_string_from_reference(p.reference)) |
|
||
if class_name in class_overrides: | ||
return class_overrides[class_name] | ||
|
||
return Reference(class_name=class_name, module_name=stringcase.snakecase(ref_value),) | ||
return Reference(class_name=class_name, module_name=stringcase.snakecase(class_name),) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will conflict with #29 most likely, so whichever one gets merged first will trigger an update in the other. Just to be aware.
models_dir.__truediv__.side_effect = lambda x: module_paths[x] | ||
|
||
def models_dir_get(x): | ||
return module_paths[x] | ||
|
||
models_dir.__truediv__.side_effect = models_dir_get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this change was because it was difficult to read. Maybe I should be using itemgetter for this, would that be better / more Pythonic you think?
Pretty sure I do this in several tests.
Codecov Report
@@ Coverage Diff @@
## master #31 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 9 +1
Lines 532 573 +41
=========================================
+ Hits 532 573 +41
Continue to review full report at Codecov.
|
name schemas using the declaring property name if no
"title"
property is available. Currently the generator breaks when processing cases such as :This will use
CoolFunModel
as the schema name in these cases.Conversely, for enum properties, if a
title
property is available in the property schema then ths this is used to name the enum. This also addresses Allow defining Enums ahead of time #21 - in the case where repeated property enums are derived from a single enum in a typed language (e.g. Java), if they have the sametitle
they will be merged back into a single Python enum in the client.