Skip to content

Commit

Permalink
arm, remove special handling for ARM types (#2749)
Browse files Browse the repository at this point in the history
* remove dummy resource schema

* re-generate test code

* remove deduplication logic

* fix lint, add back one ArmResource

---------

Co-authored-by: actions-user <[email protected]>
  • Loading branch information
XiaofeiCao and actions-user authored May 11, 2024
1 parent b010511 commit e612740
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 59 deletions.
46 changes: 0 additions & 46 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
getEncode,
getOverloadedOperation,
EnumMember,
walkPropertiesInherited,
isVoidType,
isErrorModel,
} from "@typespec/compiler";
Expand Down Expand Up @@ -489,10 +488,6 @@ export class CodeModelBuilder {
// deduplicate model name
const nameCount = new Map<string, number>();
const deduplicateName = (schema: Schema) => {
// skip models under "Azure.ResourceManager"
if (this.isArm() && schema.language.default?.namespace?.startsWith("Azure.ResourceManager")) {
return;
}
const name = schema.language.default.name;
// skip models under "com.azure.core."
if (name && !schema.language.java?.namespace?.startsWith("com.azure.core.")) {
Expand Down Expand Up @@ -2146,21 +2141,6 @@ export class CodeModelBuilder {

private processObjectSchema(type: Model, name: string): ObjectSchema {
const namespace = getNamespace(type);
if (
(this.isArm() &&
namespace?.startsWith("Azure.ResourceManager") &&
// there's ResourceListResult under Azure.ResourceManager namespace,
// which shouldn't be considered Resource schema parent
(name?.startsWith("TrackedResource") ||
name?.startsWith("ExtensionResource") ||
name?.startsWith("ProxyResource"))) ||
name === "ArmResource"
) {
const objectSchema = this.dummyResourceSchema(type, name, namespace);
this.codeModel.schemas.add(objectSchema);

return objectSchema;
}
const objectSchema = new ObjectScheme(name, this.getDoc(type), {
summary: this.getSummary(type),
language: {
Expand Down Expand Up @@ -2337,32 +2317,6 @@ export class CodeModelBuilder {
return type;
}

private dummyResourceSchema(type: Model, name?: string, namespace?: string): ObjectSchema {
const resourceModelName = name?.startsWith("TrackedResource") ? "Resource" : "ProxyResource";
const resource = this.dummyObjectSchema(type, resourceModelName, namespace);
const declaredProperties = walkPropertiesInherited(type);
for (const prop of declaredProperties) {
resource.addProperty(this.processModelProperty(prop));
}
return resource;
}

private dummyObjectSchema(type: Model, name: string, namespace?: string): ObjectSchema {
return new ObjectScheme(name, this.getDoc(type), {
summary: this.getSummary(type),
language: {
default: {
name: name,
namespace: namespace,
},
java: {
name: name,
namespace: getJavaNamespace(namespace),
},
},
});
}

private applyModelPropertyDecorators(prop: ModelProperty, nameHint: string, schema: Schema): Schema {
// if (schema instanceof StringSchema) {
// const decorators = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,62 @@
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.fluent.models.ChildResourceProperties",
"name" : "com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceInner",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.models.ChildResourceUpdate",
"name" : "com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceProperties",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.implementation.models.ChildResourceListResult",
"name" : "com.cadl.armresourceprovider.fluent.models.CustomTemplateResourceInner",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceInner",
"name" : "com.cadl.armresourceprovider.fluent.models.CustomTemplateResourceProperties",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.fluent.models.TopLevelArmResourceProperties",
"name" : "com.cadl.armresourceprovider.models.ManagedServiceIdentity",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.models.TopLevelArmResourceUpdate",
"name" : "com.cadl.armresourceprovider.models.UserAssignedIdentity",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.models.TopLevelArmResourceUpdateProperties",
"name" : "com.cadl.armresourceprovider.fluent.models.ChildResourceProperties",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.implementation.models.TopLevelArmResourceListResult",
"name" : "com.cadl.armresourceprovider.models.ChildResourceUpdate",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.fluent.models.CustomTemplateResourceInner",
"name" : "com.cadl.armresourceprovider.implementation.models.ChildResourceListResult",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.fluent.models.CustomTemplateResourceProperties",
"name" : "com.cadl.armresourceprovider.models.TopLevelArmResourceUpdate",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.models.ManagedServiceIdentity",
"name" : "com.cadl.armresourceprovider.models.TopLevelArmResourceUpdateProperties",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
}, {
"name" : "com.cadl.armresourceprovider.models.UserAssignedIdentity",
"name" : "com.cadl.armresourceprovider.implementation.models.TopLevelArmResourceListResult",
"allDeclaredConstructors" : true,
"allDeclaredFields" : true,
"allDeclaredMethods" : true
Expand Down
2 changes: 1 addition & 1 deletion typespec-tests/tsp/arm.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ interface Operations extends Azure.ResourceManager.Operations {}
@armResourceCreateOrUpdate(TResource)
@patch
op ArmResourceUpdateSync<
TResource extends Azure.ResourceManager.Foundations.Resource,
TResource extends Azure.ResourceManager.Foundations.ArmResource,
TBaseParameters = Azure.ResourceManager.Foundations.BaseParameters<TResource>
>(
...ResourceInstanceParameters<TResource, TBaseParameters>,
Expand Down

0 comments on commit e612740

Please sign in to comment.