Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function buildMongooseSchema(target: any): MongooseSchema {
const properties = PropertyRegistry.getProperties(target);
const schema: MongooseSchema = {schema: {}, virtuals: new Map()};
if (properties) {
const properties = PropertyRegistry.getProperties(target);
properties.forEach((propertyMetadata, key) => {
if (MONGOOSE_RESERVED_KEYS.includes(key as string)) {
return;
}
// Keeping the Mongoose Schema separate so it can overwrite everything once schema has been built.
const schemaTypeOptions = propertyMetadata.store.get(MONGOOSE_SCHEMA) || {};
if (isVirtualRef(schemaTypeOptions)) {
schemaTypeOptions.justOne = !propertyMetadata.isArray;
schema.virtuals.set(key as string, schemaTypeOptions);
return;
}
export function buildMongooseSchema(target: any): MongooseSchema {
const properties = PropertyRegistry.getProperties(target);
const schema: MongooseSchema = {schema: {}, virtuals: new Map()};
if (properties) {
const properties = PropertyRegistry.getProperties(target);
properties.forEach((propertyMetadata, key) => {
if (MONGOOSE_RESERVED_KEYS.includes(key as string)) {
return;
}
// Keeping the Mongoose Schema separate so it can overwrite everything once schema has been built.
const schemaTypeOptions = propertyMetadata.store.get(MONGOOSE_SCHEMA) || {};
if (isVirtualRef(schemaTypeOptions)) {
schemaTypeOptions.justOne = !propertyMetadata.isArray;
schema.virtuals.set(key as string, schemaTypeOptions);
build(): this {
const properties = PropertyRegistry.getProperties(this.target);
const store = Store.from(this.target);
const schema: Schema = this.getClassSchema();
schema.type = "object";
schema.properties = {};
if (store.get("description")) {
schema.description = schema.description || store.get("description");
}
if (schema.required && schema.required.length) {
this._responses[400] = {description: "Missing required parameter"};
}
properties.forEach((property: PropertyMetadata) => {
const propertyKey = property.name || property.propertyKey;
schema.properties![String(propertyKey)] = this.createSchema(property);
export function buildMongooseSchema(target: any): mongoose.SchemaDefinition {
const properties = PropertyRegistry.getProperties(target);
const jsonSchema: any = JsonSchemesRegistry.getSchemaDefinition(target) || {};
const mSchema: mongoose.SchemaDefinition = {};
if (properties) {
properties.forEach((propertyMetadata: PropertyMetadata, propertyKey: string) => {
if (MONGOOSE_RESERVED_KEYS.indexOf(propertyKey) > -1) {
return;
}
let definition = {
required: propertyMetadata.required
? function() {
return propertyMetadata.isRequired(this[propertyKey]);
}
: false
};
export function buildMongooseSchema(target: any): mongoose.SchemaDefinition {
const properties = PropertyRegistry.getProperties(target);
const jsonSchema: any = JsonSchemesRegistry.getSchemaDefinition(target) || {};
const mSchema: mongoose.SchemaDefinition = {};
if (properties) {
properties.forEach((propertyMetadata: PropertyMetadata, propertyKey: string) => {
if (MONGOOSE_RESERVED_KEYS.indexOf(propertyKey) > -1) {
return;
}
let definition = {
required: propertyMetadata.required
? function() {
return propertyMetadata.isRequired(this[propertyKey]);
}
: false
};