Skip to content

Commit

Permalink
Refine model filtering logic (#1498)
Browse files Browse the repository at this point in the history
* refine model filtering logic

* changelog

* regenerate with changes

also updated spector dependencies to avoid mismatched tsp

* refine model filtering logic

---------

Co-authored-by: Joel Hendrix <jhendrix@microsoft.com>
  • Loading branch information
tadelesh and jhendrixMSFT authored Feb 21, 2025
1 parent 10cb38b commit af5a817
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 51 deletions.
158 changes: 135 additions & 23 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: 6 additions & 0 deletions packages/typespec-go/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 0.3.8 (UNRELEASED)

### Bugs Fixed

* Remove filtering Azure core model since some instances of template model is in `Azure.Core` namespace. Logic of filtering exception model could cover the filtering needs.

## 0.3.7 (2025-02-11)

### Bugs Fixed
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-go/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"readme": "https://github.com/Azure/autorest.go/blob/main/readme.md",
"devDependencies": {
"@typespec/spector": "~0.1.0-alpha.6",
"@typespec/http-specs": "~0.1.0-alpha.7",
"@azure-tools/azure-http-specs": "~0.1.0-alpha.5",
"@typespec/http-specs": "~0.1.0-alpha.9",
"@azure-tools/azure-http-specs": "~0.1.0-alpha.6",
"@azure-tools/typespec-autorest": ">=0.51.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.51.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.51.0 <1.0.0",
Expand Down
35 changes: 9 additions & 26 deletions packages/typespec-go/src/tcgcadapter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as naming from '../../../naming.go/src/naming.js';
import * as go from '../../../codemodel.go/src/index.js';
import { uncapitalize } from '@azure-tools/codegen';
import { values } from '@azure-tools/linq';
import * as tcgc from '@azure-tools/typespec-client-generator-core';
import * as tsp from '@typespec/compiler';
import * as http from '@typespec/http';
import { values } from '@azure-tools/linq';
import { uncapitalize } from '@azure-tools/codegen';
import * as go from '../../../codemodel.go/src/index.js';
import * as naming from '../../../naming.go/src/naming.js';

// used to convert SDK types to Go code model types
export class typeAdapter {
Expand All @@ -32,8 +32,8 @@ export class typeAdapter {
if (enumType.usage === tcgc.UsageFlags.ApiVersionEnum) {
// we have a pipeline policy for controlling the api-version
continue;
} else if (this.skipSpecificTypes(enumType)) {
// skip specific types
} else if ((enumType.usage & tcgc.UsageFlags.Input) === 0 && (enumType.usage & tcgc.UsageFlags.Output) === 0) {
// skip types without input and output usage
continue;
}
const constType = this.getConstantType(enumType);
Expand All @@ -45,14 +45,14 @@ export class typeAdapter {
const ifaceTypes = new Array<InterfaceTypeSdkModelType>();
for (const modelType of sdkContext.sdkPackage.models) {
if (modelType.name.length === 0) {
// tcgc creates some unamed models for spread params.
// tcgc creates some unnamed models for spread params.
// we don't use these so just skip them.
continue;
} else if (modelType.access === 'internal' && (modelType.usage & tcgc.UsageFlags.Spread) === tcgc.UsageFlags.Spread) {
// we don't use the internal models for spread params
continue;
} else if (this.skipSpecificTypes(modelType)) {
// skip specific types
} else if ((modelType.usage & tcgc.UsageFlags.Input) === 0 && (modelType.usage & tcgc.UsageFlags.Output) === 0) {
// skip types without input and output usage
continue;
}

Expand Down Expand Up @@ -111,23 +111,6 @@ export class typeAdapter {
}
}

private skipSpecificTypes(type: tcgc.SdkModelType | tcgc.SdkEnumType): boolean {
if (tcgc.isAzureCoreModel(type)) {
// skip core types
return true;
} else if ((type.usage & tcgc.UsageFlags.Exception) === tcgc.UsageFlags.Exception && (type.usage & tcgc.UsageFlags.Input) === 0 && (type.usage & tcgc.UsageFlags.Output) === 0) {
// skip error type
return true;
} else if ((type.usage & tcgc.UsageFlags.LroPolling) === tcgc.UsageFlags.LroPolling && (type.usage & tcgc.UsageFlags.Input) === 0 && (type.usage & tcgc.UsageFlags.Output) === 0) {
// skip lro polling type
return true;
} else if ((type.usage & tcgc.UsageFlags.LroInitial) === tcgc.UsageFlags.LroInitial && (type.usage & tcgc.UsageFlags.Input) === 0 && (type.usage & tcgc.UsageFlags.Output) === 0) {
// skip lro initial response type
return true;
}
return false;
}

// returns the synthesized paged response types
private getPagedResponses(sdkContext: tcgc.SdkContext): Array<tcgc.SdkModelType> {
const pagedResponses = new Array<tcgc.SdkModelType>();
Expand Down

0 comments on commit af5a817

Please sign in to comment.