Skip to content

Commit

Permalink
adopt new spread behavior from tcgc (#2676)
Browse files Browse the repository at this point in the history
* adopt new spread behavior from tcgc

* fix

* async update

* changelog

* fix test

* format

* test new pkg

* upgrade to dev version
  • Loading branch information
tadelesh committed Jul 9, 2024
1 parent 507d8ca commit 22a843f
Show file tree
Hide file tree
Showing 128 changed files with 14,598 additions and 310 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/new_spread-2024-6-2-23-6-56.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-python"
---

spread object when it is spread in TypeSpec
6 changes: 3 additions & 3 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@azure-tools/typespec-azure-core": ">=0.43.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.43.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.43.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.43.1 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.43.2 <1.0.0",
"@typespec/compiler": ">=0.57.0 <1.0.0",
"@typespec/http": ">=0.57.0 <1.0.0",
"@typespec/rest": ">=0.57.0 <1.0.0",
Expand All @@ -70,7 +70,7 @@
"@azure-tools/typespec-azure-resource-manager": "~0.43.0",
"@azure-tools/typespec-autorest": "~0.43.0",
"@azure-tools/cadl-ranch-expect": "~0.14.0",
"@azure-tools/cadl-ranch-specs": "~0.34.0",
"@azure-tools/cadl-ranch-specs": "~0.34.3",
"@types/js-yaml": "~4.0.5",
"@types/mocha": "~10.0.1",
"@types/node": "^18.16.3",
Expand All @@ -82,7 +82,7 @@
"rimraf": "~5.0.0",
"typescript": "~5.1.3",
"@azure-tools/typespec-azure-core": "~0.43.0",
"@azure-tools/typespec-client-generator-core": "~0.43.1",
"@azure-tools/typespec-client-generator-core": "~0.43.2",
"@typespec/compiler": "~0.57.0",
"@typespec/http": "~0.57.0",
"@typespec/rest": "~0.57.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-python/src/code-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export function emitCodeModel<TServiceOperation extends SdkServiceOperation>(
subnamespaceToClients: {},
};
for (const model of sdkPackage.models) {
if (model.name === "") {
if (model.name === "" || (model.usage & UsageFlags.Spread) > 0) {
continue;
}
getType(sdkContext, model);
Expand Down
3 changes: 2 additions & 1 deletion packages/typespec-python/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SdkQueryParameter,
SdkServiceMethod,
SdkServiceResponseHeader,
UsageFlags,
} from "@azure-tools/typespec-client-generator-core";
import {
camelToSnakeCase,
Expand Down Expand Up @@ -178,7 +179,7 @@ function emitHttpOperation(
if (
result.bodyParameter &&
operation.bodyParam?.type.kind === "model" &&
operation.bodyParam?.type.isGeneratedName
(operation.bodyParam?.type.usage & UsageFlags.Spread) > 0
) {
result.bodyParameter["propertyToParameterName"] = {};
result.bodyParameter["defaultToUnsetSentinel"] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class InvalidAuth(_model_base.Model):
"""InvalidAuth.
All required parameters must be populated in order to send to server.
:ivar error: Required.
:vartype error: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class InvalidAuth(_model_base.Model):
"""InvalidAuth.
All required parameters must be populated in order to send to server.
:ivar error: Required.
:vartype error: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class InvalidAuth(_model_base.Model):
"""InvalidAuth.
All required parameters must be populated in order to send to server.
:ivar error: Required.
:vartype error: str
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release History

## 1.0.0b1 (1970-01-01)

- Initial version
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include *.md
include LICENSE
include specs/azure/core/model/py.typed
recursive-include tests *.py
recursive-include samples *.py *.md
include specs/__init__.py
include specs/azure/__init__.py
include specs/azure/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@


# Specs Azure Core Model client library for Python
<!-- write necessary description of service -->

## Getting started

### Install the package

```bash
python -m pip install specs-azure-core-model
```

#### 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 Specs Azure Core Model 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 [email protected] 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,9 @@
{
"CrossLanguagePackageId": "_Specs_.Azure.Core.Model",
"CrossLanguageDefinitionId": {
"specs.azure.core.model.models.AzureEmbeddingModel": "_Specs_.Azure.Core.Model.AzureEmbeddingModel",
"specs.azure.core.model.ModelClient.azure_core_embedding_vector.get": "_Specs_.Azure.Core.Model.AzureCoreEmbeddingVector.get",
"specs.azure.core.model.ModelClient.azure_core_embedding_vector.put": "_Specs_.Azure.Core.Model.AzureCoreEmbeddingVector.put",
"specs.azure.core.model.ModelClient.azure_core_embedding_vector.post": "_Specs_.Azure.Core.Model.AzureCoreEmbeddingVector.post"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-e ../../../tools/azure-sdk-tools
../../core/azure-core
aiohttp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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.
# --------------------------------------------------------------------------
import os
import pytest
from dotenv import load_dotenv
from devtools_testutils import (
test_proxy,
add_general_regex_sanitizer,
add_body_key_sanitizer,
add_header_regex_sanitizer,
)

load_dotenv()


# aovid record sensitive identity information in recordings
@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy):
model_subscription_id = os.environ.get("MODEL_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
model_tenant_id = os.environ.get("MODEL_TENANT_ID", "00000000-0000-0000-0000-000000000000")
model_client_id = os.environ.get("MODEL_CLIENT_ID", "00000000-0000-0000-0000-000000000000")
model_client_secret = os.environ.get("MODEL_CLIENT_SECRET", "00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=model_subscription_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=model_tenant_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=model_client_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=model_client_secret, value="00000000-0000-0000-0000-000000000000")

add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]")
add_header_regex_sanitizer(key="Cookie", value="cookie;")
add_body_key_sanitizer(json_path="$..access_token", value="access_token")
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.
# --------------------------------------------------------------------------
import pytest
from devtools_testutils import recorded_by_proxy
from testpreparer import ModelClientTestBase, ModelPreparer


@pytest.mark.skip("you may need to update the auto-generated test case before run it")
class TestModelAzureCoreEmbeddingVectorOperations(ModelClientTestBase):
@ModelPreparer()
@recorded_by_proxy
def test_get(self, model_endpoint):
client = self.create_client(endpoint=model_endpoint)
response = client.azure_core_embedding_vector.get()

# please add some check logic here by yourself
# ...

@ModelPreparer()
@recorded_by_proxy
def test_put(self, model_endpoint):
client = self.create_client(endpoint=model_endpoint)
response = client.azure_core_embedding_vector.put(
body=[0],
)

# please add some check logic here by yourself
# ...

@ModelPreparer()
@recorded_by_proxy
def test_post(self, model_endpoint):
client = self.create_client(endpoint=model_endpoint)
response = client.azure_core_embedding_vector.post(
body={"embedding": [0]},
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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.
# --------------------------------------------------------------------------
import pytest
from devtools_testutils.aio import recorded_by_proxy_async
from testpreparer import ModelPreparer
from testpreparer_async import ModelClientTestBaseAsync


@pytest.mark.skip("you may need to update the auto-generated test case before run it")
class TestModelAzureCoreEmbeddingVectorOperationsAsync(ModelClientTestBaseAsync):
@ModelPreparer()
@recorded_by_proxy_async
async def test_get(self, model_endpoint):
client = self.create_async_client(endpoint=model_endpoint)
response = await client.azure_core_embedding_vector.get()

# please add some check logic here by yourself
# ...

@ModelPreparer()
@recorded_by_proxy_async
async def test_put(self, model_endpoint):
client = self.create_async_client(endpoint=model_endpoint)
response = await client.azure_core_embedding_vector.put(
body=[0],
)

# please add some check logic here by yourself
# ...

@ModelPreparer()
@recorded_by_proxy_async
async def test_post(self, model_endpoint):
client = self.create_async_client(endpoint=model_endpoint)
response = await client.azure_core_embedding_vector.post(
body={"embedding": [0]},
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 devtools_testutils import AzureRecordedTestCase, PowerShellPreparer
import functools
from specs.azure.core.model import ModelClient


class ModelClientTestBase(AzureRecordedTestCase):

def create_client(self, endpoint):
credential = self.get_credential(ModelClient)
return self.create_client_from_credential(
ModelClient,
credential=credential,
endpoint=endpoint,
)


ModelPreparer = functools.partial(PowerShellPreparer, "model", model_endpoint="https://fake_model_endpoint.com")
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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 devtools_testutils import AzureRecordedTestCase
from specs.azure.core.model.aio import ModelClient


class ModelClientTestBaseAsync(AzureRecordedTestCase):

def create_async_client(self, endpoint):
credential = self.get_credential(ModelClient, is_async=True)
return self.create_client_from_credential(
ModelClient,
credential=credential,
endpoint=endpoint,
)
Loading

0 comments on commit 22a843f

Please sign in to comment.