joi-route-to-swagger 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +17 -10
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -101,23 +101,30 @@ function addRouteParameters(sharedSchemas, route, validators, position) {
|
|
|
101
101
|
})
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
function containsBinaryField(schema, sharedSchemas) {
|
|
105
|
+
let anyBinaryField = _.some(schema.properties, (fieldDefn) => {
|
|
106
|
+
if (fieldDefn.type === 'array') {
|
|
107
|
+
return fieldDefn.items.format === 'binary'
|
|
108
|
+
}
|
|
109
|
+
return fieldDefn.format === 'binary'
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
if (!anyBinaryField && schema.$ref) {
|
|
113
|
+
const sharedSchemaName = schema.$ref.replace('#/components/schemas/', '')
|
|
114
|
+
anyBinaryField = containsBinaryField(sharedSchemas[sharedSchemaName])
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return anyBinaryField
|
|
118
|
+
}
|
|
119
|
+
|
|
104
120
|
function addRequestBodyParams(sharedSchemas, swaggerReq, validators) {
|
|
105
121
|
if (validators && validators.body) {
|
|
106
122
|
const schema = joi2json(validators.body, 'open-api', sharedSchemas)
|
|
107
123
|
delete schema.schemas
|
|
108
124
|
|
|
109
125
|
let contentType = 'application/json'
|
|
110
|
-
let anyBinaryField = _.some(schema.properties, (fieldDefn) => {
|
|
111
|
-
return fieldDefn.format === 'binary'
|
|
112
|
-
})
|
|
113
|
-
if (schema.$ref) {
|
|
114
|
-
const sharedSchemaName = schema.$ref.replace('#/components/schemas/', '')
|
|
115
|
-
anyBinaryField = _.some(sharedSchemas[sharedSchemaName].properties, (fieldDefn) => {
|
|
116
|
-
return fieldDefn.format === 'binary'
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
126
|
|
|
120
|
-
if (
|
|
127
|
+
if (containsBinaryField(schema, sharedSchemas)) {
|
|
121
128
|
contentType = 'multipart/form-data'
|
|
122
129
|
}
|
|
123
130
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joi-route-to-swagger",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Convert joi route definition to swagger doc json format (Open API v3)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/kenspirit/joi-route-to-swagger#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"joi-to-json": "^2.
|
|
32
|
+
"joi-to-json": "^2.6.1",
|
|
33
33
|
"lodash": "^4.17.21"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|