@@ -7,6 +7,7 @@ import type { Response } from './response.js';
77import type { SecurityRequirement } from './security-requirement.js' ;
88import type { Tag } from './tag.js' ;
99import type { ExtractRouteParams } from './types.js' ;
10+ import { stripUndefined } from './utils.js' ;
1011
1112export interface OperationOptions < TPath extends string = '/' > {
1213 operationId : string ;
@@ -20,13 +21,16 @@ export interface OperationOptions<TPath extends string = '/'> {
2021 [ statusCode : string | number ] : Response ;
2122 } ;
2223 requestBody ?: RequestBody | RequestBodyOptions ;
24+ order ?: number ;
2325}
2426
2527export class Operation < TPath extends string = '/' > extends Construct {
2628 private readonly options : OperationOptions < TPath > ;
2729
2830 public readonly method : HttpMethods ;
2931
32+ public readonly order : number ;
33+
3034 private requestBody ?: RequestBody ;
3135
3236 public hasOperationId ( operationId : OperationOptions [ 'operationId' ] ) : boolean {
@@ -42,6 +46,8 @@ export class Operation<TPath extends string = '/'> extends Construct {
4246 this . method = method ;
4347 this . options = options ;
4448
49+ this . order = options . order || 0 ;
50+
4551 if ( options . requestBody ) {
4652 this . requestBody =
4753 options . requestBody instanceof RequestBody
@@ -68,10 +74,13 @@ export class Operation<TPath extends string = '/'> extends Construct {
6874 }
6975
7076 public synth ( ) {
71- return {
72- ...( this . options . operationId && {
73- operationId : this . options . operationId ,
74- } ) ,
77+ return stripUndefined ( {
78+ operationId : this . options . operationId ,
79+ description : this . options . description || undefined ,
80+ summary : this . options . summary || undefined ,
81+ tags :
82+ this . options . tags && [ ...this . options . tags ] . map ( ( child ) => child . name ) ,
83+ deprecated : this . options . deprecated ,
7584 ...( this . options . parameters && {
7685 parameters : this . options . parameters . map ( ( child ) => child . synth ( ) ) ,
7786 } ) ,
@@ -92,6 +101,6 @@ export class Operation<TPath extends string = '/'> extends Construct {
92101 ] ) ,
93102 ) ,
94103 } ) ,
95- } satisfies oas31 . OperationObject ;
104+ } ) satisfies oas31 . OperationObject ;
96105 }
97106}
0 commit comments