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

arm, remove special handling for ARM types #2749

Merged
merged 4 commits into from
May 11, 2024
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
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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading