From 7a1e7aded38f7342a131d80aa2a3f93dff896992 Mon Sep 17 00:00:00 2001 From: ryanrain2016 <398244837@qq.com> Date: Wed, 12 Dec 2018 10:28:31 +0800 Subject: [PATCH] fixed Link's encoding is no longer fixed to `application/json`, it's from the schema. --- README.md | 5 +++++ lib/codecs/corejson.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 109b256..57fb758 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,8 @@ To run the tests (linting & unit tests): [npm-url]: http://badge.fury.io/js/coreapi [codecov-image]: https://codecov.io/gh/core-api/javascript-client/branch/master/graph/badge.svg [codecov-url]: https://codecov.io/gh/core-api/javascript-client + + +# Fixed + +Link's encoding is no longer fixed to `application/json`, it's from the schema. \ No newline at end of file diff --git a/lib/codecs/corejson.js b/lib/codecs/corejson.js index d1d8a67..2d511f2 100644 --- a/lib/codecs/corejson.js +++ b/lib/codecs/corejson.js @@ -73,6 +73,7 @@ function primitiveToNode (data, baseUrl) { const title = getString(data, 'title') const description = getString(data, 'description') const fieldsData = getArray(data, 'fields') + const encoding = getString(data, 'encoding') || 'application/json' var fields = [] for (let idx = 0, len = fieldsData.length; idx < len; idx++) { let value = fieldsData[idx] @@ -83,7 +84,7 @@ function primitiveToNode (data, baseUrl) { let field = new document.Field(name, required, location, fieldDescription) fields.push(field) } - return new document.Link(url, method, 'application/json', fields, title, description) + return new document.Link(url, method, encoding, fields, title, description) } else if (isObject) { // Object let content = {}