Skip to content

Commit

Permalink
update additional properties test (#2518)
Browse files Browse the repository at this point in the history
* update additional properties test

* add test for ser/deser of additional properties

* add more types

* update dependencies

* add changelog
  • Loading branch information
tadelesh authored Apr 23, 2024
1 parent 08e1093 commit 3129511
Show file tree
Hide file tree
Showing 20 changed files with 3,299 additions and 1,038 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-python"
---

Support TypeSpec new additional properties syntax.
4 changes: 2 additions & 2 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.2 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.3 <1.0.0",
"@typespec/compiler": ">=0.55.0 <1.0.0",
"@typespec/http": ">=0.55.0 <1.0.0",
"@typespec/rest": ">=0.55.0 <1.0.0",
Expand Down Expand Up @@ -78,7 +78,7 @@
"rimraf": "~5.0.0",
"typescript": "~5.1.3",
"@azure-tools/typespec-azure-core": "~0.41.0",
"@azure-tools/typespec-client-generator-core": "~0.41.2",
"@azure-tools/typespec-client-generator-core": "~0.41.3",
"@typespec/compiler": "~0.55.0",
"@typespec/http": "~0.55.0",
"@typespec/rest": "~0.55.0",
Expand Down
9 changes: 2 additions & 7 deletions packages/typespec-python/src/code-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function emitLroPagingMethod<TServiceOperation extends SdkServiceOperation>(

function emitMethodParameter<TServiceOperation extends SdkServiceOperation>(
context: PythonSdkContext<TServiceOperation>,
client: SdkClientType<TServiceOperation>,
parameter: SdkEndpointParameter | SdkCredentialParameter | SdkMethodParameter,
): Record<string, any>[] {
if (parameter.kind === "endpoint") {
Expand Down Expand Up @@ -206,17 +205,13 @@ function emitClient<TServiceOperation extends SdkServiceOperation>(
context.__endpointPathParameters = [];
}
const parameters =
client.initialization?.properties
.map((x) => emitMethodParameter(context, client, x))
.reduce((a, b) => [...a, ...b]) ?? [];
client.initialization?.properties.map((x) => emitMethodParameter(context, x)).reduce((a, b) => [...a, ...b]) ??
[];

const endpointParameter = client.initialization?.properties.find((x) => x.kind === "endpoint") as
| SdkEndpointParameter
| undefined;
const operationGroups = emitOperationGroups(context, client, client, "");
if (context.__subscriptionIdPathParameter) {
parameters.push(context.__subscriptionIdPathParameter);
}
return {
name: client.name,
description: client.description ?? "",
Expand Down
1 change: 0 additions & 1 deletion packages/typespec-python/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function createPythonSdkContext<TServiceOperation extends SdkServiceOperation>(
return {
...createSdkContext<PythonEmitterOptions, TServiceOperation>(context, "@azure-tools/typespec-python"),
__endpointPathParameters: [],
__subscriptionIdPathParameter: undefined,
};
}

Expand Down
4 changes: 0 additions & 4 deletions packages/typespec-python/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
getImplementation,
isAbstract,
isAzureCoreModel,
isSubscriptionId,
} from "./utils.js";
import { KnownTypes, getType } from "./types.js";
import { PythonSdkContext } from "./lib.js";
Expand Down Expand Up @@ -295,9 +294,6 @@ function emitHttpParameters(
parameters.push(emitHttpPathParameter(context, parameter));
break;
}
if (isSubscriptionId(context, parameter) && context.__subscriptionIdPathParameter === undefined) {
context.__subscriptionIdPathParameter = parameters[parameters.length - 1];
}
}
return parameters;
}
Expand Down
1 change: 0 additions & 1 deletion packages/typespec-python/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface PythonEmitterOptions {
export interface PythonSdkContext<TServiceOperation extends SdkServiceOperation>
extends SdkContext<PythonEmitterOptions, TServiceOperation> {
__endpointPathParameters: Record<string, any>[];
__subscriptionIdPathParameter: Record<string, any> | undefined;
}

const EmitterOptionsSchema: JSONSchemaType<PythonEmitterOptions> = {
Expand Down
12 changes: 0 additions & 12 deletions packages/typespec-python/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export function getImplementation<TServiceOperation extends SdkServiceOperation>
parameter: SdkParameter | SdkHttpParameter,
): "Client" | "Method" {
if (parameter.onClient) return "Client";
if (isSubscriptionId(context, parameter)) return "Client";
return "Method";
}

Expand Down Expand Up @@ -83,17 +82,6 @@ export function getAddedOn<TServiceOperation extends SdkServiceOperation>(
return type.apiVersions[0];
}

export function isSubscriptionId<TServiceOperation extends SdkServiceOperation>(
context: PythonSdkContext<TServiceOperation>,
parameter: SdkParameter | SdkHttpParameter,
): boolean {
return (
Boolean(context.arm) &&
(parameter.kind === "query" || parameter.kind === "path" || parameter.kind === "header") &&
parameter.serializedName === "subscriptionId"
);
}

export function emitParamBase<TServiceOperation extends SdkServiceOperation>(
context: PythonSdkContext<TServiceOperation>,
parameter: SdkParameter | SdkHttpParameter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"CrossLanguagePackageId": "Type.Property.AdditionalProperties",
"CrossLanguageDefinitionId": {
"typetest.property.additionalproperties.models.DifferentSpreadFloatRecord": "Type.Property.AdditionalProperties.DifferentSpreadFloatRecord",
"typetest.property.additionalproperties.models.DifferentSpreadFloatDerived": "Type.Property.AdditionalProperties.DifferentSpreadFloatDerived",
"typetest.property.additionalproperties.models.DifferentSpreadModelArrayRecord": "Type.Property.AdditionalProperties.DifferentSpreadModelArrayRecord",
"typetest.property.additionalproperties.models.DifferentSpreadModelArrayDerived": "Type.Property.AdditionalProperties.DifferentSpreadModelArrayDerived",
"typetest.property.additionalproperties.models.DifferentSpreadModelRecord": "Type.Property.AdditionalProperties.DifferentSpreadModelRecord",
"typetest.property.additionalproperties.models.DifferentSpreadModelDerived": "Type.Property.AdditionalProperties.DifferentSpreadModelDerived",
"typetest.property.additionalproperties.models.DifferentSpreadStringRecord": "Type.Property.AdditionalProperties.DifferentSpreadStringRecord",
"typetest.property.additionalproperties.models.DifferentSpreadStringDerived": "Type.Property.AdditionalProperties.DifferentSpreadStringDerived",
"typetest.property.additionalproperties.models.ExtendsFloatAdditionalProperties": "Type.Property.AdditionalProperties.ExtendsFloatAdditionalProperties",
"typetest.property.additionalproperties.models.ExtendsModelAdditionalProperties": "Type.Property.AdditionalProperties.ExtendsModelAdditionalProperties",
Expand All @@ -22,6 +26,16 @@
"typetest.property.additionalproperties.models.IsUnknownAdditionalPropertiesDiscriminated": "Type.Property.AdditionalProperties.IsUnknownAdditionalPropertiesDiscriminated",
"typetest.property.additionalproperties.models.IsUnknownAdditionalPropertiesDiscriminatedDerived": "Type.Property.AdditionalProperties.IsUnknownAdditionalPropertiesDiscriminatedDerived",
"typetest.property.additionalproperties.models.ModelForRecord": "Type.Property.AdditionalProperties.ModelForRecord",
"typetest.property.additionalproperties.models.MultipleSpreadRecord": "Type.Property.AdditionalProperties.MultipleSpreadRecord",
"typetest.property.additionalproperties.models.SpreadFloatRecord": "Type.Property.AdditionalProperties.SpreadFloatRecord",
"typetest.property.additionalproperties.models.SpreadModelArrayRecord": "Type.Property.AdditionalProperties.SpreadModelArrayRecord",
"typetest.property.additionalproperties.models.SpreadModelRecord": "Type.Property.AdditionalProperties.SpreadModelRecord",
"typetest.property.additionalproperties.models.SpreadRecordForDiscriminatedUnion": "Type.Property.AdditionalProperties.SpreadRecordForDiscriminatedUnion",
"typetest.property.additionalproperties.models.SpreadRecordForNonDiscriminatedUnion": "Type.Property.AdditionalProperties.SpreadRecordForNonDiscriminatedUnion",
"typetest.property.additionalproperties.models.SpreadRecordForNonDiscriminatedUnion2": "Type.Property.AdditionalProperties.SpreadRecordForNonDiscriminatedUnion2",
"typetest.property.additionalproperties.models.SpreadRecordForNonDiscriminatedUnion3": "Type.Property.AdditionalProperties.SpreadRecordForNonDiscriminatedUnion3",
"typetest.property.additionalproperties.models.SpreadRecordForUnion": "Type.Property.AdditionalProperties.SpreadRecordForUnion",
"typetest.property.additionalproperties.models.SpreadStringRecord": "Type.Property.AdditionalProperties.SpreadStringRecord",
"typetest.property.additionalproperties.models.WidgetData0": "Type.Property.AdditionalProperties.WidgetData0",
"typetest.property.additionalproperties.models.WidgetData1": "Type.Property.AdditionalProperties.WidgetData1",
"typetest.property.additionalproperties.models.WidgetData2": "Type.Property.AdditionalProperties.WidgetData2",
Expand Down
Loading

0 comments on commit 3129511

Please sign in to comment.