mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 16:13:06 +00:00
Upgraded JSON Schema from version 6 to version 7 Upgraded TypeDoc version to latest Replaced 'jsonschema' with 'json-schema' package to better comply with 'ts-json-schema-generator' Replace JSON Schema validation with AJV in areas where it wasn't used previously Removed commander help output as it causes strange issues
128 lines
3.5 KiB
TypeScript
128 lines
3.5 KiB
TypeScript
/*
|
|
* 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 {Logger} from '@openstapps/logger';
|
|
import {expect} from 'chai';
|
|
import {slow, suite, test, timeout} from 'mocha-typescript';
|
|
import {join} from 'path';
|
|
import {Converter, getValidatableTypesFromReflection} from '../src/schema';
|
|
|
|
process.on('unhandledRejection', (error: unknown) => {
|
|
if (error instanceof Error) {
|
|
Logger.error('UNHANDLED REJECTION', error.stack);
|
|
}
|
|
process.exit(1);
|
|
});
|
|
|
|
@suite(timeout(20000), slow(10000))
|
|
export class SchemaSpec {
|
|
@test
|
|
async getSchema() {
|
|
const converter = new Converter(join(__dirname, '..', 'src', 'resources'));
|
|
|
|
const schema = converter.getSchema('Foo', '0.0.1');
|
|
expect(schema).to.be.deep.equal({
|
|
$id: 'https://core.stapps.tu-berlin.de/v0.0.1/lib/schema/Foo.json',
|
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
additionalProperties: false,
|
|
definitions: {
|
|
FooType: {
|
|
description: 'This is a simple type declaration for\nusage in the Foo interace.',
|
|
enum: [
|
|
'Foo',
|
|
],
|
|
type: 'string',
|
|
},
|
|
SCFoo: {
|
|
additionalProperties: false,
|
|
description: 'This is a simple interface declaration for\ntesting the schema generation and validation.',
|
|
properties: {
|
|
lorem: {
|
|
description: 'Dummy parameter',
|
|
enum: [
|
|
'ipsum',
|
|
],
|
|
type: 'string',
|
|
},
|
|
type: {
|
|
$ref: '#/definitions/FooType',
|
|
description: 'String literal type property',
|
|
},
|
|
},
|
|
required: [
|
|
'lorem',
|
|
'type',
|
|
],
|
|
type: 'object',
|
|
},
|
|
},
|
|
description: 'This is a simple interface declaration for\ntesting the schema generation and validation.',
|
|
properties: {
|
|
lorem: {
|
|
description: 'Dummy parameter',
|
|
enum: [
|
|
'ipsum',
|
|
],
|
|
type: 'string',
|
|
},
|
|
type: {
|
|
$ref: '#/definitions/FooType',
|
|
description: 'String literal type property',
|
|
},
|
|
},
|
|
required: [
|
|
'lorem',
|
|
'type',
|
|
],
|
|
type: 'object',
|
|
});
|
|
}
|
|
|
|
@test
|
|
async getValidatableTypesFromReflection() {
|
|
const reflection: any = {
|
|
children: [
|
|
{
|
|
children: [
|
|
{
|
|
comment: {
|
|
tags: [
|
|
{
|
|
tagName: 'validatable',
|
|
},
|
|
],
|
|
},
|
|
name: 'foo',
|
|
},
|
|
{
|
|
name: 'bar',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
children: [
|
|
{
|
|
name: 'foobar',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const validatableTypes = getValidatableTypesFromReflection(reflection as any);
|
|
|
|
expect(validatableTypes).to.be.deep.equal(['foo']);
|
|
}
|
|
}
|