Skip to content

Commit

Permalink
Merge 9a63d3c into 5329907
Browse files Browse the repository at this point in the history
  • Loading branch information
DScheglov committed Aug 29, 2021
2 parents 5329907 + 9a63d3c commit 2d98be0
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 63 deletions.
104 changes: 52 additions & 52 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
module.exports = {
'env': {
'commonjs': true,
'es6': true,
'node': true,
'jest/globals': true
},
'extends': [
'eslint:recommended',
'airbnb-base'
env: {
commonjs: true,
es6: true,
node: true,
'jest/globals': true,
},
extends: [
'eslint:recommended',
'airbnb-base',
],
plugins: ['jest'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
},
rules: {
indent: [
'error',
2,
],
'plugins': ['jest'],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parserOptions': {
'ecmaVersion': 2018
},
'rules': {
'indent': [
'error',
2
],
'linebreak-style': [
'error',
'unix'
],
'quotes': [
'error',
'single'
],
'semi': [
'error',
'always'
],
'global-require': 0,
'no-underscore-dangle': 0,
'import/order': 0,
'camelcase': 0,
'no-param-reassign': 0,
'no-use-before-define': 0,
'no-plusplus': 0,
'no-restricted-syntax': 0,
'no-continue': 0,
'arrow-parens': ['error', 'as-needed'],
'no-mixed-operators': 0,
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/valid-expect': 'error'
}
};
'linebreak-style': [
'error',
'unix',
],
quotes: [
'error',
'single',
],
semi: [
'error',
'always',
],
'global-require': 0,
'no-underscore-dangle': 0,
'import/order': 0,
camelcase: 0,
'no-param-reassign': 0,
'no-use-before-define': 0,
'no-plusplus': 0,
'no-restricted-syntax': 0,
'no-continue': 0,
'arrow-parens': ['error', 'as-needed'],
'no-mixed-operators': 0,
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/valid-expect': 'error',
},
};
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: node_js
node_js:
- "8"
- "9"
- "10"
- "12"
- "14"

env:
- MONGOOSE_VERSION=5
- MONGOOSE_VERSION=6

install:
- npm install
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ module.exports = function moduleFactory(mongoose) {
Types.Array.prototype.jsonSchema = types.array_jsonSchema;
Types.DocumentArray.prototype.jsonSchema = types.array_jsonSchema;

Types.Embedded.prototype.jsonSchema = types.mixed_jsonSchema;
if (Types.Embedded) {
Types.Embedded.prototype.jsonSchema = types.mixed_jsonSchema;
}

if (Types.Subdocument) {
Types.Subdocument.prototype.jsonSchema = types.mixed_jsonSchema;
}

Types.Mixed.prototype.jsonSchema = types.mixed_jsonSchema;

Types.Map.prototype.jsonSchema = types.map_jsonSchema;
Expand Down
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ module.exports = {
collectCoverageFrom: ['lib/**'],
coverageDirectory: 'coverage',
testEnvironment: 'node',
transformIgnorePatterns: ['/node_modules/'],
setupFiles: ['./jest.setup.js'],
};
6 changes: 6 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if (global.TextEncoder == null) {
// Support for node v.10
const util = require('util');
global.TextEncoder = util.TextEncoder;
global.TextDecoder = util.TextDecoder;
}
2 changes: 1 addition & 1 deletion lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function array_jsonSchema(name) {
result.items = this.caster.jsonSchema(itemName);
}

if (result.items.__required) {
if (result.items.__required || this.schemaOptions.required) {
result.minItems = 1;
}

Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
"devDependencies": {
"ajv": "^6.12.0",
"coveralls": "^3.0.2",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.8.2",
"jest": "^25.3.0",
"jsonschema": "^1.2.2",
"mongoose": "^5.0.0"
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.0",
"jest": "^27.1.0",
"jsonschema": "^1.2.2"
},
"peerDependencies": {
"mongoose": "^5.0.0"
Expand Down
2 changes: 2 additions & 0 deletions test/suites/description.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const mongoose = require('../../index')(require('mongoose'));
const isV6pl = require('mongoose/package.json').version > '6';
const assert = require('assert');

describe('Description: Schema.jsonSchema()', () => {
Expand Down Expand Up @@ -195,6 +196,7 @@ describe('Description: Schema.jsonSchema()', () => {
type: ['object', 'null'],
default: null,
properties: {
...(isV6pl ? { _id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' } } : undefined),
x: { type: 'number' },
y: { type: 'number' },
},
Expand Down
3 changes: 3 additions & 0 deletions test/suites/nullable-types.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Schema } = require('../../index')(require('mongoose'));
const isV6pl = require('mongoose/package.json').version > '6';
const assert = require('assert');

describe('nullable: schema.jsonSchema', () => {
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('nullable: schema.jsonSchema', () => {
type: ['object', 'null'],
default: null,
properties: {
...(isV6pl ? { _id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' } } : undefined),
x: {
type: 'array',
minItems: 1,
Expand Down Expand Up @@ -116,6 +118,7 @@ describe('nullable: schema.jsonSchema', () => {
type: 'object',
title: 'itemOf_t',
properties: {
...(isV6pl ? { _id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' } } : undefined),
x: { type: 'number' },
y: { type: 'number' },
},
Expand Down
4 changes: 4 additions & 0 deletions test/suites/translation.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable func-names */
const mongoose = require('../../index')(require('mongoose'));
const isV6pl = require('mongoose/package.json').version > '6';

const { Schema } = mongoose;
const assert = require('assert');
Expand Down Expand Up @@ -229,6 +230,7 @@ describe('schema.jsonSchema', () => {
title: 'embededDoc',
type: 'object',
properties: {
...(isV6pl ? { _id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' } } : undefined),
n: { type: 'number' },
s: { type: 'string' },
d: { type: 'string', format: 'date-time' },
Expand Down Expand Up @@ -370,6 +372,7 @@ describe('schema.jsonSchema', () => {
title: 'rNestedDoc',
type: 'object',
properties: {
...(isV6pl ? { _id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' } } : undefined),
n: { type: 'number' },
s: { type: 'string' },
},
Expand Down Expand Up @@ -495,6 +498,7 @@ describe('schema.jsonSchema', () => {
title: 'xyz',
type: 'object',
properties: {
...(isV6pl ? { _id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' } } : undefined),
x: {
type: 'array',
minItems: 1,
Expand Down

0 comments on commit 2d98be0

Please sign in to comment.