Files
openstapps/packages/json-schema-generator/test/schema.spec.js

61 lines
2.0 KiB
JavaScript

/* eslint-disable unicorn/prefer-module */
/*
* Copyright (C) 2018-2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {expect} from 'chai';
import {compileSchema} from '../src/index.js';
import path from 'path';
import {fileURLToPath} from 'url';
describe('Schema', function () {
this.timeout(40_000);
this.slow(10_000);
it('should create schema', function () {
const [schema, _types] = compileSchema(
path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'src', 'resources'),
path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'tsconfig.json'),
);
expect(schema).to.be.deep.equal({
$schema: 'http://json-schema.org/draft-07/schema#',
definitions: {
FooType: {
description: 'This is a simple type declaration for usage in the Foo interface.',
const: 'Foo',
type: 'string',
},
Foo: {
additionalProperties: false,
description:
'This is a simple interface declaration for testing the schema generation and validation.',
properties: {
lorem: {
description: 'lorem parameter',
enum: ['lorem', 'ipsum'],
type: 'string',
},
type: {
$ref: '#/definitions/FooType',
description: 'String literal type property',
},
},
required: ['lorem', 'type'],
type: 'object',
},
},
});
});
});