anyone encounter "Error parsing json" when uploadi...
# pact-jvm
a
anyone encounter "Error parsing json" when uploading the OAS to the broker? happens both for yml and json file, the file is created by springdoc-openapi and generates a 3.0.1 openapi version file which seems valid to my ide
m
hello!
👋 1
how are you uploading the OAS - are you able to share?
a
currently in a meeting, will get back to you in a moment, sorry
👍 1
I am using a bash script, based on this example (https://docs.pactflow.io/docs/bi-directional-contract-testing/contracts/oas/#publishing-the-provider-contract--results-to-pactflow) currently it's a yml file,
Copy code
OAS=$(cat ${CI_BUILDS_DIR}/${CI_PROJECT_PATH}/target/openApi/openapi.yml | base64 -w0)
curl:
Copy code
curl \
  -X PUT \
  -H "Authorization: Bearer ${PACT_BROKER_TOKEN}" \
  -H "Content-Type: application/json" \
  "${PACT_BROKER_BASE_URL}/contracts/provider/${PACTICIPANT}/version/${CI_COMMIT_SHORT_SHA}" \
  -d '{ "content": "'$OAS'", "contractType": "oas", "contentType": "application/yaml", "verificationResults": { "success": '$SUCCESS', "content": '$REPORT', "contentType": "text/plain", "verifier": "verifier" } }'
the output of the curl: ==> Uploading OAS to Pactflow 196 % Total % Received % Xferd Average Speed Time Time Time Current 197 Dload Upload Total Spent Left Speed 198100 13839 100 6973 100 6866 4849 4774 00001 00001 -- -- 9617 199{"error":"Error parsing JSON - Error parsing JSON
m
interesting. Is it a really big file by any chance?
is
$REPORT
a string or a a primitive? I think it would need escaping also if it’s a string (update: definitely needs quoting if a string, see below)
you may want to out the new beta CLI for this - https://pact-foundation.slack.com/archives/CLS16AVEE/p1652436428503859
(it’s the usual CLI, with a feature flag enabled to publish provider contracts)
FYI this is how I managed to get an invalid JSON locally using your code above as a basis:
Copy code
export REPORT="aoeuaeou"
export SUCCESS=true
echo '{ "content": "'$OAS'", "contractType": "oas", "contentType": "application/yaml", "verificationResults": { "success": '$SUCCESS', "content": '$REPORT', "contentType": "text/plain", "verifier": "verifier" } }'  | jq .

parse error: Invalid numeric literal at line 1, column 137
a
it's super small
report was a string (with some whitespace)
and result stays the same when I switch report to a simple string
m
Ok cool, I think you just need to add double quotes around REPORT then
a
in the curl command?
what exactly is this report anyway?^^
quotes worked wonders, thanks @Matt (pactflow.io / pact-js / pact-go)
When I have the sample up and running with the bidirectional, I will get back to you regarding the new CLI thingy