Skip to content

Commit 3904ad3

Browse files
authored
Tsp - Add support for constant value (#1413)
1 parent ff7132a commit 3904ad3

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

packages/typespec-powershell/src/utils/modelUtils.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
import { SdkContext, isReadOnly } from "@azure-tools/typespec-client-generator-core";
5050

5151
import { reportDiagnostic } from "../lib.js";
52-
import { AnySchema, SealedChoiceSchema, ChoiceSchema, ChoiceValue, SchemaType, ArraySchema, Schema, DictionarySchema, ObjectSchema, Discriminator as M4Discriminator, Property, StringSchema, NumberSchema, ConstantSchema, ConstantValue } from "@autorest/codemodel";
52+
import { AnySchema, SealedChoiceSchema, ChoiceSchema, ChoiceValue, SchemaType, ArraySchema, Schema, DictionarySchema, ObjectSchema, Discriminator as M4Discriminator, Property, StringSchema, NumberSchema, ConstantSchema, ConstantValue, BooleanSchema } from "@autorest/codemodel";
5353
import {
5454
getHeaderFieldName,
5555
getPathParamName,
@@ -967,15 +967,22 @@ function getSchemaForModel(
967967
// OA schema is just a regular object schema.
968968
function getSchemaForLiteral(type: Type): any {
969969
// ToDo: by xiaogang, need to implement other kinds as String
970-
switch (type.kind) {
971-
case "Number":
972-
return { type: `${type.value}`, isConstant: true };
973-
case "String": {
974-
const schema = new StringSchema(type.value, "");
975-
return schema;
970+
if (type.kind) {
971+
const schema = new ConstantSchema("", "");
972+
switch (type.kind) {
973+
case "Number":
974+
schema.valueType = new NumberSchema("Constant", "Constant number", SchemaType.Number, 64);
975+
schema.value = new ConstantValue(type.value);
976+
return schema;
977+
case "String":
978+
schema.valueType = new StringSchema("Constant", "Constant string");
979+
schema.value = new ConstantValue(type.value);
980+
return schema;
981+
case "Boolean":
982+
schema.valueType = new BooleanSchema("Constant", "Constant boolean");
983+
schema.value = new ConstantValue(type.value);
984+
return schema;
976985
}
977-
case "Boolean":
978-
return { type: `${type.value}`, isConstant: true };
979986
}
980987
if (type.kind === undefined) {
981988
if (typeof type === "string") {

0 commit comments

Comments
 (0)