Fixes consumes and produces
This commit is contained in:
Родитель
70327dce09
Коммит
5bbf7114b1
|
@ -9,6 +9,7 @@ var util = require('util'),
|
|||
utils = require('../util/utils'),
|
||||
Constants = require('../util/constants'),
|
||||
log = require('../util/logging'),
|
||||
_ = require('lodash'),
|
||||
ErrorCodes = Constants.ErrorCodes;
|
||||
|
||||
/**
|
||||
|
@ -522,9 +523,27 @@ class SpecResolver {
|
|||
for (let verb in pathObj) {
|
||||
let operation = pathObj[verb];
|
||||
//scan every parameter in the operation
|
||||
let consumes = _.isUndefined(operation.consumes) ?
|
||||
_.isUndefined(spec.consumes) ?
|
||||
['application/json']
|
||||
: spec.consumes
|
||||
: operation.consumes;
|
||||
|
||||
let produces = _.isUndefined(operation.produces) ?
|
||||
_.isUndefined(spec.produces) ?
|
||||
['application/json']
|
||||
: spec.produces
|
||||
: operation.produces;
|
||||
|
||||
function octetStream(elements) {
|
||||
return elements.some(e => {
|
||||
return e.toLowerCase() === 'application/octet-stream';
|
||||
});
|
||||
}
|
||||
|
||||
if (operation.parameters) {
|
||||
operation.parameters.forEach((param) => {
|
||||
if (param.in && param.in === 'body' && param.schema) {
|
||||
if (param.in && param.in === 'body' && param.schema && !octetStream(consumes)) {
|
||||
param.schema = utils.relaxModelLikeEntities(param.schema);
|
||||
} else {
|
||||
param = utils.relaxEntityType(param, param.required);
|
||||
|
@ -535,10 +554,8 @@ class SpecResolver {
|
|||
if (operation.responses) {
|
||||
for (let statusCode in operation.responses) {
|
||||
let response = operation.responses[statusCode];
|
||||
if (response.schema) {
|
||||
if (operation.produces != 'application/octet-stream') {
|
||||
response.schema = utils.relaxModelLikeEntities(response.schema);
|
||||
}
|
||||
if (response.schema && !octetStream(produces)) {
|
||||
response.schema = utils.relaxModelLikeEntities(response.schema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
"https"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
"application/octet-stream"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
"application/octet-stream"
|
||||
],
|
||||
"paths": {
|
||||
"/open/object": {
|
||||
|
@ -28,6 +28,7 @@
|
|||
"$ref": "./examples/download.json"
|
||||
}
|
||||
},
|
||||
"consumes": [],
|
||||
"produces": [
|
||||
"application/octet-stream"
|
||||
],
|
||||
|
@ -53,9 +54,7 @@
|
|||
"$ref": "./examples/download.json"
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/octet-stream"
|
||||
],
|
||||
"consumes": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
|
@ -78,6 +77,7 @@
|
|||
"$ref": "./examples/download.json"
|
||||
}
|
||||
},
|
||||
"consumes": [],
|
||||
"produces": [
|
||||
"application/octet-stream"
|
||||
],
|
||||
|
@ -130,9 +130,6 @@
|
|||
"tags": [
|
||||
"Content"
|
||||
],
|
||||
"consumes": [
|
||||
"application/octet-stream"
|
||||
],
|
||||
"operationId": "Content_ConsumeTypeFile",
|
||||
"description": "Operation to test consume application/octet-stream",
|
||||
"x-ms-examples": {
|
||||
|
|
Загрузка…
Ссылка в новой задаче