Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu committed Nov 2, 2022
1 parent ce78737 commit ae7edf3
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 180 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

# The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.

* @fmvilas @jstoiko @asyncapi-bot-eve
* @fmvilas @jstoiko @magicmatatjahu @asyncapi-bot-eve
35 changes: 0 additions & 35 deletions index.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ const r2j = require('ramldt2jsonschema');
import type { SchemaParser, ParseSchemaInput, ValidateSchemaInput, SchemaValidateResult } from '@asyncapi/parser';
import type { v2 } from '@asyncapi/parser/esm/spec-types';

export function RamlSchemaParser(): SchemaParser {
export function RamlDTSchemaParser(): SchemaParser {
return {
validate,
parse,
getMimeTypes,
};
}
export default RamlDTSchemaParser;

async function validate(input: ValidateSchemaInput<unknown, unknown>): Promise<SchemaValidateResult[]> {
const payload = formatPayload(input.data);
Expand Down
111 changes: 0 additions & 111 deletions test/complex_cat.raml

This file was deleted.

90 changes: 90 additions & 0 deletions test/documents/complex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"schemaFormat": "application/raml+yaml;version=1.0",
"payload":
{
"type":
[
"CatWithAddress",
"CatWithCity"
],
"minProperties": 1,
"maxProperties": 50,
"additionalProperties": false,
"discriminator": "breed",
"discriminatorValue": "CatOne",
"properties":
{
"proscons":
{
"type": "CatPros | CatCons",
"required": true
},
"name":
{
"type": "CatName",
"amazing": true
},
"breed":
{
"type": "CatBreed"
},
"age": "CatAge",
"rating":
{
"type": "integer",
"multipleOf": 5,
"example":
{
"displayName": "Cat's rating",
"description": "Rating of cat's awesomeness",
"strict": false,
"value": 50
}
},
"year_of_birth": "date-only",
"time_of_birth": "time-only",
"dt_of_birth":
{
"type": "datetime-only",
"required": false
},
"addition_date":
{
"type": "datetime",
"format": "rfc2616"
},
"removal_date":
{
"type": "datetime"
},
"photo":
{
"type": "file",
"fileTypes":
[
"image/jpeg",
"image/png"
],
"minLength": 1,
"maxLength": 307200
},
"description": "nil",
"habits?": "string",
"character": "nil | string",
"siblings": "string[]",
"parents": "CatName[]",
"ratingHistory": "(integer | number)[]",
"additionalData":
{
"type":
{
"type": "object",
"properties":
{
"weight": "number"
}
}
}
}
}
}
22 changes: 22 additions & 0 deletions test/documents/invalid-asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
asyncapi: 2.4.0
info:
title: My API
version: '1.0.0'

channels:
myChannel:
publish:
message:
$ref: '#/components/messages/testMessage'

components:
messages:
testMessage:
schemaFormat: application/raml+yaml;version=1.0
payload:
type: object
properties:
title: string
author:
type: string
examples: test
13 changes: 13 additions & 0 deletions test/documents/invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"schemaFormat": "application/raml+yaml;version=1.0",
"payload": {
"type": "object",
"properties": {
"title": "string",
"author": {
"type": "string",
"examples": "test"
}
}
}
}
21 changes: 21 additions & 0 deletions test/documents/simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"schemaFormat": "application/raml+yaml;version=1.0",
"payload": {
"type": "object",
"properties": {
"title": "string",
"author": {
"type": "string",
"examples": {
"anExample": "Eva"
}
}
},
"examples": {
"exampleOne": {
"title": "A book",
"author": "An author"
}
}
}
}
17 changes: 6 additions & 11 deletions test/asyncapi-raml.yaml → test/documents/valid-asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
asyncapi: 2.0.0
asyncapi: 2.4.0
info:
title: Example using RAML data types
title: My API
version: '1.0.0'

channels:
mychannel:
myChannel:
publish:
message:
$ref: '#/components/messages/testMessage'
otherchannel:
subscribe:
message:
schemaFormat: 'application/raml+yaml;version=1.0'
payload:
$ref: 'complex_cat.raml#/types/Cat'

components:
messages:
testMessage:
schemaFormat: 'application/raml+yaml;version=1.0'
schemaFormat: application/raml+yaml;version=1.0
payload:
type: object
properties:
Expand All @@ -29,4 +24,4 @@ components:
examples:
exampleOne:
title: A book
author: An author
author: An author
21 changes: 0 additions & 21 deletions test/parse_test.js

This file was deleted.

Loading

0 comments on commit ae7edf3

Please sign in to comment.