@@ -49,7 +49,7 @@ import {
4949import { SdkContext , isReadOnly } from "@azure-tools/typespec-client-generator-core" ;
5050
5151import { 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" ;
5353import {
5454 getHeaderFieldName ,
5555 getPathParamName ,
@@ -967,15 +967,22 @@ function getSchemaForModel(
967967// OA schema is just a regular object schema.
968968function 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