@@ -106,7 +106,9 @@ type PromiseInputField =
106106 | ( InputField & { readonly optional : boolean } )
107107 | { readonly name : string ; readonly source : "wildcard" ; readonly optional : false }
108108
109- const resolveHttpApiStatus = SchemaAST . resolveAt < number > ( "httpApiStatus" )
109+ const resolveHttpApiStatus = ( ast : SchemaAST . AST ) =>
110+ SchemaAST . resolveAt < number > ( "httpApiStatus" ) ( ast ) ??
111+ ( ast . checks === undefined ? ast . context ?. annotations ?. httpApiStatus : undefined )
110112const resolveHttpApiEncoding = SchemaAST . resolveAt < HttpApiSchema . Encoding > ( "~httpApiEncoding" )
111113const Manifest = Schema . fromJsonString ( Schema . Array ( Schema . String ) )
112114const manifestName = ".httpapi-codegen.json"
@@ -1784,7 +1786,10 @@ function sameChecks(left: SchemaAST.Checks | undefined, right: SchemaAST.Checks
17841786}
17851787
17861788function sameContext ( left : SchemaAST . Context | undefined , right : SchemaAST . Context | undefined ) {
1787- return left ?. isOptional === right ?. isOptional && left ?. isMutable === right ?. isMutable
1789+ return (
1790+ ( left ?. isOptional ?? false ) === ( right ?. isOptional ?? false ) &&
1791+ ( left ?. isMutable ?? false ) === ( right ?. isMutable ?? false )
1792+ )
17881793}
17891794
17901795export function write (
@@ -2068,7 +2073,9 @@ function isDataEnvelope(schema: Schema.Top) {
20682073 )
20692074}
20702075
2071- function isStreamSchema ( schema : Schema . Top ) : schema is HttpApiSchema . StreamSchema {
2076+ function isStreamSchema (
2077+ schema : Schema . Top ,
2078+ ) : schema is Exclude < HttpApiSchema . StreamSchema , HttpApiSchema . StreamNdjson < Schema . Top > > {
20722079 return "_tag" in schema && ( schema . _tag === "StreamSse" || schema . _tag === "StreamUint8Array" )
20732080}
20742081
@@ -2171,7 +2178,7 @@ function renderGroup(group: Group) {
21712178 const inputDeclaration =
21722179 operation . operation . inputMode === "none"
21732180 ? ""
2174- : `${ opaquePayload ? `type ${ prefix } Request = Parameters<RawGroup[${ JSON . stringify ( endpoint . identifier ) } ]>[0]\n` : "" } type ${ prefix } Input = { ${ inputType } }\n`
2181+ : `${ opaquePayload ? `type ${ prefix } Request = Parameters<RawGroup[${ JSON . stringify ( endpoint . identifier ) } ]>[0] & { readonly responseMode?: "decoded-only" } \n` : "" } type ${ prefix } Input = { ${ inputType } }\n`
21752182 adapters . push (
21762183 `${ inputDeclaration } const ${ prefix } DeclaredError = ${ declaredSchema } \nconst map${ prefix } Error = (error: unknown) => HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error) ? new ClientError({ cause: error }) : Schema.is(${ prefix } DeclaredError)(error) ? error : new ClientError({ cause: error })\nconst ${ prefix } = (raw: RawGroup) => (${ argument } ) => ${ operation . operation . success === "stream" ? `Stream.unwrap(${ rawCall } .pipe(Effect.mapError(map${ prefix } Error), Effect.map((stream) => stream.pipe(Stream.mapError(map${ prefix } Error)))))` : mapped } ` ,
21772184 )
@@ -2252,7 +2259,9 @@ function renderSchemas(slots: ReadonlyArray<Slot>) {
22522259 ]
22532260 const document = SchemaRepresentation . toCodeDocument (
22542261 SchemaRepresentation . toRepresentations (
2255- codegenAsts ( expanded . map ( ( slot ) => slot . schema . ast ) ) as [ SchemaAST . AST , ...Array < SchemaAST . AST > ] ,
2262+ codegenAsts (
2263+ expanded . map ( ( slot ) => slot . schema . annotate ( { httpApiStatus : resolveHttpApiStatus ( slot . schema . ast ) } ) . ast ) ,
2264+ ) as [ SchemaAST . AST , ...Array < SchemaAST . AST > ] ,
22562265 ) ,
22572266 )
22582267 const artifacts = document . artifacts . flatMap ( ( artifact ) => {
0 commit comments