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

[tcgc] add example model in tcgc #1076

Merged
merged 50 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0e0995e
wip
tadelesh Jun 14, 2024
f26d980
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jun 14, 2024
ed2d59f
add interface
tadelesh Jun 14, 2024
38cbc1e
add resp header
tadelesh Jun 17, 2024
81bb593
update
tadelesh Jun 18, 2024
b979ece
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jun 19, 2024
a4c5434
init impl
tadelesh Jun 21, 2024
831bb03
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jun 21, 2024
e2ad988
init test support
tadelesh Jun 24, 2024
e38ea8c
add test
tadelesh Jun 24, 2024
4f6983a
changelog
tadelesh Jun 24, 2024
8faef9d
add helper for those not adopt tcgc
tadelesh Jun 25, 2024
2e99efd
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jun 25, 2024
0648859
breaking change adoption
tadelesh Jun 25, 2024
464fb07
changelog
tadelesh Jun 25, 2024
0212155
adopt tcgc breaking
tadelesh Jun 26, 2024
97c2912
changelog
tadelesh Jun 26, 2024
5b7cb86
Merge branch 'main' into tcgc_sample
tadelesh Jun 26, 2024
928c685
fix lint
tadelesh Jun 26, 2024
833b46a
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jun 26, 2024
79cbde7
refine logic
tadelesh Jun 26, 2024
49e3535
fix test in ci
tadelesh Jun 26, 2024
0a40345
Rename Get.json to get.json
tadelesh Jun 26, 2024
70302e7
Merge branch 'main' into tcgc_sample
tadelesh Jun 26, 2024
8be5f98
Merge branch 'main' into tcgc_sample
tadelesh Jun 26, 2024
961eed7
refine
tadelesh Jul 1, 2024
d74a074
add doc
tadelesh Jul 1, 2024
00f0ebe
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jul 3, 2024
82e40dd
wip
tadelesh Jul 3, 2024
a3286fe
support client customization
tadelesh Jul 3, 2024
424b159
remove useless
tadelesh Jul 3, 2024
7ad27b5
remove useless
tadelesh Jul 3, 2024
a658bb1
merge main
tadelesh Jul 4, 2024
a433c1a
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jul 4, 2024
a175333
format
tadelesh Jul 4, 2024
24549fa
Merge branch 'main' into tcgc_sample
tadelesh Jul 4, 2024
3b748f4
fix
tadelesh Jul 4, 2024
72d13c0
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jul 11, 2024
3921bef
update package
tadelesh Jul 11, 2024
f0e2784
fix test
tadelesh Jul 12, 2024
906c6db
fix example load bug
tadelesh Jul 16, 2024
f221023
merge
tadelesh Jul 16, 2024
a44cabd
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jul 16, 2024
d6253c8
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jul 16, 2024
33468fd
format
tadelesh Jul 16, 2024
268f34c
Merge remote-tracking branch 'origin/main' into tcgc_sample
tadelesh Jul 17, 2024
e2880fc
update
tadelesh Jul 17, 2024
737d74e
Merge remote-tracking branch 'origin/release/july-2024' into tcgc_sample
tadelesh Jul 23, 2024
557e056
refine interface
tadelesh Jul 23, 2024
20aabcc
update lock file and format
tadelesh Jul 23, 2024
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
7 changes: 7 additions & 0 deletions .chronus/changes/tcgc_sample-2024-5-24-18-19-39.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-client-generator-core"
---

add example types support
7 changes: 7 additions & 0 deletions .chronus/changes/tcgc_sample-2024-5-25-18-26-42.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-autorest"
---

create tcgc context change to async
7 changes: 7 additions & 0 deletions .chronus/changes/tcgc_sample-2024-5-26-10-23-7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-autorest-canonical"
---

adopt tcgc breaking
5 changes: 4 additions & 1 deletion packages/typespec-autorest-canonical/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ interface ResolvedAutorestCanonicalEmitterOptions extends AutorestDocumentEmitte

export async function $onEmit(context: EmitContext<AutorestCanonicalEmitterOptions>) {
const resolvedOptions = { ...defaultOptions, ...context.options };
const tcgcSdkContext = createSdkContext(context, "@azure-tools/typespec-autorest-canonical");
const tcgcSdkContext = await createSdkContext(
context,
"@azure-tools/typespec-autorest-canonical"
);
const armTypesDir = interpolatePath(
resolvedOptions["arm-types-dir"] ?? "{project-root}/../../common-types/resource-management",
{
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-autorest/src/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export async function getAllServicesAtAllVersions(
program: Program,
options: ResolvedAutorestEmitterOptions
): Promise<AutorestServiceRecord[]> {
const tcgcSdkContext = createSdkContext(
const tcgcSdkContext = await createSdkContext(
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
{ program, options: {} } as any,
"@azure-tools/typespec-autorest",
{
Expand Down
3 changes: 2 additions & 1 deletion packages/typespec-client-generator-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@azure-tools/typespec-azure-core": "workspace:~",
"@typespec/compiler": "workspace:~",
"@typespec/http": "workspace:~",
"@typespec/openapi": "workspace:~",
"@typespec/rest": "workspace:~",
"@typespec/versioning": "workspace:~"
},
Expand All @@ -71,10 +72,10 @@
"@typespec/compiler": "workspace:~",
"@typespec/http": "workspace:~",
"@typespec/library-linter": "workspace:~",
"@typespec/openapi": "workspace:~",
"@typespec/prettier-plugin-typespec": "workspace:~",
"@typespec/rest": "workspace:~",
"@typespec/tspd": "workspace:~",
"@typespec/versioning": "workspace:~",
"@typespec/xml": "workspace:~",
"@vitest/coverage-v8": "^1.6.0",
"@vitest/ui": "^1.6.0",
Expand Down
27 changes: 16 additions & 11 deletions packages/typespec-client-generator-core/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import { isHeader } from "@typespec/http";
import { buildVersionProjections, getVersions } from "@typespec/versioning";
import { defaultDecoratorsAllowList } from "./configs.js";
import { handleClientExamples } from "./example.js";
import {
AccessFlags,
LanguageScopes,
Expand All @@ -41,7 +42,13 @@ import {
SdkServiceOperation,
UsageFlags,
} from "./interfaces.js";
import { AllScopes, TCGCContext, clientNameKey, parseEmitterName } from "./internal-utils.js";
import {
AllScopes,
TCGCContext,
clientNameKey,
getValidApiVersion,
parseEmitterName,
} from "./internal-utils.js";
import { createStateSymbol, reportDiagnostic } from "./lib.js";
import { getSdkPackage } from "./package.js";
import { getLibraryName } from "./public-utils.js";
Expand Down Expand Up @@ -230,14 +237,7 @@ function serviceVersioningProjection(context: TCGCContext, client: SdkClient) {
?.getVersions()
.map((x) => x.value);
if (!allApiVersions) return;
let apiVersion = context.apiVersion;
if (
apiVersion === "latest" ||
apiVersion === undefined ||
!allApiVersions.includes(apiVersion)
) {
apiVersion = allApiVersions[allApiVersions.length - 1];
}
const apiVersion = getValidApiVersion(context, allApiVersions);
if (apiVersion === undefined) return;
const versionProjections = buildVersionProjections(context.program, client.service).filter(
(v) => apiVersion === v.version
Expand Down Expand Up @@ -599,14 +599,14 @@ export interface CreateSdkContextOptions {
additionalDecorators?: string[];
}

export function createSdkContext<
export async function createSdkContext<
TOptions extends Record<string, any> = SdkEmitterOptions,
TServiceOperation extends SdkServiceOperation = SdkHttpOperation,
>(
context: EmitContext<TOptions>,
emitterName?: string,
options?: CreateSdkContextOptions
): SdkContext<TOptions, TServiceOperation> {
): Promise<SdkContext<TOptions, TServiceOperation>> {
const diagnostics = createDiagnosticCollector();
const protocolOptions = true; // context.program.getLibraryOptions("generate-protocol-methods");
const convenienceOptions = true; // context.program.getLibraryOptions("generate-convenience-methods");
Expand All @@ -631,10 +631,15 @@ export function createSdkContext<
__namespaceToApiVersionParameter: new Map(),
__tspTypeToApiVersions: new Map(),
__namespaceToApiVersionClientDefaultValue: new Map(),
examplesDirectory: context.options["examples-directory"],
decoratorsAllowList: [...defaultDecoratorsAllowList, ...(options?.additionalDecorators ?? [])],
previewStringRegex: options?.versioning?.previewStringRegex || /-preview$/,
};
sdkContext.sdkPackage = getSdkPackage(sdkContext);
for (const client of sdkContext.sdkPackage.clients) {
diagnostics.pipe(await handleClientExamples(sdkContext, client));
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
}

if (sdkContext.diagnostics) {
sdkContext.diagnostics = sdkContext.diagnostics.concat(
sdkContext.sdkPackage.diagnostics // eslint-disable-line deprecation/deprecation
Expand Down
Loading
Loading