Skip to content

Commit e951de2

Browse files
committed
update tests
1 parent 7170c90 commit e951de2

File tree

4 files changed

+113
-2
lines changed

4 files changed

+113
-2
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"type": "object",
3+
"additionalProperties": false,
4+
"required": [
5+
"clientId",
6+
"contact",
7+
"credentials"
8+
],
9+
"properties": {
10+
"contact": {
11+
"$id": "https: //json.schemastore.org/bungee-plugin",
12+
"$schema": "http: //json-schema.org/draft-07/schema#",
13+
"additionalProperties": true,
14+
"definitions": {
15+
"plugin-name": {
16+
"type": "string",
17+
"pattern": "^[A-Za-z0-9_\\.-]+$"
18+
}
19+
},
20+
"properties": {
21+
"name": {
22+
"description": "The name of the plugin.",
23+
"type": "string",
24+
"pattern": "^[A-Za-z0-9_\\.-]+$"
25+
},
26+
"main": {
27+
"description": "Plugin main class.",
28+
"type": "string",
29+
"pattern": "^([a-zA-Z_$][a-zA-Z\\d_$]*\\.)*[a-zA-Z_$][a-zA-Z\\d_$]*$"
30+
},
31+
"version": {
32+
"description": "Plugin version.",
33+
"type": "string"
34+
},
35+
"author": {
36+
"description": "Plugin author.",
37+
"type": "string"
38+
},
39+
"depends": {
40+
"description": "Plugin hard dependencies.",
41+
"type": "array",
42+
"items": {
43+
"type": "string",
44+
"pattern": "^[A-Za-z0-9_\\.-]+$"
45+
}
46+
},
47+
"softDepends": {
48+
"description": "Plugin soft dependencies.",
49+
"type": "array",
50+
"items": {
51+
"type": "string",
52+
"pattern": "^[A-Za-z0-9_\\.-]+$"
53+
}
54+
},
55+
"description": {
56+
"description": "Optional description.",
57+
"type": "string"
58+
}
59+
},
60+
"required": [
61+
"name",
62+
"main"
63+
],
64+
"title": "JSON schema for BungeeCord Plugin YAML",
65+
"type": "object"
66+
},
67+
"clientId": {
68+
"type": "string"
69+
},
70+
"credentials": {
71+
"type": "object",
72+
"additionalProperties": false,
73+
"properties": {
74+
"username": {
75+
"type": "string",
76+
"example": "user@example.com"
77+
},
78+
"password": {
79+
"type": "string"
80+
},
81+
"callbackURL": {
82+
"type": "string",
83+
"example": "http: //www.xyz.com"
84+
}
85+
}
86+
}
87+
}
88+
}

test/src/Convertor.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const complexTypeArraySchema = require('../schemas/complex-typeArray')
2424
const complexDefaultValuesSchema = require('../schemas/complex-defaultValues')
2525
const complexAdditionalPropertiesSchema = require('../schemas/complex-additionalProperties')
2626
const complexItemsAsArraySchema = require('../schemas/complex-itemsAsArray')
27+
const complexEmbeddedDefinitionsSchema = require('../schemas/complex-embeddedDefinitions')
2728

2829
const simpleOpenAPI = require('../openAPI/simple')
2930

@@ -47,6 +48,7 @@ describe('Convertor', () => {
4748
delete require.cache[require.resolve('../schemas/complex-defaultValues')];
4849
delete require.cache[require.resolve('../schemas/complex-additionalProperties')];
4950
delete require.cache[require.resolve('../schemas/complex-itemsAsArray')];
51+
delete require.cache[require.resolve('../schemas/complex-embeddedDefinitions')];
5052
convertor = new Convertor(simpleSchema)
5153
});
5254

@@ -359,6 +361,27 @@ describe('Convertor', () => {
359361
})
360362
expect(valid).to.be.true
361363
});
364+
365+
it('should return a schema valid for OpenAPI v3.0.0 when definitions are deeply embedded', async function() {
366+
const complexConvertor = new Convertor(complexEmbeddedDefinitionsSchema)
367+
const components = complexConvertor.convert()
368+
const cloned = JSON.parse(JSON.stringify(simpleOpenAPI))
369+
let valid = await validator.validateInner(cloned, {})
370+
expect(valid).to.be.true
371+
Object.assign(cloned, {components})
372+
expect(cloned).to.have.property('components')
373+
expect(cloned.components).to.have.property('schemas')
374+
expect(cloned.components.schemas).to.have.property('main')
375+
expect(cloned.components.schemas.main.properties).to.have.property('contact')
376+
expect(cloned.components.schemas.main.properties.contact).to.not.have.property('definitions')
377+
expect(cloned.components.schemas.main.properties).to.have.property('clientId')
378+
expect(cloned.components.schemas.main.properties).to.have.property('credentials')
379+
valid = await validator.validateInner(cloned, {})
380+
.catch(err => {
381+
console.log(err)
382+
})
383+
expect(valid).to.be.true
384+
});
362385
});
363386

364387
describe('convert a schema that has definitions that have already been resolved', () => {

test/src/Factory.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ describe('Factory', () => {
2929
expect(expected.schemas).to.have.property('message')
3030
});
3131
});
32-
});
32+
});

test/src/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ describe('index', () => {
2929
expect(expected.schemas).to.have.property('message')
3030
});
3131
});
32-
});
32+
});

0 commit comments

Comments
 (0)