Skip to content

Commit

Permalink
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python
Browse files Browse the repository at this point in the history
…into multiapi_classes

* 'autorestv3' of https://github.com/Azure/autorest.python:
  Handle m4 accept header parameter (#748)
  Multipart (#746)
  Introduce explode into autorest (#705)
  update azure-core and msrest versions (#747)
  Update package.json
  Update ChangeLog.md
  Replace not extend scopes (#745)
  Have either AzureKeyCredential typing or TokenCredential typing (#744)
  • Loading branch information
iscai-msft committed Aug 18, 2020
2 parents b9575b9 + 4b50e30 commit 2d65d35
Show file tree
Hide file tree
Showing 396 changed files with 4,952 additions and 2,077 deletions.
18 changes: 17 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Change Log

### 2020-xx-xx - 5.1.0-preview.7
### 2020-xx-xx - 5.1.0-preview.8
Autorest Core version: 3.0.6302
Modelerfour version: 4.15.400

**New Features**

- Updated minimum `azure-core` version to 1.8.0 #747
- Updated minimum `msrest` version to 0.6.18 #747
- Support for `multipart/form-data` #746

**Bug fixes**

- Fix "multi" in Swagger (will generate correctly multiple query param now)

### 2020-08-07 - 5.1.0-preview.7
Autorest Core version: 3.0.6302
Modelerfour version: 4.15.400

**New Features**

- Add `azure-mgmt-core` as a dependency in the generated setup.py file #738
- Correct typing for `credential` when default credential policy type is `AzureKeyCredentialPolicy` #744
- Replace instead of extending `credential_scopes` if user has inputted their own #745

### 2020-08-04 - 5.1.0-preview.6
Autorest Core version: 3.0.6287
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ AutoRest needs the below config to pick this up as a plug-in - see https://githu
pass-thru:
- model-deduplicator
- subset-reducer
version: 3.0.6302
version: ~3.0.6306
use-extension:
"@autorest/modelerfour": "4.15.400"
"@autorest/modelerfour": 4.15.410

modelerfour:
group-parameters: true
Expand Down
8 changes: 5 additions & 3 deletions autorest/codegen/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# --------------------------------------------------------------------------
from typing import Any, Dict
from .base_model import BaseModel
from .code_model import CodeModel, CredentialSchema
from .code_model import CodeModel
from .credential_schema import AzureKeyCredentialSchema, TokenCredentialSchema
from .object_schema import ObjectSchema
from .dictionary_schema import DictionarySchema
from .list_schema import ListSchema
Expand All @@ -25,10 +26,10 @@


__all__ = [
"AzureKeyCredentialSchema",
"BaseModel",
"BaseSchema",
"CodeModel",
"CredentialSchema",
"ConstantSchema",
"ObjectSchema",
"DictionarySchema",
Expand All @@ -45,7 +46,8 @@
"ParameterList",
"OperationGroup",
"Property",
"SchemaResponse"
"SchemaResponse",
"TokenCredentialSchema",
]

def _generate_as_object_schema(yaml_data: Dict[str, Any]) -> bool:
Expand Down
55 changes: 8 additions & 47 deletions autorest/codegen/models/code_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# --------------------------------------------------------------------------
from itertools import chain
import logging
from typing import cast, List, Dict, Optional, Any, Set
from typing import cast, List, Dict, Optional, Any, Set, Union

from .base_schema import BaseSchema
from .credential_schema import AzureKeyCredentialSchema, TokenCredentialSchema
from .enum_schema import EnumSchema
from .object_schema import ObjectSchema
from .operation_group import OperationGroup
Expand All @@ -17,7 +18,6 @@
from .parameter import Parameter, ParameterLocation
from .client import Client
from .parameter_list import ParameterList
from .imports import FileImport, ImportType, TypingSection
from .schema_response import SchemaResponse
from .property import Property
from .primitive_schemas import IOSchema
Expand All @@ -26,50 +26,6 @@
_LOGGER = logging.getLogger(__name__)


class CredentialSchema(BaseSchema):
def __init__(self, async_mode) -> None: # pylint: disable=super-init-not-called
self.async_mode = async_mode
self.async_type = "~azure.core.credentials_async.AsyncTokenCredential"
self.sync_type = "~azure.core.credentials.TokenCredential"
self.default_value = None

@property
def serialization_type(self) -> str:
if self.async_mode:
return self.async_type
return self.sync_type

@property
def docstring_type(self) -> str:
return self.serialization_type

@property
def type_annotation(self) -> str:
if self.async_mode:
return '"AsyncTokenCredential"'
return '"TokenCredential"'

@property
def docstring_text(self) -> str:
return "credential"

def imports(self) -> FileImport:
file_import = FileImport()
if self.async_mode:
file_import.add_from_import(
"azure.core.credentials_async", "AsyncTokenCredential",
ImportType.AZURECORE,
typing_section=TypingSection.TYPING
)
else:
file_import.add_from_import(
"azure.core.credentials", "TokenCredential",
ImportType.AZURECORE,
typing_section=TypingSection.TYPING
)
return file_import


class CodeModel: # pylint: disable=too-many-instance-attributes
"""Holds all of the information we have parsed out of the yaml file. The CodeModel is what gets
serialized by the serializers.
Expand Down Expand Up @@ -168,7 +124,11 @@ def add_credential_global_parameter(self) -> None:
:return: None
:rtype: None
"""
credential_schema = CredentialSchema(async_mode=False)
credential_schema: Union[AzureKeyCredentialSchema, TokenCredentialSchema]
if self.options["credential_default_policy_type"] == "BearerTokenCredentialPolicy":
credential_schema = TokenCredentialSchema(async_mode=False)
else:
credential_schema = AzureKeyCredentialSchema()
credential_parameter = Parameter(
yaml_data={},
schema=credential_schema,
Expand All @@ -191,6 +151,7 @@ def _lro_initial_function(operation: LROOperation) -> Operation:
description="",
url=operation.url,
method=operation.method,
multipart=operation.multipart,
api_versions=operation.api_versions,
parameters=operation.parameters.parameters,
requests=operation.requests,
Expand Down
83 changes: 83 additions & 0 deletions autorest/codegen/models/credential_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from .base_schema import BaseSchema
from .imports import FileImport, ImportType, TypingSection

class CredentialSchema(BaseSchema):
def __init__(self) -> None: # pylint: disable=super-init-not-called
self.default_value = None

@property
def docstring_type(self) -> str:
return self.serialization_type

@property
def docstring_text(self) -> str:
return "credential"

@property
def serialization_type(self) -> str:
# this property is added, because otherwise pylint says that
# abstract serialization_type in BaseSchema is not overridden
pass


class AzureKeyCredentialSchema(CredentialSchema):

@property
def serialization_type(self) -> str:
return "~azure.core.credentials.AzureKeyCredential"

@property
def type_annotation(self) -> str:
return "AzureKeyCredential"

def imports(self) -> FileImport:
file_import = FileImport()
file_import.add_from_import(
"azure.core.credentials",
"AzureKeyCredential",
ImportType.AZURECORE,
typing_section=TypingSection.CONDITIONAL
)
return file_import


class TokenCredentialSchema(CredentialSchema):
def __init__(self, async_mode) -> None:
super(TokenCredentialSchema, self).__init__()
self.async_mode = async_mode
self.async_type = "~azure.core.credentials_async.AsyncTokenCredential"
self.sync_type = "~azure.core.credentials.TokenCredential"

@property
def serialization_type(self) -> str:
if self.async_mode:
return self.async_type
return self.sync_type

@property
def type_annotation(self) -> str:
if self.async_mode:
return '"AsyncTokenCredential"'
return '"TokenCredential"'


def imports(self) -> FileImport:
file_import = FileImport()
if self.async_mode:
file_import.add_from_import(
"azure.core.credentials_async", "AsyncTokenCredential",
ImportType.AZURECORE,
typing_section=TypingSection.TYPING
)
else:
file_import.add_from_import(
"azure.core.credentials", "TokenCredential",
ImportType.AZURECORE,
typing_section=TypingSection.TYPING
)
return file_import
2 changes: 2 additions & 0 deletions autorest/codegen/models/lro_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
description: str,
url: str,
method: str,
multipart: bool,
api_versions: Set[str],
requests: List[SchemaRequest],
summary: Optional[str] = None,
Expand All @@ -40,6 +41,7 @@ def __init__(
description,
url,
method,
multipart,
api_versions,
requests,
summary,
Expand Down
3 changes: 2 additions & 1 deletion autorest/codegen/models/lro_paging_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(
description: str,
url: str,
method: str,
multipart: bool,
api_versions: Set[str],
requests: List[SchemaRequest],
summary: Optional[str] = None,
Expand All @@ -36,6 +37,7 @@ def __init__(
description,
url,
method,
multipart,
api_versions,
requests,
summary,
Expand All @@ -55,4 +57,3 @@ def imports(self, code_model, async_mode: bool) -> FileImport:
file_import = lro_imports
file_import.merge(paging_imports)
return file_import

Loading

0 comments on commit 2d65d35

Please sign in to comment.