File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
packages/emitter-express/src Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @typespec-tools/emitter-express " : minor
3
+ ---
4
+
5
+ remove statusCode from response body
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as prettier from "prettier";
2
2
import {
3
3
EmitContext ,
4
4
getNamespaceFullName ,
5
+ Model ,
5
6
ModelProperty ,
6
7
Operation ,
7
8
} from "@typespec/compiler" ;
@@ -12,6 +13,7 @@ import {
12
13
isBodyRoot ,
13
14
isPathParam ,
14
15
isQueryParam ,
16
+ isStatusCode ,
15
17
listHttpOperationsIn ,
16
18
} from "@typespec/http" ;
17
19
import {
@@ -107,6 +109,23 @@ export class ExpressEmitter extends TypescriptEmitter<EmitterOptions> {
107
109
return this . emitter . result . declaration ( name , cb . reduce ( ) ) ;
108
110
}
109
111
112
+ modelProperties ( model : Model ) : EmitterOutput < string > {
113
+ const program = this . emitter . getProgram ( ) ;
114
+ const builder = new StringBuilder ( ) ;
115
+
116
+ for ( const prop of model . properties . values ( ) ) {
117
+ if ( isStatusCode ( program , prop ) ) {
118
+ // Remove status code from model properties
119
+ // This will be added to the response object
120
+ continue ;
121
+ }
122
+ const propVal = this . emitter . emitModelProperty ( prop ) ;
123
+ builder . push ( code `${ propVal } ;` ) ;
124
+ }
125
+
126
+ return this . emitter . result . rawCode ( builder . reduce ( ) ) ;
127
+ }
128
+
110
129
async sourceFile ( sourceFile : SourceFile < string > ) : Promise < EmittedSourceFile > {
111
130
const program = this . emitter . getProgram ( ) ;
112
131
const [ httpServices ] = getAllHttpServices ( program , { } ) ;
You can’t perform that action at this time.
0 commit comments