tyranid-openapi
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -10,1 +10,7 @@ import { Tyr } from 'tyranid'; | ||
export declare function schema(def: Tyr.CollectionDefinitionHydrated, opts: IndividualCollectionSchemaOptions): SchemaContainer; | ||
/** | ||
* Include field in schema | ||
* | ||
* @param field tyranid field instance | ||
*/ | ||
export declare function include(field: Tyr.FieldInstance, path: string): boolean; |
@@ -267,8 +267,11 @@ "use strict"; | ||
return INCLUDE_CACHE[path]; | ||
if ((field.fields && utils_1.each(field.fields, include)) || | ||
if ((field.fields && | ||
utils_1.someOf(field.fields, (f, n) => include(f, extendPath(n, path)))) || | ||
(field.of && include(field.of, extendPath(name, path))) || | ||
field.def.openAPI) | ||
field.def.openAPI) { | ||
return (INCLUDE_CACHE[path] = true); | ||
INCLUDE_CACHE[path] = false; | ||
} | ||
return (INCLUDE_CACHE[path] = false); | ||
} | ||
exports.include = include; | ||
/** | ||
@@ -275,0 +278,0 @@ * Get a list of child props marked required |
@@ -24,2 +24,3 @@ "use strict"; | ||
})); | ||
// TODO: blow away INCLUDE_CACHE before each test | ||
ava_1.default('pascalCase should return correct values', t => { | ||
@@ -29,2 +30,11 @@ t.is(_1.pascal('my short sentence'), 'MyShortSentence'); | ||
}); | ||
ava_1.default('should not exclude nested fields if first field not openAPI', (t) => __awaiter(this, void 0, void 0, function* () { | ||
const col = tyranid_1.Tyr.byName.metricObservation; | ||
t.truthy(_1.include(col.fields.nested2, `${col.name}.nested2`)); | ||
})); | ||
ava_1.default('should not exclude nested fields with the same name', (t) => __awaiter(this, void 0, void 0, function* () { | ||
const col = tyranid_1.Tyr.byName.metricObservation; | ||
t.falsy(_1.include(col.fields.nested1, `${col.name}.nested1`)); | ||
t.truthy(_1.include(col.fields.nested2, `${col.name}.nested2`)); | ||
})); | ||
ava_1.default('should generate correct definition from schema', (t) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -31,0 +41,0 @@ const col = tyranid_1.Tyr.byName.metric; |
@@ -13,4 +13,4 @@ "use strict"; | ||
name: { is: 'string', openAPI: true, required: true } | ||
}, | ||
} | ||
}); | ||
//# sourceMappingURL=Metric.js.map |
@@ -17,5 +17,23 @@ "use strict"; | ||
date: { is: 'date', openAPI: true }, | ||
value: { is: 'double', openAPI: true } | ||
}, | ||
value: { is: 'double', openAPI: true }, | ||
nested1: { | ||
is: 'object', | ||
fields: { | ||
hidden: { | ||
is: 'boolean' | ||
} | ||
} | ||
}, | ||
nested2: { | ||
is: 'object', | ||
fields: { | ||
notApiField: { is: 'string' }, | ||
hidden: { | ||
is: 'boolean', | ||
openAPI: true | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
//# sourceMappingURL=MetricObservation.js.map |
@@ -35,6 +35,7 @@ "use strict"; | ||
type: { | ||
link: 'metricTargetType', openAPI: true | ||
link: 'metricTargetType', | ||
openAPI: true | ||
} | ||
}, | ||
} | ||
}); | ||
//# sourceMappingURL=MetricTarget.js.map |
@@ -30,13 +30,13 @@ "use strict"; | ||
years: { | ||
is: 'integer', | ||
is: 'integer' | ||
}, | ||
name: { | ||
is: 'string', | ||
note: 'The name of a skill that the user has.', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
note: 'The name of a skill that the user has.' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
//# sourceMappingURL=User.js.map |
@@ -31,4 +31,13 @@ import * as AJV from 'ajv'; | ||
[key: string]: T; | ||
}, fn: (element: T, field: string) => S): S | undefined; | ||
}, fn: (element: T, field: string) => S, returnPredicate?: (val: S) => boolean): S | undefined; | ||
/** | ||
* map over obj, short on true | ||
* | ||
* @param obj | ||
* @param fn | ||
*/ | ||
export declare const someOf: <T>(obj: { | ||
[key: string]: T; | ||
}, fn: (element: T, field: string) => boolean | undefined) => boolean | undefined; | ||
/** | ||
* Get options from schema | ||
@@ -35,0 +44,0 @@ * |
@@ -41,2 +41,8 @@ "use strict"; | ||
/** | ||
* return if value is defined | ||
* | ||
* @param val | ||
*/ | ||
const returnOnDefined = (val) => typeof val !== 'undefined'; | ||
/** | ||
* Iterate over properties in object | ||
@@ -47,7 +53,7 @@ * | ||
*/ | ||
function each(obj, fn) { | ||
function each(obj, fn, returnPredicate = returnOnDefined) { | ||
for (const field in obj) { | ||
if (obj.hasOwnProperty(field)) { | ||
const result = fn(obj[field], field); | ||
if (typeof result !== 'undefined') | ||
if (returnPredicate(result)) | ||
return result; | ||
@@ -58,2 +64,15 @@ } | ||
exports.each = each; | ||
/** | ||
* return if value is true | ||
* | ||
* @param val | ||
*/ | ||
const returnOnTrue = (val) => val === true; | ||
/** | ||
* map over obj, short on true | ||
* | ||
* @param obj | ||
* @param fn | ||
*/ | ||
exports.someOf = (obj, fn) => each(obj, fn, returnOnTrue); | ||
function options(def) { | ||
@@ -60,0 +79,0 @@ const openAPI = def.openAPI; |
{ | ||
"name": "tyranid-openapi", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Open API spec and express app generator for tyranid", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
120961
1994