@@ -6,11 +6,11 @@ import { AAZEmitterContext, AAZOperationEmitterContext, AAZSchemaEmitterContext
66import { resolveOperationId } from "./utils.js" ;
77import { TypeSpecPathItem } from "./model/path_item.js" ;
88import { CMDHttpOperation } from "./model/operation.js" ;
9- import { DiagnosticTarget , Enum , EnumMember , Model , ModelProperty , Namespace , Program , Scalar , TwoLevelMap , Type , Union , Value , getDiscriminator , getDoc , getEncode , getFormat , getMaxItems , getMaxLength , getMaxValue , getMaxValueExclusive , getMinItems , getMinLength , getMinValue , getMinValueExclusive , getPattern , getProjectedName , getProperty , isArrayModelType , isNeverType , isNullType , isRecordModelType , isService , isTemplateDeclaration , isVoidType , resolveEncodedName , IntrinsicType } from "@typespec/compiler" ;
9+ import { DiagnosticTarget , Enum , EnumMember , Model , ModelProperty , Namespace , Program , Scalar , TwoLevelMap , Type , Union , Value , getDiscriminator , getDoc , getEncode , getFormat , getMaxItems , getMaxLength , getMaxValue , getMaxValueExclusive , getMinItems , getMinLength , getMinValue , getMinValueExclusive , getPattern , getProjectedName , getProperty , isArrayModelType , isNeverType , isNullType , isRecordModelType , isService , isTemplateDeclaration , isVoidType , resolveEncodedName , IntrinsicType , serializeValueAsJson } from "@typespec/compiler" ;
1010import { LroMetadata , PagedResultMetadata , UnionEnum , getArmResourceIdentifierConfig , getLroMetadata , getPagedResult , getUnionAsEnum } from "@azure-tools/typespec-azure-core" ;
1111import { XmsPageable } from "./model/x_ms_pageable.js" ;
1212import { CMDHttpRequest , CMDHttpResponse } from "./model/http.js" ;
13- import { CMDArraySchemaBase , CMDClsSchema , CMDClsSchemaBase , CMDObjectSchema , CMDObjectSchemaBase , CMDSchema , CMDSchemaBase , CMDStringSchema , CMDStringSchemaBase , CMDIntegerSchemaBase , Ref , ClsType , ArrayType , CMDObjectSchemaDiscriminator , CMDByteSchemaBase , CMDInteger32SchemaBase , CMDInteger64SchemaBase , CMDFloatSchemaBase , CMDFloat64SchemaBase , CMDFloat32SchemaBase , CMDUuidSchemaBase , CMDPasswordSchemaBase , CMDResourceIdSchemaBase , CMDDateSchemaBase , CMDDateTimeSchemaBase , CMDDurationSchemaBase , CMDResourceLocationSchema , CMDIdentityObjectSchemaBase , CMDBooleanSchemaBase , CMDAnyTypeSchemaBase } from "./model/schema.js" ;
13+ import { CMDArraySchemaBase , CMDClsSchema , CMDClsSchemaBase , CMDObjectSchema , CMDObjectSchemaBase , CMDSchema , CMDSchemaBase , CMDStringSchema , CMDStringSchemaBase , CMDIntegerSchemaBase , Ref , ClsType , ArrayType , CMDObjectSchemaDiscriminator , CMDByteSchemaBase , CMDInteger32SchemaBase , CMDInteger64SchemaBase , CMDFloatSchemaBase , CMDFloat64SchemaBase , CMDFloat32SchemaBase , CMDUuidSchemaBase , CMDPasswordSchemaBase , CMDResourceIdSchemaBase , CMDDateSchemaBase , CMDDateTimeSchemaBase , CMDDurationSchemaBase , CMDResourceLocationSchema , CMDIdentityObjectSchemaBase , CMDBooleanSchemaBase , CMDAnyTypeSchemaBase , CMDBinarySchema } from "./model/schema.js" ;
1414import { reportDiagnostic } from "./lib.js" ;
1515import {
1616 getExtensions ,
@@ -267,9 +267,6 @@ function extractHttpRequest(context: AAZOperationEmitterContext, operation: Http
267267 if ( body . bodyKind === "multipart" ) {
268268 throw new Error ( "NotImplementedError: Multipart form data payloads are not supported." ) ;
269269 }
270- if ( isBinaryPayload ( body . type , consumes ) ) {
271- throw new Error ( "NotImplementedError: Binary payloads are not supported." ) ;
272- }
273270 if ( consumes . includes ( "multipart/form-data" ) ) {
274271 throw new Error ( "NotImplementedError: Multipart form data payloads are not supported." ) ;
275272 }
@@ -303,6 +300,12 @@ function extractHttpRequest(context: AAZOperationEmitterContext, operation: Http
303300 clientFlatten : true ,
304301 } as CMDObjectSchema ;
305302 }
303+ if ( isBinaryPayload ( body . type , consumes ) ) {
304+ schema = {
305+ ...schema ,
306+ type : "binary"
307+ } as CMDBinarySchema
308+ }
306309 request . body = {
307310 json : {
308311 schema
@@ -554,7 +557,7 @@ function convert2CMDSchema(context: AAZSchemaEmitterContext, param: ModelPropert
554557
555558 if ( param . defaultValue ) {
556559 schema . default = {
557- value : getDefaultValue ( context , param . defaultValue ) ,
560+ value : getDefaultValue ( context , param . defaultValue , param ) ,
558561 }
559562 }
560563 }
@@ -563,6 +566,10 @@ function convert2CMDSchema(context: AAZSchemaEmitterContext, param: ModelPropert
563566 ...schema ,
564567 ...applySchemaFormat ( context , param , schema as CMDSchemaBase )
565568 }
569+ schema = {
570+ ...schema ,
571+ ...applyEncoding ( context , param , schema )
572+ }
566573 schema = {
567574 ...schema ,
568575 ...applyExtensionsDecorators ( context , param , schema )
@@ -614,6 +621,7 @@ function convert2CMDSchemaBase(context: AAZSchemaEmitterContext, type: Type): CM
614621 }
615622 if ( schema ) {
616623 schema = applySchemaFormat ( context , type , schema ) ;
624+ schema = applyEncoding ( context , type , schema ) ;
617625 schema = applyExtensionsDecorators ( context , type , schema ) ;
618626 }
619627
@@ -1686,6 +1694,24 @@ function emitArrayFormat(context: AAZSchemaEmitterContext, type: Model, targetFo
16861694
16871695// TODO: add emitResourceIdFormat
16881696
1697+ function applyEncoding (
1698+ context : AAZSchemaEmitterContext ,
1699+ type :Type ,
1700+ schema : CMDSchemaBase
1701+ ) : CMDSchemaBase {
1702+ if ( type . kind !== "Scalar" && type . kind !== "ModelProperty" ) {
1703+ return schema ;
1704+ }
1705+ const encodeData = getEncode ( context . program , type ) ;
1706+ if ( encodeData !== undefined ) {
1707+ schema = {
1708+ ...schema ,
1709+ ...convertScalar2CMDSchemaBase ( context , encodeData . type )
1710+ } ;
1711+ }
1712+ return schema ;
1713+ }
1714+
16891715// apply extension decorators
16901716function applyExtensionsDecorators (
16911717 context : AAZSchemaEmitterContext ,
@@ -1923,25 +1949,10 @@ function getClsDefinitionModel(schema: CMDClsSchemaBase): CMDObjectSchemaBase |
19231949 return schema . type . pendingSchema . schema !
19241950}
19251951
1926- function getDefaultValue ( content : AAZSchemaEmitterContext , defaultType : Value ) : unknown {
1927- switch ( defaultType . valueKind ) {
1928- case "StringValue" :
1929- return defaultType . value ;
1930- case "NumericValue" :
1931- return defaultType . value . asNumber ( ) ?? undefined ;
1932- case "BooleanValue" :
1933- return defaultType . value ;
1934- case "ArrayValue" :
1935- return defaultType . values . map ( ( x ) => getDefaultValue ( content , x ) ) ;
1936- case "NullValue" :
1937- return null ;
1938- case "EnumValue" :
1939- return defaultType . value . value ?? defaultType . value . name ;
1940- default :
1941- reportDiagnostic ( content . program , {
1942- code : "invalid-default" ,
1943- format : { type : defaultType . valueKind } ,
1944- target : defaultType ,
1945- } ) ;
1946- }
1952+ function getDefaultValue (
1953+ context : AAZSchemaEmitterContext ,
1954+ defaultType : Value ,
1955+ modelProperty : ModelProperty ,
1956+ ) : any {
1957+ return serializeValueAsJson ( context . program , defaultType , modelProperty ) ;
19471958}
0 commit comments