Skip to content

Commit

Permalink
Binder models tcgc (#2759)
Browse files Browse the repository at this point in the history
* Generate models from TCGC and use binder

* generic serializers

* fix const and enum value expression

* fix paged result model name

* Update packages/typespec-ts/src/modular/emit-models.ts

* remove old imports and refactor serializer util

* fix serializer

* fix anomalydetector

* fix readonly, enum docs missing, serializeRecord crash issues

* Update packages/typespec-ts/src/index.ts

* fix extensible enum docs, knownvalue enum

* fix known enum name

* use binder to resolve dependencies and reserve work

* Fix missing TokenCredential imports

* Fix client not found issue

* fix client factory signature

* fix anonymous models and visitSdkPackage type

* fix missing models and client parameters

* add deserializer

* add serializer for enum and union

* do not export deserializer

* use operation template

* use sdkmethod to filter method level lifted parameters

* fix endpoint template arguments fetching logic

* fix duplicate imports

* fix record serializer missing

* fix unused imports

* update serializer and reserve work

* fix body optional

* use tcgc name

* fix model namespace name

* smoke-test

* fix extra quotes

* fix serializer and deserializer missing

* normalize clientOptional params

* add array serializer

* add array serializer

* refactor operation helpers

* fix serialize value

* fix smoke test

* use binder for streamable and generate empty object as record of any

* fix docs missing

* modular models for multi clients

* use modular client name as context name

* move options into api folder

* fix docs missing

* fix unit test

* fix some unit test and deserializer missing

* refactor serializer in operationHelpers

* fix some ut and add alias description

* fix some ut description

* fix duplicate union type generation

* resolve conflicts and rerun smoke-test

* resolve emit unit test

* fix some issues

* skip tests because of clientDefaultValue

* add todo

* fix client parameters and remove enum serializer and deserializer

* resolve ut

* additional properties support and parameterized host issues

* add notes for todo

* fix smoke test

* filter models with usage

* fix test

* resolve cadl-ranch generation

* fix cadl ranch

* fix addcredential filter

* regen smoke test

* fix additional properties and record ser/deserializer

* filter api version if it is not global

* fix deserializer undefined prefix

* fix binary payload and array ser/deser

* fix array and discriminated union ser/deser

* fix smoke test

* fix cadl ranch regen

* fix smoke test

* improve ser/deser

* fix ci

* add unit test

* add extensible enum case

* add additional properties ser/deser unit test

* fix extensible enum inline generation

* fix ci

* fix duplicate expression

* format change

* fix unit test

* fix unused identifiers

* fix format and ci

* remove api layer at top level index

* resolve some comments

* resolve comments

* fix client parameter normalize

* fix discriminated union and polymorphic base

* fix discriminated base in model properties

* Update packages/typespec-ts/src/modular/emitSamples.ts

Co-authored-by: Daniel Getu <dgetu00@gmail.com>

* reserve work

* filter out lro models

* filter out context

* fix union docs missing

* fix ci

* fix format

* reserve work

* stop exporting anonymous model and generate anonymous body inline

* anonymous model condition change and clear export with no named exports

* unit test missing await

* fix more uts missing await in assertEqualContent

* normalize property name and add ignorePropertyNameNormalize option

* remove unnecessary as any

* Update packages/typespec-test/eng/smoke-test.js

Co-authored-by: Daniel Getu <dgetu00@gmail.com>

---------

Co-authored-by: qiaozha <qiaozha@microsoft.com>
Co-authored-by: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com>
Co-authored-by: Daniel Getu <dgetu00@gmail.com>
  • Loading branch information
4 people authored Oct 18, 2024
1 parent 9d7bada commit 30b5928
Show file tree
Hide file tree
Showing 361 changed files with 20,555 additions and 33,446 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
}
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
},
"[javascript]": {
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
}
}
4 changes: 2 additions & 2 deletions common/config/rush/pnpm-lock.yaml

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

6 changes: 1 addition & 5 deletions packages/rlc-common/src/helpers/nameConstructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,10 @@ export function getImportModuleName(name: ModuleName, codeModel: RLCModel) {

export function getClientName(model: RLCModel) {
const clientName = model.libraryName;
let clientInterfaceName = clientName.endsWith("Client")
const clientInterfaceName = clientName.endsWith("Client")
? `${clientName}`
: `${clientName}Client`;

if (model.options?.isModularLibrary) {
clientInterfaceName = `${clientName.replace("Client", "")}Context`;
}

return clientInterfaceName;
}

Expand Down
1 change: 1 addition & 0 deletions packages/rlc-common/src/helpers/nameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const ReservedModelNames: ReservedName[] = [
{ name: "with", reservedFor: [NameType.Parameter] },
{ name: "yield", reservedFor: [NameType.Parameter] },
{ name: "arguments", reservedFor: [NameType.Parameter] },
{ name: "global", reservedFor: [...Newable] },
// reserve client for codegen
{ name: "client", reservedFor: [NameType.Parameter] },
{ name: "endpoint", reservedFor: [NameType.Parameter] },
Expand Down
1 change: 1 addition & 0 deletions packages/rlc-common/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export interface RLCOptions {
compatibilityMode?: boolean;
experimentalExtensibleEnums?: boolean;
clearOutputFolder?: boolean;
ignorePropertyNameNormalize?: boolean;
}

export interface ServiceInfo {
Expand Down
8 changes: 1 addition & 7 deletions packages/rlc-common/src/metadata/buildReadmeFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RLCModel } from "../interfaces.js";
import hbs from "handlebars";
import { NameType, normalizeName } from "../helpers/nameUtils.js";
import { isAzurePackage } from "../helpers/packageUtil.js";
import { getClientName } from "../helpers/nameConstructors.js";

const azureReadmeRLCTemplate = `# {{ clientDescriptiveName }} library for JavaScript
Expand Down Expand Up @@ -430,10 +431,3 @@ function getServiceName(model: RLCModel) {
: `Azure ${simpleServiceName}`
: simpleServiceName;
}

function getClientName(model: RLCModel) {
const clientName = model.libraryName;
return clientName.endsWith("Client")
? `${clientName}`
: `${clientName}Client`;
}
12 changes: 10 additions & 2 deletions packages/typespec-test/eng/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,16 @@ async function generate(path, logger) {

// Clean up the folder before generation
if (await exists(join(path, "generated", "typespec-ts"))) {
const pathToRemove = join(path, "generated", "typespec-ts");
await rm(pathToRemove, { recursive: true, force: true });
const outputRoot = join(path, "generated", "typespec-ts");
await readdir(outputRoot)
.then((files) =>
Promise.all(files
.filter((file) => file !== "node_modules")
.map((file) =>
rm(join(outputRoot, file), { recursive: true, force: true })
)
)
);
}
} catch (e) {
// do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,6 @@ export interface UserAssignedIdentity {
readonly principalId?: string;
}

// @public
export type Versions = "2023-11-15";

// @public
export interface VirtualNetworkRule {
action?: string;
Expand Down
Loading

0 comments on commit 30b5928

Please sign in to comment.