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 option to show only the alias for a field #99
Comments
thanks for sharing your feature request! I think it is a reasonable proposal regarding your use case. However, I believe this use case is rather infrequent and narrow. The tradeoff between introduced complexity and gained functionality might be rather unbalanced towards the former. I'm not rejecting your request in any way. Rather, please help me justify it ;-). Can you think of other use cases? Or perhaps, if we provide a skeleton example of how an application configuration is loaded from a yaml file and used with autodoc-pydantic to be documented, it would be of use for others too. |
Thanks for your reply.
and validates everything with pydantic. The general idea is that you define your configuration in pydantic. from pydantic import BaseModel, Field
from easyconfig import AppConfigMixin, create_app_config
class MySimpleAppConfig(BaseModel, AppConfigMixin): # <-- AppConfigMixin is optional
retries: int = Field(5, description='Amount of retries on error')
url: str = 'localhost'
port: int = 443
# Create a global variable which then can be used throughout your code
# It implements the file loader, yaml logic and optional callbacks in case of value change.
CONFIG = create_app_config(MySimpleAppConfig())
# Use with type hints and auto complete
print(CONFIG.port)
# Load configuration file from disk.
# If the file does not exist it will be created
# Loading will also change all values of CONFIG accordingly
CONFIG.load_config_file('/my/configuration/file.yml') Created yaml file retries: 5 # Amount of retries on error
url: localhost
port: 443 Since this is depended on another library I'm not sure if you want it in your docs. |
For clarification: let's assume the alias is shown instead of the original attribute name. Does the original attribute name appear anywhere (e.g. where the alias was shown previously)? I suggest |
Yes - my first idea would be to not show the name at all. However if we just add a switch to swap name and alias then we have all use cases covered (e.g. e.g.: field: int = Field(1, alias="field2")
I currently can't think of a use case where one would show name and alias in switched order so both is fine for me. |
This looks good to me - I agree with We have to keep in mind, that field summary list needs to be modified to if name and alias are swapped. Otherwise we would have an inconsistency between the field summary in the model's header and the actual field names. |
@spacemanspiff2007 This is accomplished by #119.
Before merging the related PR, it would be great if you could test the behavior on your site. To do so, please install the current dev release in your doc-building-environment via The actual implementation was more complex because of interactions with other configurations (model-show-field-summary, model-show-validator-summary, validator-replace-signature, validator-list-fields) that require a replacement of field name with field alias for consistency reasons. Otherwise, we would show the field alias in one place but the the field name elsewhere. |
This is included in v1.7.0 (released just few minutes ago). |
I'm loading the application configuration from a yaml file and want to use autodoc-pydantic to document the available settings.
It's really great that there are so many configuration options so everything can be tailored to ones needs.
However I'm missing one more thing:
Since I load from file I load the corresponding values by alias and not by name.
Would it be possible to add a configuration option which shows the alias instead of the field name?
My users have to enter the alias in the configuration file - the field name is of no use for them and might be confusing.
Example:
Valid entry in yaml file
The text was updated successfully, but these errors were encountered: