Skip to content
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

Fix several issues in converter #5050

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Fix the ResourceListResult issue in data plane.",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import pluralize from "pluralize";
import {
TypespecOperation,
TspArmResource,
isArmResourceActionOperation,
TypespecTemplateModel,
TypespecVoidType,
TspLroHeaders,
Expand Down Expand Up @@ -129,7 +128,7 @@ function generateArmResourceOperation(resource: TspArmResource): string {
definitions.push(
`${operation.name} is ${operation.kind}<${operation.resource}, ${generateArmRequest(
operation.request,
)}, ${generateArmResponse(operation.response)}${operation.baseParameters![0]}${
)}, ${generateArmResponse(operation.response)}, BaseParameters = ${operation.baseParameters![0]}${
operation.parameters ? `, Parameters = { ${generateParameters(operation.parameters)} }` : ""
}>`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
TspArmResourceLifeCycleOperation,
TspArmResourceListOperation,
isArmResourceActionOperation,
TypespecDataType,
} from "../interfaces";
import { getOptions, updateOptions } from "../options";
import { createClientNameDecorator, createCSharpNameDecorator } from "../pretransforms/rename-pretransform";
Expand All @@ -42,14 +41,8 @@ import {
getResourceOperations,
isResourceSchema,
} from "../utils/resource-discovery";
import { isArraySchema, isResponseSchema } from "../utils/schemas";
import { getSuppresssionWithCode } from "../utils/suppressions";
import {
getFullyQualifiedName,
getTemplateResponses,
isResourceListResult,
NamesOfResponseTemplate,
} from "../utils/type-mapping";
import { getFullyQualifiedName, getTemplateResponses, NamesOfResponseTemplate } from "../utils/type-mapping";
import { getTypespecType, isTypespecType, transformObjectProperty } from "./transform-object";
import { transformParameter } from "./transform-operations";

Expand Down Expand Up @@ -790,9 +783,13 @@ function buildBodyDecorator(
}

function getOtherProperties(schema: ArmResourceSchema, noCommonTypes: boolean): TypespecObjectProperty[] {
const knownProperties = ["properties", "name"];
const knownProperties = ["properties", "name", "id", "type", "systemData"];
const resourceKind = getResourceKind(schema);
if (resourceKind === "TrackedResource") {
knownProperties.push(...["location", "tags"]);
}
if (!noCommonTypes) {
knownProperties.push(...["id", "type", "systemData", "location", "tags", "identity", "sku", "eTag", "plan"]);
knownProperties.push(...["identity", "sku", "eTag", "plan"]);
}
const otherProperties: TypespecObjectProperty[] = [];
for (const property of schema.properties ?? []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ function transformVerb(protocol?: Protocols) {
}

function transformResponse(response: Response): [string, string] {
const { isArm } = getOptions();
const statusCode = response.protocol.http?.statusCodes[0] as string;
const codeModel = getSession().model;
const dataTypes = getDataTypes(codeModel);
if (!isResponseSchema(response)) {
return [statusCode, "void"];
}

if (isResourceListResult(response)) {
if (isResourceListResult(response) && isArm) {
const valueSchema = ((response as SchemaResponse).schema as ObjectSchema).properties?.find(
(p) => p.language.default.name === "value",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ model DeletedServiceContract
SegmentName = "deletedservices",
NamePattern = "^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$"
>;

/**
* API Management Service Master Location.
*/
@visibility("read")
location?: string;
}

@armResourceOperations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,6 @@ model CloudService
NamePattern = ""
>;

/**
* Resource Id.
*/
@visibility("read")
id?: string;

/**
* Resource type.
*/
@visibility("read")
type?: string;

/**
* Resource location.
*/
location: string;

/**
* Resource tags.
*/
#suppress "@azure-tools/typespec-azure-resource-manager/arm-no-record" "For backward compatibility"
tags?: Record<string>;

/**
* Metadata pertaining to creation and last modification of the resource.
*/
@visibility("read")
systemData?: SystemData;

/**
* List of logical availability zone of the resource. List should contain only 1 zone where cloud service should be provisioned. This field is optional.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ model CloudServiceRole
NamePattern = ""
>;

/**
* Resource id
*/
@visibility("read")
id?: string;

/**
* Resource type
*/
@visibility("read")
type?: string;

/**
* Resource location
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ interface DedicatedHosts {
restart is ArmResourceActionAsyncBase<
DedicatedHost,
void,
OkResponseDefaultBaseParameters<DedicatedHost>
OkResponse,
BaseParameters = DefaultBaseParameters<DedicatedHost>
>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ model OSFamily is Azure.ResourceManager.ProxyResource<OSFamilyProperties> {
NamePattern = ""
>;

/**
* Resource Id.
*/
@visibility("read")
id?: string;

/**
* Resource type.
*/
@visibility("read")
type?: string;

/**
* Resource location.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ model OSVersion is Azure.ResourceManager.ProxyResource<OSVersionProperties> {
NamePattern = ""
>;

/**
* Resource Id.
*/
@visibility("read")
id?: string;

/**
* Resource type.
*/
@visibility("read")
type?: string;

/**
* Resource location.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ model PrivateEndpointConnection
SegmentName = "privateEndpointConnections",
NamePattern = ""
>;

/**
* private endpoint connection Id
*/
@visibility("read")
id?: string;

/**
* private endpoint connection type
*/
@visibility("read")
type?: string;
}

@armResourceOperations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,6 @@ model RoleInstance
NamePattern = ""
>;

/**
* Resource Id
*/
@visibility("read")
id?: string;

/**
* Resource Type.
*/
@visibility("read")
type?: string;

/**
* Resource Location.
*/
@visibility("read")
location?: string;

/**
* Resource tags.
*/
#suppress "@azure-tools/typespec-azure-resource-manager/arm-no-record" "For backward compatibility"
@visibility("read")
tags?: Record<string>;

/**
* The role instance SKU.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ model VirtualMachineScaleSetExtension
SegmentName = "extensions",
NamePattern = ""
>;

/**
* Resource type
*/
@visibility("read")
type?: string;
}

@armResourceOperations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ model VirtualMachineScaleSetVMExtension
NamePattern = ""
>;

/**
* Resource type
*/
@visibility("read")
type?: string;

/**
* The location of the extension.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,7 @@ interface RoleAssignmentsOperations {
@query("$filter")
$filter?: string;
},
ResourceListResult<RoleAssignment>
RoleAssignmentListResult
>;
}

Expand Down
Loading