Skip to content

Commit

Permalink
feat(oas3): support description in response object
Browse files Browse the repository at this point in the history
  • Loading branch information
klokane authored and kylef committed Jan 22, 2019
1 parent fed0668 commit 5958d1a
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 269 deletions.
2 changes: 1 addition & 1 deletion packages/fury-adapter-oas3-parser/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ HTTP Status Code ranges are not currently supported.

| Field Name | Support |
|:--|:--|
| description | |
| description | |
| headers ||
| content | [~](#media-type-object) |
| links ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const {
const parseObject = require('../parseObject');
const parseMediaTypeObject = require('./parseMediaTypeObject');

const parseCopy = require('../parseCopy');

const name = 'Response Object';
const unsupportedKeys = [
'description', 'headers', 'links',
'headers', 'links',
];
const isUnsupportedKey = R.anyPass(R.map(hasKey, unsupportedKeys));

Expand Down Expand Up @@ -58,6 +60,7 @@ function parseResponseObject(context, element) {

const parseMember = R.cond([
[hasKey('content'), R.compose(parseContent, getValue)],
[hasKey('description'), parseCopy(context, name, false)],

[isUnsupportedKey, createUnsupportedMemberWarning(namespace, name)],

Expand All @@ -71,21 +74,21 @@ function parseResponseObject(context, element) {
const parseResponse = pipeParseResult(namespace,
parseObject(context, name, parseMember),
(responseObject) => {
const responses = responseObject.get('content');

if (responses) {
// If we have responses from the media type parsing, return those
// after attaching Response Object information
return new namespace.elements.ParseResult(responses.map((response) => {
response.statusCode = element.key.toValue();
return response;
}));
}

// No media types defined in content, return empty response
const response = new namespace.elements.HttpResponse();
response.statusCode = element.key.toValue();
return response;
// Try to fecth responses from the media type parsing
// if not, create empty HttpResponse
const responses = R.or(responseObject.get('content'), [new namespace.elements.HttpResponse()]);

const description = responseObject.get('description');

return new namespace.elements.ParseResult(responses.map((response) => {
response.statusCode = element.key.toValue();

if (description) {
response.push(description);
}

return response;
}));
});

return parseResponse(element.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,55 @@
"content": {
"element": "array"
}
},
{
"element": "copy",
"attributes": {
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 14
},
"column": {
"element": "number",
"content": 24
}
},
"content": 296
},
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 14
},
"column": {
"element": "number",
"content": 45
}
},
"content": 21
}
]
}
]
}
]
}
},
"content": "A paged array of pets"
}
]
}
Expand All @@ -559,66 +608,6 @@
]
}
]
},
{
"element": "annotation",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "warning"
}
]
}
},
"attributes": {
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 14
},
"column": {
"element": "number",
"content": 11
}
},
"content": 283
},
{
"element": "number",
"attributes": {
"line": {
"element": "number",
"content": 14
},
"column": {
"element": "number",
"content": 22
}
},
"content": 11
}
]
}
]
}
]
}
},
"content": "'Response Object' contains unsupported key 'description'"
}
]
}
Loading

0 comments on commit 5958d1a

Please sign in to comment.