From 2eff358c52f1062e9f168ebf5f567acee6893cb1 Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Tue, 2 Jul 2024 23:46:17 +0400 Subject: [PATCH] test(definitions): tag, server, reference new tests structure https://github.com/asyncapi/spec-json-schemas/issues/551 --- test/definitions/3.0.0/models/index.mjs | 3 - .../3.0.0/models/reference/index.mjs | 6 -- .../index.mjs => reference object.test.mjs} | 47 ++++++-- .../reference/reference object/array.json | 11 -- .../reference/reference object/boolean.json | 3 - .../reference/reference object/empty.json | 3 - .../reference/reference object/null.json | 3 - .../reference/reference object/number.json | 3 - .../reference/reference object/object.json | 5 - .../reference/reference object/string.json | 3 - .../reference/reference object/uri.json | 3 - .../3.0.0/models/reference/reference.test.mjs | 49 +++++++++ .../models/reference/reference/empty.json | 1 - .../models/reference/reference/example.json | 3 - .../models/reference/reference/extended.json | 8 -- .../models/reference/reference/index.mjs | 49 --------- .../reference/only required properties.json | 3 - .../without required properties.json | 1 - .../reference/reference/wrongly extended.json | 9 -- .../definitions/3.0.0/models/server/index.mjs | 6 -- .../models/server/server variable.test.mjs | 75 +++++++++++++ .../3.0.0/models/server/server.test.mjs | 61 +++++++++++ .../3.0.0/models/server/server/empty.json | 1 - .../3.0.0/models/server/server/example.json | 100 ------------------ .../3.0.0/models/server/server/index.mjs | 45 -------- .../server/only required properties.json | 4 - .../server/without required properties.json | 100 ------------------ .../models/server/serverVariable/empty.json | 1 - .../models/server/serverVariable/example.json | 12 --- .../server/serverVariable/extended.json | 17 --- .../models/server/serverVariable/index.mjs | 37 ------- .../only required properties.json | 1 - .../without required properties.json | 12 --- test/definitions/3.0.0/models/tag/empty.json | 1 - .../definitions/3.0.0/models/tag/example.json | 8 -- .../3.0.0/models/tag/extended.json | 8 -- test/definitions/3.0.0/models/tag/index.mjs | 39 ------- .../models/tag/only required properties.json | 3 - .../definitions/3.0.0/models/tag/tag.test.mjs | 60 +++++++++++ .../tag/without required properties.json | 7 -- .../3.0.0/models/tag/wrongly extended.json | 9 -- 41 files changed, 281 insertions(+), 539 deletions(-) delete mode 100644 test/definitions/3.0.0/models/reference/index.mjs rename test/definitions/3.0.0/models/reference/{reference object/index.mjs => reference object.test.mjs} (60%) delete mode 100644 test/definitions/3.0.0/models/reference/reference object/array.json delete mode 100644 test/definitions/3.0.0/models/reference/reference object/boolean.json delete mode 100644 test/definitions/3.0.0/models/reference/reference object/empty.json delete mode 100644 test/definitions/3.0.0/models/reference/reference object/null.json delete mode 100644 test/definitions/3.0.0/models/reference/reference object/number.json delete mode 100644 test/definitions/3.0.0/models/reference/reference object/object.json delete mode 100644 test/definitions/3.0.0/models/reference/reference object/string.json delete mode 100644 test/definitions/3.0.0/models/reference/reference object/uri.json create mode 100644 test/definitions/3.0.0/models/reference/reference.test.mjs delete mode 100644 test/definitions/3.0.0/models/reference/reference/empty.json delete mode 100644 test/definitions/3.0.0/models/reference/reference/example.json delete mode 100644 test/definitions/3.0.0/models/reference/reference/extended.json delete mode 100644 test/definitions/3.0.0/models/reference/reference/index.mjs delete mode 100644 test/definitions/3.0.0/models/reference/reference/only required properties.json delete mode 100644 test/definitions/3.0.0/models/reference/reference/without required properties.json delete mode 100644 test/definitions/3.0.0/models/reference/reference/wrongly extended.json delete mode 100644 test/definitions/3.0.0/models/server/index.mjs create mode 100644 test/definitions/3.0.0/models/server/server variable.test.mjs create mode 100644 test/definitions/3.0.0/models/server/server.test.mjs delete mode 100644 test/definitions/3.0.0/models/server/server/empty.json delete mode 100644 test/definitions/3.0.0/models/server/server/example.json delete mode 100644 test/definitions/3.0.0/models/server/server/index.mjs delete mode 100644 test/definitions/3.0.0/models/server/server/only required properties.json delete mode 100644 test/definitions/3.0.0/models/server/server/without required properties.json delete mode 100644 test/definitions/3.0.0/models/server/serverVariable/empty.json delete mode 100644 test/definitions/3.0.0/models/server/serverVariable/example.json delete mode 100644 test/definitions/3.0.0/models/server/serverVariable/extended.json delete mode 100644 test/definitions/3.0.0/models/server/serverVariable/index.mjs delete mode 100644 test/definitions/3.0.0/models/server/serverVariable/only required properties.json delete mode 100644 test/definitions/3.0.0/models/server/serverVariable/without required properties.json delete mode 100644 test/definitions/3.0.0/models/tag/empty.json delete mode 100644 test/definitions/3.0.0/models/tag/example.json delete mode 100644 test/definitions/3.0.0/models/tag/extended.json delete mode 100644 test/definitions/3.0.0/models/tag/index.mjs delete mode 100644 test/definitions/3.0.0/models/tag/only required properties.json create mode 100644 test/definitions/3.0.0/models/tag/tag.test.mjs delete mode 100644 test/definitions/3.0.0/models/tag/without required properties.json delete mode 100644 test/definitions/3.0.0/models/tag/wrongly extended.json diff --git a/test/definitions/3.0.0/models/index.mjs b/test/definitions/3.0.0/models/index.mjs index add80ec4..ca2b3af1 100644 --- a/test/definitions/3.0.0/models/index.mjs +++ b/test/definitions/3.0.0/models/index.mjs @@ -3,7 +3,4 @@ import {describe} from 'vitest'; describe('Models Test Suite', async () => { await import('./channel'); await import('./operation'); - await import('./reference'); - await import('./server'); - await import('./tag'); }); diff --git a/test/definitions/3.0.0/models/reference/index.mjs b/test/definitions/3.0.0/models/reference/index.mjs deleted file mode 100644 index ec55a2e8..00000000 --- a/test/definitions/3.0.0/models/reference/index.mjs +++ /dev/null @@ -1,6 +0,0 @@ -import {describe} from 'vitest'; - -describe('Reference Test Suite', async () => { - await import('./reference'); - await import('./reference object'); -}); \ No newline at end of file diff --git a/test/definitions/3.0.0/models/reference/reference object/index.mjs b/test/definitions/3.0.0/models/reference/reference object.test.mjs similarity index 60% rename from test/definitions/3.0.0/models/reference/reference object/index.mjs rename to test/definitions/3.0.0/models/reference/reference object.test.mjs index 58894933..f672a9f5 100644 --- a/test/definitions/3.0.0/models/reference/reference object/index.mjs +++ b/test/definitions/3.0.0/models/reference/reference object.test.mjs @@ -1,52 +1,77 @@ -import path from 'path'; -import TestHelper from '@test/test-helper'; +import TestHelper from '@test/test-helper.mjs'; const jsonSchema = require('@definitions/3.0.0/Reference.json'); describe('Reference Object', () => { it('$ref may be empty', () => TestHelper.objectIsValid( jsonSchema, - path.resolve(__dirname, './empty.json'), + { + "$ref": "" + }, )); it('$ref cannot be number', () => TestHelper.objectIsNotValid( jsonSchema, - path.resolve(__dirname, './number.json'), + { + "$ref": 1234 + }, ['must be string'] )); it('$ref cannot be object', () => TestHelper.objectIsNotValid( jsonSchema, - path.resolve(__dirname, './object.json'), + { + "$ref": { + "$ref": "#/components/schemas/user" + } + }, ['must be string'] )); it('$ref cannot be plain string', () => TestHelper.objectIsNotValid( jsonSchema, - path.resolve(__dirname, './string.json'), + { + "$ref": "string value" + }, ['must match format "uri-reference"'] )); it('$ref cannot be boolean', () => TestHelper.objectIsNotValid( jsonSchema, - path.resolve(__dirname, './boolean.json'), + { + "$ref": true + }, ['must be string'] )); it('$ref cannot be null', () => TestHelper.objectIsNotValid( jsonSchema, - path.resolve(__dirname, './null.json'), + { + "$ref": null + }, ['must be string'] )); it('$ref cannot be array', () => TestHelper.objectIsNotValid( jsonSchema, - path.resolve(__dirname, './array.json'), + { + "$ref": [ + 1, + null, + false, + "#/components/schemas/user", + { + "$ref": "#/components/schemas/user" + } + ] + }, ['must be string'] )); - it('$ref is URI', () => TestHelper.objectIsValid( + it('$ref MUST be URI', () => TestHelper.objectIsValid( jsonSchema, - path.resolve(__dirname, './uri.json'), + { + "$ref": "#/components/schemas/user" + }, )); }); diff --git a/test/definitions/3.0.0/models/reference/reference object/array.json b/test/definitions/3.0.0/models/reference/reference object/array.json deleted file mode 100644 index 04cdc564..00000000 --- a/test/definitions/3.0.0/models/reference/reference object/array.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$ref": [ - 1, - null, - false, - "#/components/schemas/user", - { - "$ref": "#/components/schemas/user" - } - ] -} diff --git a/test/definitions/3.0.0/models/reference/reference object/boolean.json b/test/definitions/3.0.0/models/reference/reference object/boolean.json deleted file mode 100644 index a40732d9..00000000 --- a/test/definitions/3.0.0/models/reference/reference object/boolean.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": true -} diff --git a/test/definitions/3.0.0/models/reference/reference object/empty.json b/test/definitions/3.0.0/models/reference/reference object/empty.json deleted file mode 100644 index 61db4a8f..00000000 --- a/test/definitions/3.0.0/models/reference/reference object/empty.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": "" -} diff --git a/test/definitions/3.0.0/models/reference/reference object/null.json b/test/definitions/3.0.0/models/reference/reference object/null.json deleted file mode 100644 index 61dc3cea..00000000 --- a/test/definitions/3.0.0/models/reference/reference object/null.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": null -} diff --git a/test/definitions/3.0.0/models/reference/reference object/number.json b/test/definitions/3.0.0/models/reference/reference object/number.json deleted file mode 100644 index 2d652a0a..00000000 --- a/test/definitions/3.0.0/models/reference/reference object/number.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": 1234 -} diff --git a/test/definitions/3.0.0/models/reference/reference object/object.json b/test/definitions/3.0.0/models/reference/reference object/object.json deleted file mode 100644 index 44ae5b68..00000000 --- a/test/definitions/3.0.0/models/reference/reference object/object.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$ref": { - "$ref": "#/components/schemas/user" - } -} diff --git a/test/definitions/3.0.0/models/reference/reference object/string.json b/test/definitions/3.0.0/models/reference/reference object/string.json deleted file mode 100644 index f7115df0..00000000 --- a/test/definitions/3.0.0/models/reference/reference object/string.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": "string value" -} diff --git a/test/definitions/3.0.0/models/reference/reference object/uri.json b/test/definitions/3.0.0/models/reference/reference object/uri.json deleted file mode 100644 index fd5bb0d1..00000000 --- a/test/definitions/3.0.0/models/reference/reference object/uri.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": "#/components/schemas/user" -} diff --git a/test/definitions/3.0.0/models/reference/reference.test.mjs b/test/definitions/3.0.0/models/reference/reference.test.mjs new file mode 100644 index 00000000..7869308f --- /dev/null +++ b/test/definitions/3.0.0/models/reference/reference.test.mjs @@ -0,0 +1,49 @@ +import { + JsonSchemaTestSuite, + JsonSchemaTestSuiteConfig, + JsonSchemaTestSuiteData +} from '@test/definitions/base-schema-test.mjs'; +import {describe} from 'vitest'; + +const jsonSchema = require('@definitions/3.0.0/Reference.json'); + +const config = new JsonSchemaTestSuiteConfig( + true, + ['must have required property \'$ref\''], + true, + [] +); + +const data = new JsonSchemaTestSuiteData( + jsonSchema, + [ + { + "$ref": "#/components/schemas/user" + } + ], + { + "$ref": "#/components/schemas/user" + }, + {}, + { + "$ref": "#/components/schemas/user", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + } + }, + { + "$ref": "#/components/schemas/user", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + }, + "ext-number": 1 + } +); + +describe('Reference', () => { + new JsonSchemaTestSuite(data, config).testSuite() +}); diff --git a/test/definitions/3.0.0/models/reference/reference/empty.json b/test/definitions/3.0.0/models/reference/reference/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/reference/reference/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/reference/reference/example.json b/test/definitions/3.0.0/models/reference/reference/example.json deleted file mode 100644 index fd5bb0d1..00000000 --- a/test/definitions/3.0.0/models/reference/reference/example.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": "#/components/schemas/user" -} diff --git a/test/definitions/3.0.0/models/reference/reference/extended.json b/test/definitions/3.0.0/models/reference/reference/extended.json deleted file mode 100644 index 337eb3ec..00000000 --- a/test/definitions/3.0.0/models/reference/reference/extended.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "$ref": "#/components/schemas/user", - "x-number": 0, - "x-string": "", - "x-object": { - "property": {} - } -} diff --git a/test/definitions/3.0.0/models/reference/reference/index.mjs b/test/definitions/3.0.0/models/reference/reference/index.mjs deleted file mode 100644 index a07cef17..00000000 --- a/test/definitions/3.0.0/models/reference/reference/index.mjs +++ /dev/null @@ -1,49 +0,0 @@ -import path from 'path'; -import TestHelper from '@test/test-helper'; - -const jsonSchema = require('@definitions/3.0.0/Reference.json'); - -describe('Reference', () => { - it('example is valid', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './example.json'), - )); - - it('can\'t be empty', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - ['must have required property \'$ref\''] - )); - - it('is not valid without required properties', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - ['must have required property \'$ref\''] - )); - - it('is valid with only required properties', () => () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './only required properties.json.json'), - )); - - it.skip('cannot be extended with valid extension names. add "additionalProperties": false', () => TestHelper.cantBeExtended( - jsonSchema, - path.resolve(__dirname, './extended.json'), - [ - 'x-number', - 'x-string', - 'x-object' - ] - )); - - it.skip('cannot be extended without valid extension names. add "additionalProperties": false', () => TestHelper.cantBeExtended( - jsonSchema, - path.resolve(__dirname, './wrongly extended.json'), - [ - 'x-number', - 'x-string', - 'x-object', - 'ext-number' - ] - )); -}); diff --git a/test/definitions/3.0.0/models/reference/reference/only required properties.json b/test/definitions/3.0.0/models/reference/reference/only required properties.json deleted file mode 100644 index fd5bb0d1..00000000 --- a/test/definitions/3.0.0/models/reference/reference/only required properties.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "$ref": "#/components/schemas/user" -} diff --git a/test/definitions/3.0.0/models/reference/reference/without required properties.json b/test/definitions/3.0.0/models/reference/reference/without required properties.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/reference/reference/without required properties.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/reference/reference/wrongly extended.json b/test/definitions/3.0.0/models/reference/reference/wrongly extended.json deleted file mode 100644 index 7981bdcc..00000000 --- a/test/definitions/3.0.0/models/reference/reference/wrongly extended.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$ref": "#/components/schemas/user", - "x-number": 0, - "x-string": "", - "x-object": { - "property": {} - }, - "ext-number": 1 -} diff --git a/test/definitions/3.0.0/models/server/index.mjs b/test/definitions/3.0.0/models/server/index.mjs deleted file mode 100644 index 845c2a6c..00000000 --- a/test/definitions/3.0.0/models/server/index.mjs +++ /dev/null @@ -1,6 +0,0 @@ -import {describe} from 'vitest'; - -describe('Server Test Suite', async () => { - await import('./server'); - await import('./serverVariable'); -}); diff --git a/test/definitions/3.0.0/models/server/server variable.test.mjs b/test/definitions/3.0.0/models/server/server variable.test.mjs new file mode 100644 index 00000000..2fcbde63 --- /dev/null +++ b/test/definitions/3.0.0/models/server/server variable.test.mjs @@ -0,0 +1,75 @@ +import {describe} from 'vitest'; +import { + JsonSchemaTestSuite, + JsonSchemaTestSuiteConfig, + JsonSchemaTestSuiteData +} from '@test/definitions/base-schema-test.mjs'; + +const jsonSchema = require('@definitions/3.0.0/serverVariable.json'); + +const config = new JsonSchemaTestSuiteConfig( + false, + [], + true, + [] +); + +const data = new JsonSchemaTestSuiteData( + jsonSchema, + [ + { + "enum": [ + "8883", + "8884" + ], + "default": "8883", + "description": "To which port connect", + "examples": [ + "8883", + "8884" + ] + } + ], + {}, + { + "enum": [ + "8883", + "8884" + ], + "default": "8883", + "description": "To which port connect", + "examples": [ + "8883", + "8884" + ] + }, + { + "enum": [ + "8883", + "8884" + ], + "default": "8883", + "description": "To which port connect", + "examples": [ + "8883", + "8884" + ], + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + } + }, + { + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + }, + "ext-number": 1 + } +); + +describe('Server Variable', () => { + new JsonSchemaTestSuite(data, config).testSuite() +}); \ No newline at end of file diff --git a/test/definitions/3.0.0/models/server/server.test.mjs b/test/definitions/3.0.0/models/server/server.test.mjs new file mode 100644 index 00000000..c064e0ac --- /dev/null +++ b/test/definitions/3.0.0/models/server/server.test.mjs @@ -0,0 +1,61 @@ +import {describe} from 'vitest'; +import { + JsonSchemaTestSuite, + JsonSchemaTestSuiteConfig, + JsonSchemaTestSuiteData +} from '@test/definitions/base-schema-test.mjs'; + +const jsonSchema = require('@definitions/3.0.0/server.json'); + +const config = new JsonSchemaTestSuiteConfig( + true, + [ + 'must have required property \'host\'', + 'must have required property \'protocol\'' + ], + true, + [] +); + +const data = new JsonSchemaTestSuiteData( + jsonSchema, + [ + { + "host": "rabbitmq.in.mycompany.com:5672", + "pathname": "/production", + "protocol": "amqp", + "description": "Production RabbitMQ broker (uses the `production` vhost)." + } + ], + { + "host": "rabbitmq.in.mycompany.com:5672", + "protocol": "amqp", + }, + { + "pathname": "/production", + "description": "Production RabbitMQ broker (uses the `production` vhost)." + }, + { + "host": "rabbitmq.in.mycompany.com:5672", + "protocol": "amqp", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + } + }, + { + "host": "rabbitmq.in.mycompany.com:5672", + "protocol": "amqp", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + }, + "ext-number": 1 + } +); + +describe('Server', () => { + new JsonSchemaTestSuite(data, config).testSuite() +}); \ No newline at end of file diff --git a/test/definitions/3.0.0/models/server/server/empty.json b/test/definitions/3.0.0/models/server/server/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/server/server/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/server/server/example.json b/test/definitions/3.0.0/models/server/server/example.json deleted file mode 100644 index a12232e7..00000000 --- a/test/definitions/3.0.0/models/server/server/example.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "host" : "{username}.gigantic-server.com:{port}/{basePath}", - "protocol" : "secure-mqtt", - "protocolVersion" : "5", - "pathname" : "/messages", - "description" : "The production API server", - "title" : "secure-mqtt API server", - "summary" : "API server", - "variables" : { - "username" : { - "description" : "This value is assigned by the service provider, in this example `gigantic-server.com`", - "examples" : null, - "enum" : null, - "default" : "demo" - }, - "port" : { - "description" : null, - "examples" : null, - "enum" : [ "8883", "8884" ], - "default" : "8883" - }, - "basePath" : { - "$ref" : "#/components/serverVariables/basePath" - } - }, - "security" : [ { - "type" : "apiKey", - "description" : "apiKey", - "in" : "user" - }, { - "type" : "http", - "description" : "http", - "scheme" : "bearer", - "bearerFormat" : "JWT" - } ], - "tags" : [ { - "name" : "env:staging", - "description" : "This environment is a replica of the production environment", - "externalDocs" : null - } ], - "externalDocs" : { - "description" : "Find more info here", - "url" : "https://example.com" - }, - "bindings" : { - "amqp" : { - "$ref" : "#/components/serverBindings/amqp" - }, - "amqp1" : { }, - "anypointmq" : { }, - "googlepubsub" : { }, - "http" : { }, - "ibmmq" : { - "groupId" : "PRODCLSTR1", - "ccdtQueueManagerName" : "*", - "cipherSpec" : "ANY_TLS12_OR_HIGHER", - "multiEndpointServer" : false, - "heartBeatInterval" : 300, - "bindingVersion" : "0.1.0" - }, - "jms" : { }, - "kafka" : { - "schemaRegistryUrl" : "https://my-schema-registry.com", - "schemaRegistryVendor" : "confluent", - "bindingVersion" : "0.5.0" - }, - "mercure" : { }, - "mqtt" : { - "clientId" : "guest", - "cleanSession" : true, - "lastWill" : { - "topic" : "/last-wills", - "qos" : 2, - "message" : "Guest gone offline.", - "retain" : false - }, - "keepAlive" : 60, - "bindingVersion" : "0.1.0" - }, - "mqtt5" : { - "sessionExpiryInterval" : 60, - "bindingVersion" : "0.2.0" - }, - "nats" : { }, - "pulsar" : { - "tenant" : "contoso", - "bindingVersion" : "0.1.0" - }, - "redis" : { }, - "sns" : { }, - "solace" : { - "clientName": "transactions-broker", - "msgVpn": "ProdVPN", - "bindingVersion": "0.4.0" - }, - "sqs" : { }, - "stomp" : { }, - "ws" : { } - } -} diff --git a/test/definitions/3.0.0/models/server/server/index.mjs b/test/definitions/3.0.0/models/server/server/index.mjs deleted file mode 100644 index 86acf8c6..00000000 --- a/test/definitions/3.0.0/models/server/server/index.mjs +++ /dev/null @@ -1,45 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@definitions/3.0.0/server.json'); - -describe(`Server`, () => { - it.skip('example is valid. Reason: errors with bindings, external docs, ...', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './example.json'), - )); - - it('cannot be empty', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - [ - 'must have required property \'host\'', - 'must have required property \'protocol\'' - ] - )); - - it.skip('is not valid without required properties. Reason: errors with bindings, external docs, ...', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - [ - 'must have required property \'host\'', - 'must have required property \'protocol\'' - ] - )); - - it('is valid with only required properties', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './only required properties.json'), - )); - - it.skip('extended. Reason: schema doesn\'t check for extensions', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, '../../../extended.json') - )); - - it.skip('wrongly extended. Reason: schema doesn\'t check for extensions', () => TestHelper.wronglyExtended( - jsonSchema, - path.resolve(__dirname, '../../../../wrongly extended.json') - )); -}); diff --git a/test/definitions/3.0.0/models/server/server/only required properties.json b/test/definitions/3.0.0/models/server/server/only required properties.json deleted file mode 100644 index 91e9a02f..00000000 --- a/test/definitions/3.0.0/models/server/server/only required properties.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "host": "dev.env.lo", - "protocol": "mqtt" -} diff --git a/test/definitions/3.0.0/models/server/server/without required properties.json b/test/definitions/3.0.0/models/server/server/without required properties.json deleted file mode 100644 index a12232e7..00000000 --- a/test/definitions/3.0.0/models/server/server/without required properties.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "host" : "{username}.gigantic-server.com:{port}/{basePath}", - "protocol" : "secure-mqtt", - "protocolVersion" : "5", - "pathname" : "/messages", - "description" : "The production API server", - "title" : "secure-mqtt API server", - "summary" : "API server", - "variables" : { - "username" : { - "description" : "This value is assigned by the service provider, in this example `gigantic-server.com`", - "examples" : null, - "enum" : null, - "default" : "demo" - }, - "port" : { - "description" : null, - "examples" : null, - "enum" : [ "8883", "8884" ], - "default" : "8883" - }, - "basePath" : { - "$ref" : "#/components/serverVariables/basePath" - } - }, - "security" : [ { - "type" : "apiKey", - "description" : "apiKey", - "in" : "user" - }, { - "type" : "http", - "description" : "http", - "scheme" : "bearer", - "bearerFormat" : "JWT" - } ], - "tags" : [ { - "name" : "env:staging", - "description" : "This environment is a replica of the production environment", - "externalDocs" : null - } ], - "externalDocs" : { - "description" : "Find more info here", - "url" : "https://example.com" - }, - "bindings" : { - "amqp" : { - "$ref" : "#/components/serverBindings/amqp" - }, - "amqp1" : { }, - "anypointmq" : { }, - "googlepubsub" : { }, - "http" : { }, - "ibmmq" : { - "groupId" : "PRODCLSTR1", - "ccdtQueueManagerName" : "*", - "cipherSpec" : "ANY_TLS12_OR_HIGHER", - "multiEndpointServer" : false, - "heartBeatInterval" : 300, - "bindingVersion" : "0.1.0" - }, - "jms" : { }, - "kafka" : { - "schemaRegistryUrl" : "https://my-schema-registry.com", - "schemaRegistryVendor" : "confluent", - "bindingVersion" : "0.5.0" - }, - "mercure" : { }, - "mqtt" : { - "clientId" : "guest", - "cleanSession" : true, - "lastWill" : { - "topic" : "/last-wills", - "qos" : 2, - "message" : "Guest gone offline.", - "retain" : false - }, - "keepAlive" : 60, - "bindingVersion" : "0.1.0" - }, - "mqtt5" : { - "sessionExpiryInterval" : 60, - "bindingVersion" : "0.2.0" - }, - "nats" : { }, - "pulsar" : { - "tenant" : "contoso", - "bindingVersion" : "0.1.0" - }, - "redis" : { }, - "sns" : { }, - "solace" : { - "clientName": "transactions-broker", - "msgVpn": "ProdVPN", - "bindingVersion": "0.4.0" - }, - "sqs" : { }, - "stomp" : { }, - "ws" : { } - } -} diff --git a/test/definitions/3.0.0/models/server/serverVariable/empty.json b/test/definitions/3.0.0/models/server/serverVariable/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/server/serverVariable/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/server/serverVariable/example.json b/test/definitions/3.0.0/models/server/serverVariable/example.json deleted file mode 100644 index f4dfc461..00000000 --- a/test/definitions/3.0.0/models/server/serverVariable/example.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "enum": [ - "8883", - "8884" - ], - "default": "8883", - "description": "To which port connect", - "examples": [ - "8883", - "8884" - ] -} diff --git a/test/definitions/3.0.0/models/server/serverVariable/extended.json b/test/definitions/3.0.0/models/server/serverVariable/extended.json deleted file mode 100644 index 95e1f7e2..00000000 --- a/test/definitions/3.0.0/models/server/serverVariable/extended.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "enum": [ - "8883", - "8884" - ], - "default": "8883", - "description": "To which port connect", - "examples": [ - "8883", - "8884" - ], - "x-number": 0, - "x-string": "", - "x-object": { - "property": {} - } -} diff --git a/test/definitions/3.0.0/models/server/serverVariable/index.mjs b/test/definitions/3.0.0/models/server/serverVariable/index.mjs deleted file mode 100644 index 75a7dd95..00000000 --- a/test/definitions/3.0.0/models/server/serverVariable/index.mjs +++ /dev/null @@ -1,37 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@definitions/3.0.0/serverVariable.json'); - -describe('Server Variable', () => { - it('example is valid', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './example.json'), - )); - - it('can be empty', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - )); - - it('is valid without required properties', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - )); - - it('is valid with only required properties', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './only required properties.json'), - )); - - it('is valid when is extended', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, '../../../../extended.json') - )); - - it('is not valid when is wrongly extended', () => TestHelper.wronglyExtended( - jsonSchema, - path.resolve(__dirname, '../../../../wrongly extended.json') - )); -}); diff --git a/test/definitions/3.0.0/models/server/serverVariable/only required properties.json b/test/definitions/3.0.0/models/server/serverVariable/only required properties.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/server/serverVariable/only required properties.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/server/serverVariable/without required properties.json b/test/definitions/3.0.0/models/server/serverVariable/without required properties.json deleted file mode 100644 index f4dfc461..00000000 --- a/test/definitions/3.0.0/models/server/serverVariable/without required properties.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "enum": [ - "8883", - "8884" - ], - "default": "8883", - "description": "To which port connect", - "examples": [ - "8883", - "8884" - ] -} diff --git a/test/definitions/3.0.0/models/tag/empty.json b/test/definitions/3.0.0/models/tag/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/tag/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/tag/example.json b/test/definitions/3.0.0/models/tag/example.json deleted file mode 100644 index aa06e030..00000000 --- a/test/definitions/3.0.0/models/tag/example.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "user", - "description": "User-related messages", - "externalDocs": { - "description" : "Find more info here", - "url" : "https://example.com" - } -} diff --git a/test/definitions/3.0.0/models/tag/extended.json b/test/definitions/3.0.0/models/tag/extended.json deleted file mode 100644 index 52ba185f..00000000 --- a/test/definitions/3.0.0/models/tag/extended.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "user", - "x-number": 0, - "x-string": "", - "x-object": { - "property": {} - } -} diff --git a/test/definitions/3.0.0/models/tag/index.mjs b/test/definitions/3.0.0/models/tag/index.mjs deleted file mode 100644 index 44cc8026..00000000 --- a/test/definitions/3.0.0/models/tag/index.mjs +++ /dev/null @@ -1,39 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@definitions/3.0.0/tag.json'); - -describe('Tag', () => { - it('example is valid', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './example.json'), - )); - - it('cannot be empty', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - ['must have required property \'name\''] - )); - - it('is not valid without required properties', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - ['must have required property \'name\''] - )); - - it('is valid with only required properties', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './only required properties.json') - )); - - it('is valid when is extended', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './extended.json') - )); - - it('is not valid when is wrongly extended', () => TestHelper.wronglyExtended( - jsonSchema, - path.resolve(__dirname, './wrongly extended.json') - )); -}); diff --git a/test/definitions/3.0.0/models/tag/only required properties.json b/test/definitions/3.0.0/models/tag/only required properties.json deleted file mode 100644 index 20347ed0..00000000 --- a/test/definitions/3.0.0/models/tag/only required properties.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "user" -} diff --git a/test/definitions/3.0.0/models/tag/tag.test.mjs b/test/definitions/3.0.0/models/tag/tag.test.mjs new file mode 100644 index 00000000..b4ba0fd5 --- /dev/null +++ b/test/definitions/3.0.0/models/tag/tag.test.mjs @@ -0,0 +1,60 @@ +import {describe} from 'vitest'; +import { + JsonSchemaTestSuite, + JsonSchemaTestSuiteConfig, + JsonSchemaTestSuiteData +} from '@test/definitions/base-schema-test.mjs'; + +const jsonSchema = require('@definitions/3.0.0/tag.json'); + +const config = new JsonSchemaTestSuiteConfig( + true, + ['must have required property \'name\''], + true, + [] +); + +const data = new JsonSchemaTestSuiteData( + jsonSchema, + [ + { + "name": "user", + "description": "User-related messages", + "externalDocs": { + "description" : "Find more info here", + "url" : "https://example.com" + } + } + ], + { + "name": "user" + }, + { + "description": "User-related messages", + "externalDocs": { + "description" : "Find more info here", + "url" : "https://example.com" + } + }, + { + "name": "user", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + } + }, + { + "name": "user", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + }, + "ext-number": 1 + } +); + +describe('Tag', () => { + new JsonSchemaTestSuite(data, config).testSuite() +}); \ No newline at end of file diff --git a/test/definitions/3.0.0/models/tag/without required properties.json b/test/definitions/3.0.0/models/tag/without required properties.json deleted file mode 100644 index f3f99eda..00000000 --- a/test/definitions/3.0.0/models/tag/without required properties.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "description": "User-related messages", - "externalDocs": { - "description" : "Find more info here", - "url" : "https://example.com" - } -} diff --git a/test/definitions/3.0.0/models/tag/wrongly extended.json b/test/definitions/3.0.0/models/tag/wrongly extended.json deleted file mode 100644 index 9886a13d..00000000 --- a/test/definitions/3.0.0/models/tag/wrongly extended.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "user", - "x-number": 0, - "x-string": "", - "x-object": { - "property": {} - }, - "ext-number": 1 -}