Skip to content

Commit

Permalink
fix(stringify): missing uniq path handler and prefix
Browse files Browse the repository at this point in the history
Signed-off-by: ding <playdingnow@gmail.com>
  • Loading branch information
yidinghan committed Nov 6, 2018
1 parent ce78410 commit 9c3cb1e
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions stringify_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ const defaultReqSchema = {
protocol: { type: 'string' },
secure: { type: 'string' },
ip: { type: 'string' },
length: { type: 'integer' },
},
};

const defaultResSchema = {
title: 'koa2-winston-info',
title: 'koa2-winston-info-res',
type: 'object',
properties: {
headers: {
Expand Down Expand Up @@ -103,24 +104,32 @@ const generateSchema = (payload) => {
reqKeys
.concat(reqSelect)
.map(asJsonSchemaPath)
.map(path => `properties.${path}`)
.forEach((path) => {
set(reqSchema, path, get(defaultReqSchema, path, {}));
});
reqUnselect
.map(asJsonSchemaPath)
.map(path => `properties.${path}`)
.forEach((path) => {
set(reqSchema, path, get(defaultResSchema, path, {}));
set(reqSchema, path, { type: 'null' });
});
reqUnselect.forEach((path) => {
set(reqSchema, path, { type: 'null' });
});
defaultInfoSchema.definitions.req = reqSchema;

const resSchema = {};
resKeys
.concat(resSelect)
.map(asJsonSchemaPath)
.map(path => `properties.${path}`)
.forEach((path) => {
set(resSchema, path, get(defaultResSchema, path, {}));
});
resUnselect
.map(asJsonSchemaPath)
.map(path => `properties.${path}`)
.forEach((path) => {
set(reqSchema, path, get(defaultResSchema, path, {}));
set(resSchema, path, { type: 'null' });
});
resUnselect.map(asJsonSchemaPath).forEach((path) => {
set(reqSchema, path, { type: 'null' });
});
defaultInfoSchema.definitions.res = resSchema;

return defaultInfoSchema;
Expand Down

0 comments on commit 9c3cb1e

Please sign in to comment.