@@ -79,17 +79,55 @@ describe('.getParametersAsJSONSchema()', () => {
7979 } ) ;
8080
8181 it ( 'should ignore reserved custom header parameters case-insensitively' , async ( ) => {
82+ const oas = createOasForOperation (
83+ {
84+ security : [ { bearerAuth : [ ] } ] ,
85+ parameters : [
86+ { in : 'header' , name : 'Accept' , required : true , schema : { type : 'string' } } ,
87+ { in : 'header' , name : 'accept' , required : true , schema : { type : 'string' } } ,
88+ { in : 'header' , name : 'ACCEPT' , required : true , schema : { type : 'string' } } ,
89+ { in : 'header' , name : 'Content-Type' , required : true , schema : { type : 'string' } } ,
90+ { in : 'header' , name : 'content-type' , required : true , schema : { type : 'string' } } ,
91+ { in : 'header' , name : 'CONTENT-TYPE' , required : true , schema : { type : 'string' } } ,
92+ { in : 'header' , name : 'Authorization' , required : true , schema : { type : 'string' } } ,
93+ { in : 'header' , name : 'authorization' , required : true , schema : { type : 'string' } } ,
94+ { in : 'header' , name : 'AUTHORIZATION' , required : true , schema : { type : 'string' } } ,
95+ { in : 'header' , name : 'X-Request-ID' , required : true , schema : { type : 'string' } } ,
96+ ] ,
97+ } ,
98+ { securitySchemes : { bearerAuth : { type : 'http' , scheme : 'bearer' } } } ,
99+ ) ;
100+
101+ const schemas = oas . operation ( '/' , 'get' ) . getParametersAsJSONSchema ( ) ;
102+
103+ expect ( schemas ) . toStrictEqual ( [
104+ {
105+ label : 'Headers' ,
106+ type : 'header' ,
107+ schema : {
108+ $schema : 'http://json-schema.org/draft-04/schema#' ,
109+ type : 'object' ,
110+ properties : {
111+ 'X-Request-ID' : {
112+ type : 'string' ,
113+ } ,
114+ } ,
115+ required : [ 'X-Request-ID' ] ,
116+ } ,
117+ } ,
118+ ] ) ;
119+ await expect ( schemas ?. map ( s => s . schema ) ) . toBeValidJSONSchemas ( ) ;
120+ } ) ;
121+
122+ it ( 'should render a reserved `Authorization` header param when the operation has no security scheme (CX-3611)' , async ( ) => {
123+ // `Accept` and `Content-Type` are still ignored because ReadMe computes them, but stripping
124+ // `Authorization` here would remove the only way to authenticate, so it should render.
82125 const oas = createOasForOperation ( {
83126 parameters : [
84127 { in : 'header' , name : 'Accept' , required : true , schema : { type : 'string' } } ,
85- { in : 'header' , name : 'accept' , required : true , schema : { type : 'string' } } ,
86- { in : 'header' , name : 'ACCEPT' , required : true , schema : { type : 'string' } } ,
87128 { in : 'header' , name : 'Content-Type' , required : true , schema : { type : 'string' } } ,
88- { in : 'header' , name : 'content-type' , required : true , schema : { type : 'string' } } ,
89- { in : 'header' , name : 'CONTENT-TYPE' , required : true , schema : { type : 'string' } } ,
90129 { in : 'header' , name : 'Authorization' , required : true , schema : { type : 'string' } } ,
91130 { in : 'header' , name : 'authorization' , required : true , schema : { type : 'string' } } ,
92- { in : 'header' , name : 'AUTHORIZATION' , required : true , schema : { type : 'string' } } ,
93131 { in : 'header' , name : 'X-Request-ID' , required : true , schema : { type : 'string' } } ,
94132 ] ,
95133 } ) ;
@@ -104,11 +142,17 @@ describe('.getParametersAsJSONSchema()', () => {
104142 $schema : 'http://json-schema.org/draft-04/schema#' ,
105143 type : 'object' ,
106144 properties : {
145+ Authorization : {
146+ type : 'string' ,
147+ } ,
148+ authorization : {
149+ type : 'string' ,
150+ } ,
107151 'X-Request-ID' : {
108152 type : 'string' ,
109153 } ,
110154 } ,
111- required : [ 'X-Request-ID' ] ,
155+ required : [ 'Authorization' , 'authorization' , ' X-Request-ID'] ,
112156 } ,
113157 } ,
114158 ] ) ;
0 commit comments