HTTP 415 error trying to register a json file when registering using the Swagger UI
search cancel

HTTP 415 error trying to register a json file when registering using the Swagger UI

book

Article ID: 134699

calendar_today

Updated On:

Products

CA Test Data Manager (Data Finder / Grid Tools)

Issue/Introduction

I get an HTTP 415 error trying to register a JSON file when registering using the Swagger UI. 


https://localhost:8443/TDMModelService/swagger-ui.html#!/object45controller/createObjectUsingPOST


Environment

Test Data Manager
TDM
API 

Cause

Unfortunately, there is a known limitation for Swagger UI related to this issue - https://github.com/springfox/springfox/issues/2202.

According to this, we cannot specify any content type for specific parts of type formData.

Resolution

Ways to work around this issue:
Swagger provides sample cURL record which can be executed separately

 

Here is the actual record - 
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Bearer <some token>' -F body={"objectType":"CSV","headerAt":1,"dataStartsAt":2,"tableNames":[]} -F files=Sample.csv 'http://localhost:9999/TDMModelService/api/ca/v1/objects?projectId=7548&versionId=7549'

We need to introduce 2 modifications for this record to make it work:
1. There needs to be added ;type=application/json
2. Data for body part of formData should have escaped quotes (with backslashes).
These changes are higlighted as bold below
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Bearer <some token>' -F body={\"objectType\":\"CSV\",\"headerAt\":1,\"dataStartsAt\":2,\"tableNames\":[]};type=application/json -F files=Sample.csv 'http://localhost:9999/TDMModelService/api/ca/v1/objects?projectId=7548&versionId=7549'



Attachments