Skip to content

Commit

Permalink
tsp - Remove redundant any types (Azure#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolauli authored Jan 22, 2025
1 parent caa1fec commit 2455af7
Show file tree
Hide file tree
Showing 27 changed files with 37 additions and 1,759 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
customCommand: 'install -g @microsoft/rush@5.63.1'
- pwsh: |
# Write your PowerShell commands here.
Install-Module -Name Az.Accounts -Force -Repository PSGallery
Install-Module -Name Az.Accounts -AllowClobber -Force -Repository PSGallery
displayName: 'Install latest Az.Accounts'
- script: |
rush sync-versions
Expand Down
14 changes: 12 additions & 2 deletions packages/typespec-powershell/src/utils/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const BINARY_TYPE_UNION =
"string | Uint8Array | ReadableStream<Uint8Array> | NodeJS.ReadableStream";

export const BINARY_AND_FILE_TYPE_UNION = `${BINARY_TYPE_UNION} | File`;
export const ANY_SCHEMA = 'any_schema';

export enum SchemaContext {
/** Schema is used as an input to an operation. */
Expand Down Expand Up @@ -173,7 +174,7 @@ function isBytesType(schema: any) {
export let stringSchemaForEnum: StringSchema | undefined;
export let numberSchemaForEnum: NumberSchema | undefined;
export let constantSchemaForApiVersion: ConstantSchema | undefined;
export const schemaCache = new Map<Type, Schema>();
export const schemaCache = new Map<Type|string, Schema>();
// Add this to the modelSet to avoid circular reference
export const modelSet = new Set<Type>();
// For the models that are delayed to be set, currently the only case is the model that is derived from the model with discriminator
Expand Down Expand Up @@ -242,7 +243,13 @@ export function getSchemaForType(
// schema.outputTypeName =
// schema.type === "object" ? "Record<string, any>" : "any";
// }
// by xiaogang, we only need on any schema for empty anonymous model
if (schemaCache.has(ANY_SCHEMA)) {
return schemaCache.get(ANY_SCHEMA);
}
schema.type = SchemaType.Any;
schemaCache.set(ANY_SCHEMA, schema);
return schema;
} else {
// Handle non-empty anonymous model as inline model
if (usage && usage.includes(SchemaContext.Output)) {
Expand Down Expand Up @@ -291,8 +298,11 @@ export function getSchemaForType(
}
if (isUnknownType(type)) {
// Unknown type, return any schema
if (schemaCache.has(ANY_SCHEMA)) {
return schemaCache.get(ANY_SCHEMA);
}
const returnType = new AnySchema("any");
schemaCache.set(type, returnType);
schemaCache.set(ANY_SCHEMA, returnType);
return returnType;
}
if (isNeverType(type)) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2455af7

Please sign in to comment.