-
Notifications
You must be signed in to change notification settings - Fork 57
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
Support encode int as string #2771
Changes from all commits
443ad95
1181ccf
a4ccf83
208e6fd
5b60e60
342431e
5486ab2
c9771a4
6a98ad9
a41f973
8480487
8e20f21
f816fdb
cee1219
bc9dfb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: feature | ||
packages: | ||
- "@azure-tools/typespec-python" | ||
--- | ||
|
||
Support encode int as string |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -454,6 +454,10 @@ def _serialize(o, format: typing.Optional[str] = None): # pylint: disable=too-m | |||||||||||||||||||||||||
return float(o) | ||||||||||||||||||||||||||
if isinstance(o, enum.Enum): | ||||||||||||||||||||||||||
return o.value | ||||||||||||||||||||||||||
if isinstance(o, int): | ||||||||||||||||||||||||||
if format == "str": | ||||||||||||||||||||||||||
return str(o) | ||||||||||||||||||||||||||
return o | ||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||
# First try datetime.datetime | ||||||||||||||||||||||||||
return _serialize_datetime(o, format) | ||||||||||||||||||||||||||
|
@@ -675,6 +679,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915, | |||||||||||||||||||||||||
rf: typing.Optional["_RestField"] = None, | ||||||||||||||||||||||||||
) -> typing.Optional[typing.Callable[[typing.Any], typing.Any]]: | ||||||||||||||||||||||||||
if not annotation or annotation in [int, float]: | ||||||||||||||||||||||||||
if annotation is int and rf and rf._format == "str": | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think we have to modify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. autorest.python/packages/typespec-python/generator/pygen/codegen/templates/model_base.py.jinja2 Lines 829 to 840 in 8480487
Appreciate if you could explain more how to pass in deserialization function? It seems that RestField has no parameter to pass it.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you pass it through the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for datetime/bytes encoding, we put the logic in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iscai-msft I think it is better not handle this feature with call_back so that we could keep consistent for all encoding things. But your comment hint me that we could confirm the deserialize and serialize function for model property when generate code so that we could save time for model initialization and I have created #2797 to track it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the model is vendored we can def change things, so I think we can have the rest field take in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. And the change of redesign for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I've added a separate issue for the |
||||||||||||||||||||||||||
return int | ||||||||||||||||||||||||||
return None | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# is it a type alias? | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,8 @@ export function pyright() { | |
} | ||
|
||
export function eslint() { | ||
const checkWarning = argv.skipWarning ? "" : "--max-warnings=0"; | ||
// const checkWarning = argv.skipWarning ? "" : "--max-warnings=0"; | ||
const checkWarning = ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. skip eslint failure caused by deprecation of After #2775 merged, we could revert this change. |
||
executeCommand(`npx eslint . --ext .ts ${checkWarning} `, "eslint"); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include *.md | ||
include LICENSE | ||
include azure/clientgenerator/core/flattenproperty/py.typed | ||
recursive-include tests *.py | ||
recursive-include samples *.py *.md | ||
include azure/__init__.py | ||
include azure/clientgenerator/__init__.py | ||
include azure/clientgenerator/core/__init__.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
|
||
# Azure Clientgenerator Core Flattenproperty client library for Python | ||
<!-- write necessary description of service --> | ||
|
||
## Getting started | ||
|
||
### Install the package | ||
|
||
```bash | ||
python -m pip install azure-clientgenerator-core-flattenproperty | ||
``` | ||
|
||
#### Prequisites | ||
|
||
- Python 3.8 or later is required to use this package. | ||
- You need an [Azure subscription][azure_sub] to use this package. | ||
- An existing Azure Clientgenerator Core Flattenproperty instance. | ||
|
||
## Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require | ||
you to agree to a Contributor License Agreement (CLA) declaring that you have | ||
the right to, and actually do, grant us the rights to use your contribution. | ||
For details, visit https://cla.microsoft.com. | ||
|
||
When you submit a pull request, a CLA-bot will automatically determine whether | ||
you need to provide a CLA and decorate the PR appropriately (e.g., label, | ||
comment). Simply follow the instructions provided by the bot. You will only | ||
need to do this once across all repos using our CLA. | ||
|
||
This project has adopted the | ||
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information, | ||
see the Code of Conduct FAQ or contact opencode@microsoft.com with any | ||
additional questions or comments. | ||
|
||
<!-- LINKS --> | ||
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ | ||
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token | ||
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials | ||
[azure_identity_pip]: https://pypi.org/project/azure-identity/ | ||
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential | ||
[pip]: https://pypi.org/project/pip/ | ||
[azure_sub]: https://azure.microsoft.com/free/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"CrossLanguagePackageId": "Azure.ClientGenerator.Core.FlattenProperty", | ||
"CrossLanguageDefinitionId": { | ||
"azure.clientgenerator.core.flattenproperty.models.ChildFlattenModel": "Azure.ClientGenerator.Core.FlattenProperty.ChildFlattenModel", | ||
"azure.clientgenerator.core.flattenproperty.models.ChildModel": "Azure.ClientGenerator.Core.FlattenProperty.ChildModel", | ||
"azure.clientgenerator.core.flattenproperty.models.FlattenModel": "Azure.ClientGenerator.Core.FlattenProperty.FlattenModel", | ||
"azure.clientgenerator.core.flattenproperty.models.NestedFlattenModel": "Azure.ClientGenerator.Core.FlattenProperty.NestedFlattenModel", | ||
"azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_flatten_model": "Azure.ClientGenerator.Core.FlattenProperty.putFlattenModel", | ||
"azure.clientgenerator.core.flattenproperty.FlattenPropertyClient.put_nested_flatten_model": "Azure.ClientGenerator.Core.FlattenProperty.putNestedFlattenModel" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) Python Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._client import FlattenPropertyClient | ||
from ._version import VERSION | ||
|
||
__version__ = VERSION | ||
|
||
try: | ||
from ._patch import __all__ as _patch_all | ||
from ._patch import * # pylint: disable=unused-wildcard-import | ||
except ImportError: | ||
_patch_all = [] | ||
from ._patch import patch_sdk as _patch_sdk | ||
|
||
__all__ = [ | ||
"FlattenPropertyClient", | ||
] | ||
__all__.extend([p for p in _patch_all if p not in __all__]) | ||
|
||
_patch_sdk() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) Python Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from typing import Any | ||
|
||
from azure.core.pipeline import policies | ||
|
||
from ._version import VERSION | ||
|
||
|
||
class FlattenPropertyClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long | ||
"""Configuration for FlattenPropertyClient. | ||
|
||
Note that all parameters used to create this instance are saved as instance | ||
attributes. | ||
|
||
:param endpoint: Service host. Default value is "http://localhost:3000". | ||
:type endpoint: str | ||
""" | ||
|
||
def __init__(self, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: | ||
|
||
self.endpoint = endpoint | ||
kwargs.setdefault("sdk_moniker", "clientgenerator-core-flattenproperty/{}".format(VERSION)) | ||
self.polling_interval = kwargs.get("polling_interval", 30) | ||
self._configure(**kwargs) | ||
|
||
def _configure(self, **kwargs: Any) -> None: | ||
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) | ||
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) | ||
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) | ||
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) | ||
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) | ||
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) | ||
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) | ||
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) | ||
self.authentication_policy = kwargs.get("authentication_policy") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) Python Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._operations import FlattenPropertyClientOperationsMixin | ||
|
||
from ._patch import __all__ as _patch_all | ||
from ._patch import * # pylint: disable=unused-wildcard-import | ||
from ._patch import patch_sdk as _patch_sdk | ||
|
||
__all__ = [ | ||
"FlattenPropertyClientOperationsMixin", | ||
] | ||
__all__.extend([p for p in _patch_all if p not in __all__]) | ||
_patch_sdk() |
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.
why do we have this code here> we should already be doing this in the
regenreate.ts
file, and this is also for the autorest generation. Whatever functinoality we need from this should be moved into the scripts instead of being in yml for the scriptsThere 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.
the one thing i'm not sure about is serialization. If we can't edo serialization here, we should instead add similar functionality but for serialization (and we can rename
type
todeserialization
) instead of adding extra logic through the msrest wayThere 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.