Skip to content

Commit

Permalink
Fixed anonymous type issue and upgrade autorest/powershell dependency (
Browse files Browse the repository at this point in the history
  • Loading branch information
dolauli authored Jul 12, 2024
1 parent f2a6673 commit f9c4db3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
12 changes: 6 additions & 6 deletions common/config/rush/pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion packages/typespec-powershell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"dependencies": {
"@autorest/powershell": "~4.0.700",
"@autorest/powershell": "~4.0.702",
"@autorest/codemodel": "~4.19.3",
"@autorest/extension-base": "~3.5.2",
"@azure-tools/async-io": "~3.0.0",
Expand Down
26 changes: 12 additions & 14 deletions packages/typespec-powershell/src/utils/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,20 @@ export function getSchemaForType(
typeInput: Type,
options?: GetSchemaOptions
) {
if (schemaCache.has(typeInput)) {
return schemaCache.get(typeInput);
}
const program = dpgContext.program;
const { usage } = options ?? {};
//ToDo: by xiaogang, need to confirm whether need to add this
// const type = getEffectiveModelFromType(program, typeInput);
const type = typeInput;
const type = getEffectiveModelFromType(program, typeInput);
if (schemaCache.has(type)) {
return schemaCache.get(type);
}
const builtinType = getSchemaForLiteral(type);
if (builtinType !== undefined) {
// add in description elements for types derived from primitive types (SecureString, etc.)
const doc = getDoc(program, type);
if (doc) {
builtinType.description = doc;
}
schemaCache.set(typeInput, builtinType);
schemaCache.set(type, builtinType);
return builtinType;
}

Expand All @@ -218,7 +216,7 @@ export function getSchemaForType(
addValidation(<Schema>propertySchema, type);
propertySchema.language.default.name = type.name;
propertySchema.language.default.description = getDoc(program, type) || "";
schemaCache.set(typeInput, <Schema>propertySchema);
schemaCache.set(type, <Schema>propertySchema);
return propertySchema;
} else {
return typeSchema;
Expand Down Expand Up @@ -265,25 +263,25 @@ export function getSchemaForType(
schema.typeName = `${schema.name}`;
}
schema.usage = usage;
schemaCache.set(typeInput, schema);
schemaCache.set(type, schema);
return schema;
} else if (type.kind === "Union") {
const schema = getSchemaForUnion(dpgContext, type, options);
if (schema) {
schemaCache.set(typeInput, schema);
schemaCache.set(type, schema);
}
return schema;
} else if (type.kind === "UnionVariant") {
const schema = getSchemaForUnionVariant(dpgContext, type, options);
schemaCache.set(typeInput, schema);
schemaCache.set(type, schema);
return schema;
} else if (type.kind === "Enum") {
const schema = getSchemaForEnum(dpgContext, type);
schemaCache.set(typeInput, schema);
schemaCache.set(type, schema);
return schema;
} else if (type.kind === "Scalar") {
const schema = getSchemaForScalar(dpgContext, type, options);
schemaCache.set(typeInput, schema);
schemaCache.set(type, schema);
return schema;
} else if (type.kind === "EnumMember") {
//ToDo: by xiaogang, need to confirm
Expand Down Expand Up @@ -321,7 +319,7 @@ export function getSchemaForType(
return undefined;
}
export function getEffectiveModelFromType(program: Program, type: Type): Type {
if (type.kind === "Model") {
if (type.kind === "Model" && type.name === "") {
const effective = getEffectiveModelType(program, type, isSchemaProperty);
if (effective.name) {
return effective;
Expand Down

0 comments on commit f9c4db3

Please sign in to comment.