Skip to content

Commit

Permalink
[CanonicalEmitter] Add option and isArmCommonType check (#1065)
Browse files Browse the repository at this point in the history
This PR addressed 2 issues:
1. add option "use-read-only-status-schema" to fix
ProvisioningStateMustBeReadOnly bug;
The bug is mentioned here
https://github.com/Azure/azure-rest-api-specs/discussions/29471 and the
suggested walkaround is set option "use-read-only-status-schema" to
true.
Canonical emitter doesn't have this option. So add this option to the
emitter.

![image](https://github.com/Azure/typespec-azure/assets/8683976/1e12d103-7710-4d92-8458-da8a1c98ae66)


2. add isArmCommonType check to avoid decorator validation in canonical
emitter
Canonical emitter will generate warning when @typeChangedFrom decorator
is used. To make sure this not apply to common type, add isArmCommonType
check

---------

Co-authored-by: Ding <dinwa@microsoft.com>
  • Loading branch information
dinwa-ms and Ding authored Jun 26, 2024
1 parent 83851cb commit ed1017c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@azure-tools/typespec-autorest-canonical"
---

set option "use-read-only-status-schema" to true to fix ProvisioningStateMustBeReadOnly bug;
add isArmCommonType check to avoid decorator validation in canonical emitter
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-autorest-canonical"
---

update the canonical swagger file folder name
2 changes: 2 additions & 0 deletions packages/typespec-autorest-canonical/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@
"peerDependencies": {
"@azure-tools/typespec-autorest": "workspace:~",
"@azure-tools/typespec-azure-core": "workspace:~",
"@azure-tools/typespec-azure-resource-manager": "workspace:~",
"@azure-tools/typespec-client-generator-core": "workspace:~",
"@typespec/versioning": "workspace:~"
},
"devDependencies": {
"@azure-tools/typespec-autorest": "workspace:~",
"@azure-tools/typespec-azure-core": "workspace:~",
"@azure-tools/typespec-azure-resource-manager": "workspace:~",
"@azure-tools/typespec-client-generator-core": "workspace:~",
"@types/node": "~18.11.19",
"@typespec/compiler": "workspace:~",
Expand Down
6 changes: 6 additions & 0 deletions packages/typespec-autorest-canonical/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getOpenAPIForService,
sortOpenAPIDocument,
} from "@azure-tools/typespec-autorest";
import { isArmCommonType } from "@azure-tools/typespec-azure-resource-manager";
import { SdkContext, createSdkContext } from "@azure-tools/typespec-client-generator-core";
import {
EmitContext,
Expand Down Expand Up @@ -65,6 +66,7 @@ export async function $onEmit(context: EmitContext<AutorestCanonicalEmitterOptio
omitUnreachableTypes: resolvedOptions["omit-unreachable-types"],
includeXTypeSpecName: resolvedOptions["include-x-typespec-name"],
armTypesDir,
useReadOnlyStatusSchema: true,
};

await emitAllServices(context.program, tcgcSdkContext, options);
Expand Down Expand Up @@ -162,6 +164,10 @@ function validateUnsupportedVersioning(program: Program, namespace: Namespace) {
}
},
modelProperty: (prop) => {
if (isArmCommonType(prop) || (prop.model && isArmCommonType(prop.model))) {
return;
}

if (getRenamedFrom(program, prop)) {
reportDisallowedDecorator("renamedFrom", prop);
}
Expand Down
36 changes: 0 additions & 36 deletions packages/typespec-autorest-canonical/test/property-schema.test.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/typespec-autorest-canonical/test/test-host.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpenAPI2Document } from "@azure-tools/typespec-autorest";
import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing";
import { AzureResourceManagerTestLibrary } from "@azure-tools/typespec-azure-resource-manager/testing";
import { SdkTestLibrary as TcgcTestLibrary } from "@azure-tools/typespec-client-generator-core/testing";
import { Diagnostic } from "@typespec/compiler";
import {
Expand All @@ -26,6 +27,7 @@ export async function createAutorestCanonicalTestHost() {
AutorestCanonicalTestLibrary,
VersioningTestLibrary,
AzureCoreTestLibrary,
AzureResourceManagerTestLibrary,
TcgcTestLibrary,
],
});
Expand Down
3 changes: 2 additions & 1 deletion packages/typespec-autorest-canonical/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{ "path": "../../core/packages/compiler/tsconfig.json" },
{ "path": "../../core/packages/http/tsconfig.json" },
{ "path": "../../core/packages/openapi/tsconfig.json" },
{ "path": "../typespec-azure-core/tsconfig.json" }
{ "path": "../typespec-azure-core/tsconfig.json" },
{ "path": "../typespec-azure-resource-manager/tsconfig.json" }
],
"compilerOptions": {
"outDir": "dist",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed1017c

Please sign in to comment.