@@ -144,7 +144,10 @@ type StandardOperationStore interface {
144
144
GetRequestBodyMediaType () string
145
145
getRequestBodyMediaType () string
146
146
getRequestBodyMediaTypeNormalised () string
147
+ GetXMLDeclaration () string
147
148
getXMLDeclaration () string
149
+ GetXMLRootAnnotation () string
150
+ GetXMLTransform () string
148
151
// getRequestBodyAttributeLineage(string) (string, error)
149
152
}
150
153
@@ -180,6 +183,10 @@ func (op *standardOpenAPIOperationStore) GetInline() []string {
180
183
return []string {}
181
184
}
182
185
186
+ func (op * standardOpenAPIOperationStore ) GetXMLDeclaration () string {
187
+ return op .getXMLDeclaration ()
188
+ }
189
+
183
190
func (op * standardOpenAPIOperationStore ) getXMLDeclaration () string {
184
191
rv := ""
185
192
if op .Request != nil {
@@ -201,6 +208,10 @@ func (op *standardOpenAPIOperationStore) getServiceNameForProvider() string {
201
208
return ""
202
209
}
203
210
211
+ func (op * standardOpenAPIOperationStore ) GetXMLRootAnnotation () string {
212
+ return op .getXMLRootAnnotation ()
213
+ }
214
+
204
215
func (op * standardOpenAPIOperationStore ) getXMLRootAnnotation () string {
205
216
rv := ""
206
217
if op .Request != nil {
@@ -209,6 +220,10 @@ func (op *standardOpenAPIOperationStore) getXMLRootAnnotation() string {
209
220
return rv
210
221
}
211
222
223
+ func (op * standardOpenAPIOperationStore ) GetXMLTransform () string {
224
+ return op .getXMLTransform ()
225
+ }
226
+
212
227
func (op * standardOpenAPIOperationStore ) getXMLTransform () string {
213
228
rv := ""
214
229
if op .Request != nil {
@@ -1198,15 +1213,15 @@ func (op *standardOpenAPIOperationStore) MarshalBody(body interface{}, expectedR
1198
1213
func (op * standardOpenAPIOperationStore ) marshalBody (body interface {}, expectedRequest ExpectedRequest ) ([]byte , error ) {
1199
1214
mediaType := expectedRequest .GetBodyMediaType ()
1200
1215
if expectedRequest .GetSchema () != nil {
1201
- mediaType = expectedRequest .GetSchema ().extractMediaTypeSynonym (mediaType )
1216
+ mediaType = expectedRequest .GetSchema ().ExtractMediaTypeSynonym (mediaType )
1202
1217
}
1203
1218
switch mediaType {
1204
1219
case media .MediaTypeJson :
1205
1220
return json .Marshal (body )
1206
1221
case media .MediaTypeXML , media .MediaTypeTextXML :
1207
1222
return xmlmap .MarshalXMLUserInput (
1208
1223
body ,
1209
- expectedRequest .GetSchema ().getXMLALiasOrName (),
1224
+ expectedRequest .GetSchema ().GetXMLALiasOrName (),
1210
1225
op .getXMLTransform (),
1211
1226
op .getXMLDeclaration (),
1212
1227
op .getXMLRootAnnotation (),
@@ -1215,139 +1230,6 @@ func (op *standardOpenAPIOperationStore) marshalBody(body interface{}, expectedR
1215
1230
return nil , fmt .Errorf ("media type = '%s' not supported" , expectedRequest .GetBodyMediaType ())
1216
1231
}
1217
1232
1218
- type AnalyzedInput interface {
1219
- GetQueryParams () map [string ]any
1220
- GetHeaderParam (string ) (string , bool )
1221
- GetPathParam (string ) (string , bool )
1222
- GetServerVars () map [string ]any
1223
- GetREquestBody () any
1224
- }
1225
-
1226
- func (op * standardOpenAPIOperationStore ) parameterizeFromAnalyzedInput (prov Provider , parentDoc Service , inputParams AnalyzedInput ) (* openapi3filter.RequestValidationInput , error ) {
1227
-
1228
- params := op .OperationRef .Value .Parameters
1229
- pathParams := make (map [string ]string )
1230
- q := make (url.Values )
1231
- prefilledHeader := make (http.Header )
1232
-
1233
- queryParamsRemaining := inputParams .GetQueryParams ()
1234
- for _ , p := range params {
1235
- if p .Value == nil {
1236
- continue
1237
- }
1238
- name := p .Value .Name
1239
-
1240
- if p .Value .In == openapi3 .ParameterInHeader {
1241
- val , present := inputParams .GetHeaderParam (p .Value .Name )
1242
- if present {
1243
- prefilledHeader .Set (name , fmt .Sprintf ("%v" , val ))
1244
- } else if p .Value != nil && p .Value .Schema != nil && p .Value .Schema .Value != nil && p .Value .Schema .Value .Default != nil {
1245
- prefilledHeader .Set (name , fmt .Sprintf ("%v" , p .Value .Schema .Value .Default ))
1246
- } else if isOpenapi3ParamRequired (p .Value ) {
1247
- return nil , fmt .Errorf ("standardOpenAPIOperationStore.parameterize() failure; missing required header '%s'" , name )
1248
- }
1249
- }
1250
- if p .Value .In == openapi3 .ParameterInPath {
1251
- val , present := inputParams .GetPathParam (p .Value .Name )
1252
- if present {
1253
- pathParams [name ] = fmt .Sprintf ("%v" , val )
1254
- }
1255
- if ! present && isOpenapi3ParamRequired (p .Value ) {
1256
- return nil , fmt .Errorf ("standardOpenAPIOperationStore.parameterize() failure; missing required path parameter '%s'" , name )
1257
- }
1258
- } else if p .Value .In == openapi3 .ParameterInQuery {
1259
-
1260
- pVal , present := queryParamsRemaining [p .Value .Name ]
1261
- if present {
1262
- switch val := pVal .(type ) {
1263
- case []interface {}:
1264
- for _ , v := range val {
1265
- q .Add (name , fmt .Sprintf ("%v" , v ))
1266
- }
1267
- default :
1268
- q .Set (name , fmt .Sprintf ("%v" , val ))
1269
- }
1270
- delete (queryParamsRemaining , name )
1271
- }
1272
- }
1273
- }
1274
- for k , v := range queryParamsRemaining {
1275
- q .Set (k , fmt .Sprintf ("%v" , v ))
1276
- delete (queryParamsRemaining , k )
1277
- }
1278
- openapiSvc , openapiSvcOk := op .OpenAPIService .(OpenAPIService )
1279
- if ! openapiSvcOk {
1280
- return nil , fmt .Errorf ("could not cast OpenAPIService to standardOpenAPIServiceStore" )
1281
- }
1282
- router , err := queryrouter .NewRouter (openapiSvc .getT ())
1283
- if err != nil {
1284
- return nil , err
1285
- }
1286
- servers , _ := op .getServers ()
1287
- serverParams := inputParams .GetServerVars ()
1288
- if err != nil {
1289
- return nil , err
1290
- }
1291
- sv , err := selectServer (servers , serverParams )
1292
- if err != nil {
1293
- return nil , err
1294
- }
1295
- contentTypeHeaderRequired := false
1296
- var bodyReader io.Reader
1297
-
1298
- requestBody := inputParams .GetREquestBody ()
1299
-
1300
- predOne := ! util .IsNil (requestBody )
1301
- predTwo := ! util .IsNil (op .Request )
1302
- if predOne && predTwo {
1303
- b , err := op .marshalBody (requestBody , op .Request )
1304
- if err != nil {
1305
- return nil , err
1306
- }
1307
- bodyReader = bytes .NewReader (b )
1308
- contentTypeHeaderRequired = true
1309
- }
1310
- // TODO: clean up
1311
- sv = strings .TrimSuffix (sv , "/" )
1312
- path := replaceSimpleStringVars (fmt .Sprintf ("%s%s" , sv , op .OperationRef .extractPathItem ()), pathParams )
1313
- u , err := url .Parse (fmt .Sprintf ("%s?%s" , path , q .Encode ()))
1314
- if strings .Contains (path , "?" ) {
1315
- if len (q ) > 0 {
1316
- u , err = url .Parse (fmt .Sprintf ("%s&%s" , path , q .Encode ()))
1317
- } else {
1318
- u , err = url .Parse (path )
1319
- }
1320
- }
1321
- if err != nil {
1322
- return nil , err
1323
- }
1324
- httpReq , err := http .NewRequest (strings .ToUpper (op .OperationRef .extractMethodItem ()), u .String (), bodyReader )
1325
- if err != nil {
1326
- return nil , err
1327
- }
1328
- if contentTypeHeaderRequired {
1329
- if prefilledHeader .Get ("Content-Type" ) != "" {
1330
- prefilledHeader .Set ("Content-Type" , op .Request .BodyMediaType )
1331
- }
1332
- }
1333
- httpReq .Header = prefilledHeader
1334
- route , checkedPathParams , err := router .FindRoute (httpReq )
1335
- if err != nil {
1336
- return nil , err
1337
- }
1338
- options := & openapi3filter.Options {
1339
- AuthenticationFunc : openapi3filter .NoopAuthenticationFunc ,
1340
- }
1341
- // Validate request
1342
- requestValidationInput := & openapi3filter.RequestValidationInput {
1343
- Options : options ,
1344
- PathParams : checkedPathParams ,
1345
- Request : httpReq ,
1346
- Route : route ,
1347
- }
1348
- return requestValidationInput , nil
1349
- }
1350
-
1351
1233
func (op * standardOpenAPIOperationStore ) parameterize (prov Provider , parentDoc Service , inputParams HttpParameters , requestBody interface {}) (* openapi3filter.RequestValidationInput , error ) {
1352
1234
1353
1235
params := op .OperationRef .Value .Parameters
0 commit comments