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

Avoid field name beginning with an underscore #962

Merged
merged 4 commits into from
Dec 26, 2022

Conversation

ronlib
Copy link
Contributor

@ronlib ronlib commented Dec 23, 2022

fixes #917

Adds a field prefix in any situation where the generated field name begins with _, which makes pydantic consider it by default as a private field.

@ronlib
Copy link
Contributor Author

ronlib commented Dec 23, 2022

I can see it broke some tests. Let me know what you think about the new behavior I introduced here

@koxudaxi
Copy link
Owner

@ronlib
Thank you for creating the PR.
I don't like to break current behavior.
But, JSON Schema is a public interface and should not be private.

We should add a CLI option to change field_ prefix to another string after merging the PR.

@codecov
Copy link

codecov bot commented Dec 26, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (0d51ffc) compared to base (e9b6edf).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##            master      #962     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           11        21     +10     
  Lines         1020      2619   +1599     
  Branches       201       619    +418     
===========================================
+ Hits          1020      2619   +1599     
Flag Coverage Δ
unittests 99.92% <99.90%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
datamodel_code_generator/model/__init__.py 100.00% <ø> (ø)
datamodel_code_generator/__init__.py 100.00% <100.00%> (ø)
datamodel_code_generator/__main__.py 100.00% <100.00%> (ø)
datamodel_code_generator/format.py 100.00% <100.00%> (ø)
datamodel_code_generator/http.py 100.00% <100.00%> (ø)
datamodel_code_generator/imports.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/base.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/enum.py 100.00% <100.00%> (ø)
...atamodel_code_generator/model/pydantic/__init__.py 100.00% <100.00%> (ø)
...amodel_code_generator/model/pydantic/base_model.py 100.00% <100.00%> (ø)
... and 18 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@khvn26
Copy link

khvn26 commented Sep 26, 2023

This breaks other output types such as typing.TypedDict.

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.

@ symbol in JSON keys produces private variable
3 participants