Skip to content

Commit

Permalink
1.Downgrade joi-to-json-schema because of lightsofapollo/joi-to-json-…
Browse files Browse the repository at this point in the history
…schema#11

2. Remove operationId as it's optional and not easy to auto-generate a unique one if dev is not careful enough

3. Fix object field in array not processed issue
  • Loading branch information
kenchen-cs committed Oct 7, 2019
1 parent 31b4eb5 commit a7caa16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const ROUTE_DEF_TEMPLATE = {
tags: [],
summary: '',
description: '',
operationId: '',
parameters: [],
responses: {
500: {
Expand Down Expand Up @@ -69,13 +68,17 @@ function _addArrayItemsSchema(schema, joiDefinition) {
})
}
} else {
_.forEach(joiDefinition.items.properties, (item) => {
_.forEach(joiDefinition.items.properties, (item, field) => {
if (item.examples && item.example) {
delete item.examples;
}

if (item.type === 'array') {
_addArrayItemsSchema(item, item);
}
if (item.type === 'object') {
joiDefinition.items.properties[field] = buildEmbeddedSchema(item);
}
})
schema.items = _.omit(joiDefinition.items, ['patterns']);
}
Expand Down Expand Up @@ -326,7 +329,6 @@ function buildSwaggerRequest(docEntity, moduleId, basePath, routeDef) {
swaggerReq.tags.push(moduleId);
swaggerReq.summary = routeDef.summary;
swaggerReq.description = routeDef.description;
swaggerReq.operationId = actionName;

routePath[routeDef.method] = swaggerReq;

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "joi-route-to-swagger",
"version": "0.7.0",
"version": "0.8.0",
"description": "Convert joi route definition to swagger doc json format (Open API v3)",
"main": "index.js",
"scripts": {
Expand All @@ -25,7 +25,7 @@
},
"homepage": "https://github.com/kenspirit/joi-route-to-swagger#readme",
"dependencies": {
"joi-to-json-schema": "^4.0.0",
"joi-to-json-schema": "^3.5.0",
"lodash": "^4.17.15"
},
"devDependencies": {
Expand Down
6 changes: 1 addition & 5 deletions test/sample_api_doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
],
"summary": "List",
"description": "",
"operationId": "dummyMiddlewareA",
"parameters": [
{
"name": "productId",
Expand Down Expand Up @@ -189,7 +188,6 @@
],
"summary": "Create",
"description": "",
"operationId": "dummyMiddlewareC",
"parameters": [],
"responses": {
"500": {
Expand Down Expand Up @@ -221,7 +219,6 @@
],
"summary": "Update",
"description": "",
"operationId": "dummyMiddlewareB",
"parameters": [
{
"name": "id",
Expand Down Expand Up @@ -260,7 +257,6 @@
],
"summary": "Open",
"description": "",
"operationId": "dummyMiddlewareD",
"parameters": [
{
"name": "id",
Expand Down Expand Up @@ -367,4 +363,4 @@
}
}
}
}
}

0 comments on commit a7caa16

Please sign in to comment.