opensupplyhub / open-apparel-registry

An application for searching, matching, uploading factories.
MIT License
32 stars 13 forks source link

Swagger generated curl examples that include a JSON POST are invalid #922

Closed jwalgran closed 4 years ago

jwalgran commented 4 years ago

Overview

The automatically generated swagger example for POSTing a new facility returns a 400 error if you copy past and run it in a shell. (In this case bash on macOS 10.14.6)

$ curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Token abc123...' -d '{ \ 
   "country": "US", \ 
   "name": "Azalea", \ 
   "address": "990 Spring Garden Philadelphia" \ 
 }' 'https://localhost:8081/api/facilities/?create=false'
{"detail":"JSON parse error - Expecting property name enclosed in double quotes: line 1 column 3 (char 2)"}

Removing the \ characters resolves the issue. It appears they are being included in the literal JSON string that is submitted.

$ curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Token abc123...' -d '{  
   "country": "US",  
   "name": "Azalea",  
   "address": "990 Spring Garden Philadelphia"  
 }' 'https://localhost:8081/api/facilities/?create=false'
{ ...successful match result... }

Expected Behavior

The example curl command can be pasted into a shell and run successfully without modification.

Actual Behavior

A 400 error is returned.

Steps to Reproduce

jwalgran commented 4 years ago

Superseded by #923