[json] rename server/src/tests to test

This commit is contained in:
Martin Aeschlimann
2016-01-21 22:49:05 +01:00
parent 078ac32d73
commit ea0e5bbae7
16 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,448 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import Parser = require('../jsonParser');
import SchemaService = require('../jsonSchemaService');
import JsonSchema = require('../json-toolbox/jsonSchema');
import {JSONCompletion} from '../jsonCompletion';
import {IXHROptions, IXHRResponse} from '../utils/httpRequest';
import {create as createLinesModel} from '../utils/lines';
import {CompletionItem, CompletionItemKind, CompletionOptions, ITextDocument, TextDocumentIdentifier, TextDocumentPosition, Range, Position, TextEdit} from 'vscode-languageserver';
suite('JSON Completion', () => {
var requestService = function(options: IXHROptions): Promise<IXHRResponse> {
return Promise.reject<IXHRResponse>({ responseText: '', status: 404 });
}
var assertSuggestion = function(completions: CompletionItem[], label: string, documentation?: string) {
var matches = completions.filter(function(completion: CompletionItem) {
return completion.label === label && (!documentation || completion.documentation === documentation);
}).length;
assert.equal(matches, 1, label + " should only existing once");
};
var testSuggestionsFor = function(value: string, stringAfter: string, schema?: JsonSchema.IJSONSchema): Promise<CompletionItem[]> {
var uri = 'test://test.json';
var idx = stringAfter ? value.indexOf(stringAfter) : 0;
var schemaService = new SchemaService.JSONSchemaService(requestService);
var completionProvider = new JSONCompletion(schemaService);
if (schema) {
var id = "http://myschemastore/test1";
schemaService.registerExternalSchema(id, ["*.json"], schema);
}
var document = {
getText: () => value,
uri: uri
}
var textDocumentLocation = TextDocumentPosition.create(uri, Position.create(0, idx));
var lines = createLinesModel(value);
var jsonDoc = Parser.parse(value);
return completionProvider.doSuggest(document, textDocumentLocation, lines, jsonDoc);
};
test('Complete keys no schema', function(testDone) {
Promise.all([
testSuggestionsFor('[ { "name": "John", "age": 44 }, { /**/ }', '/**/').then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'name');
assertSuggestion(result, 'age');
}),
testSuggestionsFor('[ { "name": "John", "age": 44 }, { "/**/ }', '/**/').then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'name');
assertSuggestion(result, 'age');
}),
testSuggestionsFor('[ { "name": "John", "age": 44 }, { "n/**/ }', '/**/').then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'name');
}),
testSuggestionsFor('[ { "name": "John", "age": 44 }, { "name/**/" }', '/**/').then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'name');
}),
testSuggestionsFor('[ { "name": "John", "address": { "street" : "MH Road", "number" : 5 } }, { "name": "Jack", "address": { "street" : "100 Feet Road", /**/ }', '/**/').then((result) => {
assert.strictEqual(result.length, 1);
assertSuggestion(result, 'number');
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Complete values no schema', function(testDone) {
Promise.all([
testSuggestionsFor('[ { "name": "John", "age": 44 }, { "name": /**/', '/**/').then((result) => {
assert.strictEqual(result.length, 1);
assertSuggestion(result, '"John"');
}),
testSuggestionsFor('[ { "data": { "key": 1, "data": true } }, { "data": /**/', '/**/').then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, '{}');
assertSuggestion(result, 'true');
assertSuggestion(result, 'false');
}),
testSuggestionsFor('[ { "data": "foo" }, { "data": "bar" }, { "data": "/**/" } ]', '/**/').then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, '"foo"');
assertSuggestion(result, '"bar"');
assertSuggestion(result, '"/**/"');
}),
testSuggestionsFor('[ { "data": "foo" }, { "data": "bar" }, { "data": "f/**/" } ]', '/**/').then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, '"foo"');
assertSuggestion(result, '"bar"');
assertSuggestion(result, '"f/**/"');
}),
testSuggestionsFor('[ { "data": "foo" }, { "data": "bar" }, { "data": "xoo"/**/ } ]', '/**/').then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, '"xoo"');
}),
testSuggestionsFor('[ { "data": "foo" }, { "data": "bar" }, { "data": "xoo" /**/ } ]', '/**/').then((result) => {
assert.strictEqual(result.length, 0);
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Complete keys with schema', function(testDone) {
var schema: JsonSchema.IJSONSchema = {
type: 'object',
properties: {
'a': {
type: 'number',
description: 'A'
},
'b': {
type: 'string',
description: 'B'
},
'c': {
type: 'boolean',
description: 'C'
}
}
};
Promise.all([
testSuggestionsFor('{/**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, 'a', 'A');
assertSuggestion(result, 'b', 'B');
assertSuggestion(result, 'c', 'C');
}),
testSuggestionsFor('{ "/**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, 'a', 'A');
assertSuggestion(result, 'b', 'B');
assertSuggestion(result, 'c', 'C');
}),
testSuggestionsFor('{ "a/**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, 'a', 'A');
}),
testSuggestionsFor('{ "a" = 1;/**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'b', 'B');
assertSuggestion(result, 'c', 'C');
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Complete value with schema', function(testDone) {
var schema: JsonSchema.IJSONSchema = {
type: 'object',
properties: {
'a': {
enum: ['John', 'Jeff', 'George']
}
}
};
Promise.all([
testSuggestionsFor('{ "a": /**/ }', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, '"John"');
assertSuggestion(result, '"Jeff"');
assertSuggestion(result, '"George"');
}),
testSuggestionsFor('{ "a": "J/**/ }', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, '"John"');
assertSuggestion(result, '"Jeff"');
}),
testSuggestionsFor('{ "a": "John"/**/ }', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, '"John"');
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Complete with nested schema', function(testDone) {
var content = '{/**/}';
var schema: JsonSchema.IJSONSchema = {
oneOf: [{
type: 'object',
properties: {
'a': {
type: 'number',
description: 'A'
},
'b': {
type: 'string',
description: 'B'
},
}
}, {
type: 'array'
}]
};
Promise.all([
testSuggestionsFor(content, '/**/', schema).then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'a', 'A');
assertSuggestion(result, 'b', 'B');
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Complete with required anyOf', function(testDone) {
var schema: JsonSchema.IJSONSchema = {
anyOf: [{
type: 'object',
required: ['a', 'b'],
properties: {
'a': {
type: 'string',
description: 'A'
},
'b': {
type: 'string',
description: 'B'
},
}
}, {
type: 'object',
required: ['c', 'd'],
properties: {
'c': {
type: 'string',
description: 'C'
},
'd': {
type: 'string',
description: 'D'
},
}
}]
};
Promise.all([
testSuggestionsFor('{/**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 4);
assertSuggestion(result, 'a', 'A');
assertSuggestion(result, 'b', 'B');
assertSuggestion(result, 'c', 'C');
assertSuggestion(result, 'd', 'D');
}),
testSuggestionsFor('{ "a": "", /**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 1);
assertSuggestion(result, 'b', 'B');
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Complete with anyOf', function(testDone) {
var schema: JsonSchema.IJSONSchema = {
anyOf: [{
type: 'object',
properties: {
'type': {
enum: ['house']
},
'b': {
type: 'string'
},
}
}, {
type: 'object',
properties: {
'type': {
enum: ['appartment']
},
'c': {
type: 'string'
},
}
}]
};
Promise.all([
testSuggestionsFor('{/**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, 'type');
assertSuggestion(result, 'b');
assertSuggestion(result, 'c');
}),
testSuggestionsFor('{ "type": "appartment", /**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 1);
assertSuggestion(result, 'c');
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Complete with oneOf', function(testDone) {
var schema: JsonSchema.IJSONSchema = {
oneOf: [{
type: 'object',
allOf: [{
properties: {
'a': {
type: 'string',
description: 'A'
}
}
},
{
anyOf: [{
properties: {
'b1': {
type: 'string',
description: 'B1'
}
},
}, {
properties: {
'b2': {
type: 'string',
description: 'B2'
}
},
}]
}]
}, {
type: 'object',
properties: {
'c': {
type: 'string',
description: 'C'
},
'd': {
type: 'string',
description: 'D'
},
}
}]
};
Promise.all([
testSuggestionsFor('{/**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 5);
assertSuggestion(result, 'a', 'A');
assertSuggestion(result, 'b1', 'B1');
assertSuggestion(result, 'b2', 'B2');
assertSuggestion(result, 'c', 'C');
assertSuggestion(result, 'd', 'D');
}),
testSuggestionsFor('{ "b1": "", /**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'a', 'A');
assertSuggestion(result, 'b2', 'B2');
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Complete with oneOf and enums', function(testDone) {
var schema: JsonSchema.IJSONSchema = {
oneOf: [{
type: 'object',
properties: {
'type': {
type: 'string',
enum: ['1', '2']
},
'a': {
type: 'object',
properties: {
'x': {
type: 'string'
},
'y': {
type: 'string'
}
},
"required": ['x', 'y']
},
'b': {}
},
}, {
type: 'object',
properties: {
'type': {
type: 'string',
enum: ['3']
},
'a': {
type: 'object',
properties: {
'x': {
type: 'string'
},
'z': {
type: 'string'
}
},
"required": ['x', 'z']
},
'c': {}
},
}]
};
Promise.all([
testSuggestionsFor('{/**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 4);
assertSuggestion(result, 'type');
assertSuggestion(result, 'a');
assertSuggestion(result, 'b');
assertSuggestion(result, 'c');
}),
testSuggestionsFor('{ "type": /**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 3);
assertSuggestion(result, '"1"');
assertSuggestion(result, '"2"');
assertSuggestion(result, '"3"');
}),
testSuggestionsFor('{ "a": { "x": "", "y": "" }, "type": /**/}', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, '"1"');
assertSuggestion(result, '"2"');
}),
testSuggestionsFor('{ "type": "1", "a" : { /**/ }', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'x');
assertSuggestion(result, 'y');
}),
testSuggestionsFor('{ "type": "1", "a" : { "x": "", "z":"" }, /**/', '/**/', schema).then((result) => {
// both alternatives have errors: intellisense proposes all options
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'b');
assertSuggestion(result, 'c');
}),
testSuggestionsFor('{ "a" : { "x": "", "z":"" }, /**/', '/**/', schema).then((result) => {
assert.strictEqual(result.length, 2);
assertSuggestion(result, 'type');
assertSuggestion(result, 'c');
}),
]).then(() => testDone(), (error) => testDone(error));
});
});

View File

@@ -0,0 +1,102 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import Parser = require('../jsonParser');
import SchemaService = require('../jsonSchemaService');
import JsonSchema = require('../json-toolbox/jsonSchema');
import {JSONCompletion} from '../jsonCompletion';
import {IXHROptions, IXHRResponse} from '../utils/httpRequest';
import {create as createLinesModel} from '../utils/lines';
import {JSONDocumentSymbols} from '../jsonDocumentSymbols';
import {SymbolInformation, SymbolKind, TextDocumentIdentifier, TextDocumentPosition, Range, Position, TextEdit} from 'vscode-languageserver';
suite('JSON Document Symbols', () => {
function getOutline(value: string): Promise<SymbolInformation[]> {
var uri = 'test://test.json';
var symbolProvider = new JSONDocumentSymbols();
var document = {
getText: () => value,
uri: uri
}
var lines = createLinesModel(value);
var jsonDoc = Parser.parse(value);
return symbolProvider.compute(document, lines, jsonDoc);
}
var assertOutline: any = function(actual: SymbolInformation[], expected: any[], message: string) {
assert.equal(actual.length, expected.length, message);
for (var i = 0; i < expected.length; i++) {
assert.equal(actual[i].name, expected[i].label, message);
assert.equal(actual[i].kind, expected[i].kind, message);
}
};
test('Base types', function(testDone) {
var content = '{ "key1": 1, "key2": "foo", "key3" : true }';
var expected = [
{ label: 'key1', kind: SymbolKind.Number },
{ label: 'key2', kind: SymbolKind.String },
{ label: 'key3', kind: SymbolKind.Boolean },
];
getOutline(content).then((entries: SymbolInformation[]) => {
assertOutline(entries, expected);
}).then(() => testDone(), (error) => testDone(error));
});
test('Arrays', function(testDone) {
var content = '{ "key1": 1, "key2": [ 1, 2, 3 ], "key3" : [ { "k1": 1 }, {"k2": 2 } ] }';
var expected = [
{ label: 'key1', kind: SymbolKind.Number },
{ label: 'key2', kind: SymbolKind.Array },
{ label: 'key3', kind: SymbolKind.Array },
{ label: 'k1', kind: SymbolKind.Number },
{ label: 'k2', kind: SymbolKind.Number }
];
getOutline(content).then((entries: SymbolInformation[]) => {
assertOutline(entries, expected);
}).then(() => testDone(), (error) => testDone(error));
});
test('Objects', function(testDone) {
var content = '{ "key1": { "key2": true }, "key3" : { "k1": { } }';
var expected = [
{ label: 'key1', kind: SymbolKind.Module },
{ label: 'key2', kind: SymbolKind.Boolean },
{ label: 'key3', kind: SymbolKind.Module },
{ label: 'k1', kind: SymbolKind.Module }
];
getOutline(content).then((entries: SymbolInformation[]) => {
assertOutline(entries, expected);
}).then(() => testDone(), (error) => testDone(error));
});
test('Outline - object with syntax error', function(testDone) {
var content = '{ "key1": { "key2": true, "key3":, "key4": false } }';
var expected = [
{ label: 'key1', kind: SymbolKind.Module },
{ label: 'key2', kind: SymbolKind.Boolean },
{ label: 'key4', kind: SymbolKind.Boolean },
];
getOutline(content).then((entries: SymbolInformation[]) => {
assertOutline(entries, expected);
}).then(() => testDone(), (error) => testDone(error));
});
});

View File

@@ -0,0 +1,62 @@
{
"id": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Authorization.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Microsoft.Authorization",
"description": "Microsoft Microsoft.Authorization Resource Types",
"definitions": {
"locks": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Authorization/locks"
]
},
"apiVersion": {
"enum": [
"2015-01-01"
]
},
"name": {
"type": "string",
"maxLength": 64,
"description": "Name of the lock"
},
"dependsOn": {
"type": "array",
"items": {
"type": "string"
},
"description": "Collection of resources this resource depends on"
},
"properties": {
"type": "object",
"properties": {
"level": {
"enum": [
"CannotDelete",
"ReadOnly"
],
"description": "Microsoft.Authorization/locks: level - specifies the type of lock to apply to the scope. CanNotDelete allows modification but prevents deletion, ReadOnly prevents modification or deletion."
},
"notes": {
"type": "string",
"maxLength": 512,
"description": "Microsoft.Authorization/locks: notes - user defined notes for the lock"
}
},
"required": [
"level"
]
}
},
"required": [
"name",
"type",
"apiVersion",
"properties"
],
"description": "Microsoft.Authorization/locks resource"
}
}
}

View File

@@ -0,0 +1,835 @@
{
"id": "http://schema.management.azure.com/schemas/2015-08-01/Microsoft.Compute.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Microsoft.Compute",
"description": "Microsoft Compute Resource Types",
"resourceDefinitions": {
"availabilitySets": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Compute/availabilitySets"
]
},
"apiVersion": {
"enum": [
"2015-05-01-preview",
"2015-06-15"
]
},
"properties": {
"type": "object",
"properties": {
"platformUpdateDomainCount": {
"type": "number"
},
"platformFaultDomainCount": {
"type": "number"
}
}
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"virtualMachines": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Compute/virtualMachines"
]
},
"apiVersion": {
"enum": [
"2015-05-01-preview",
"2015-06-15"
]
},
"properties": {
"properties": {
"availabilitySet": {
"$ref": "#/definitions/id"
},
"hardwareProfile": {
"$ref": "#/definitions/hardwareProfile"
},
"storageProfile": {
"$ref": "#/definitions/storageProfile"
},
"osProfile": {
"$ref": "#/definitions/osProfile"
},
"networkProfile": {
"$ref": "#/definitions/networkProfile"
}
},
"type": "object",
"required": [
"hardwareProfile",
"storageProfile",
"networkProfile"
]
},
"resources": {
"type": "array",
"items": {
"allOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/resourceBase"
},
{
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Authorization.json#/definitions/locks"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json#/definitions/links"
},
{
"$ref": "#/resourceDefinitions/extensionsChild"
}
]
}
]
},
"description": "Microsoft.Compute/virtualMachines: Resource Definition for Virtual Machines."
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"virtualMachineScaleSets": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Compute/virtualMachineScaleSets"
]
},
"apiVersion": {
"enum": [
"2015-05-01-preview",
"2015-06-15"
]
},
"sku": {
"$ref": "#/definitions/sku"
},
"properties": {
"properties": {
"upgradePolicy": {
"$ref": "#/definitions/upgradePolicy"
},
"virtualMachineProfile": {
"$ref": "#/definitions/virtualMachineProfile"
}
},
"type": "object",
"required": [
"upgradePolicy",
"virtualMachineProfile"
]
}
},
"required": [
"sku",
"properties"
]
},
"extensions": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Compute/virtualMachines/extensions"
]
},
"apiVersion": {
"enum": [
"2015-05-01-preview",
"2015-06-15"
]
},
"properties": {
"properties": {
"publisher": {
"type": "string"
},
"type": {
"type": "string"
},
"typeHandlerVersion": {
"type": "string"
},
"settings": {
"type": "object"
}
},
"type": "object",
"required": [
"publisher",
"type",
"typeHandlerVersion",
"settings"
]
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"extensionsChild": {
"type": "object",
"properties": {
"type": {
"enum": [
"extensions"
]
},
"apiVersion": {
"enum": [
"2015-05-01-preview",
"2015-06-15"
]
},
"properties": {
"properties": {
"publisher": {
"type": "string"
},
"type": {
"type": "string"
},
"typeHandlerVersion": {
"type": "string"
},
"settings": {
"type": "object"
}
},
"type": "object",
"required": [
"publisher",
"type",
"typeHandlerVersion",
"settings"
]
}
},
"required": [
"type",
"apiVersion",
"properties"
]
}
},
"definitions": {
"id": {
"properties": {
"id": {
"type": "string"
}
},
"type": "object",
"required": [
"id"
]
},
"networkInterfaces": {
"properties": {
"id": {
"type": "string"
},
"properties": {
"properties": {
"primary": {
"type": "boolean"
}
},
"type": "object",
"required": [
"primary"
]
}
},
"type": "object",
"required": [
"id"
]
},
"hardwareProfile": {
"properties": {
"vmSize": {
"type": "string"
}
},
"type": "object",
"required": [
"vmSize"
]
},
"imageReference": {
"properties": {
"publisher": {
"type": "string"
},
"offer": {
"type": "string"
},
"sku": {
"type": "string"
},
"version": {
"type": "string",
"default": "latest"
}
},
"type": "object",
"required": [
"publisher",
"offer",
"sku",
"version"
]
},
"vhd": {
"properties": {
"uri": {
"type": "string"
}
},
"type": "object",
"required": [
"uri"
]
},
"osDisk": {
"properties": {
"osType": {
"type": "string"
},
"name": {
"type": "string"
},
"vhd": {
"$ref": "#/definitions/vhd"
},
"image": {
"$ref": "#/definitions/vhd"
},
"caching": {
"type": "string"
},
"createOption": {
"type": "string"
}
},
"type": "object",
"required": [
"name",
"vhd",
"createOption"
]
},
"vhdUri": {
"properties": {
"uri": {
"type": "string"
}
},
"type": "object",
"required": [
"uri"
]
},
"dataDisk": {
"properties": {
"name": {
"type": "string"
},
"diskSizeGB": {
"type": "string"
},
"lun": {
"type": "number"
},
"vhd": {
"$ref": "#/definitions/vhdUri"
},
"caching": {
"type": "string"
},
"createOption": {
"type": "string"
}
},
"type": "object",
"required": [
"name",
"lun",
"vhd",
"createOption"
]
},
"storageProfile": {
"properties": {
"imageReference": {
"$ref": "#/definitions/imageReference"
},
"osDisk": {
"$ref": "#/definitions/osDisk"
},
"dataDisks": {
"type": "array",
"items": {
"$ref": "#/definitions/dataDisk"
}
}
},
"type": "object",
"required": [
"osDisk"
]
},
"winRMListener": {
"properties": {
"protocol": {
"oneOf": [
{
"enum": [
"http",
"https"
]
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
]
},
"certificateUrl": {
"type": "string"
}
},
"type": "object",
"required": [
"protocol",
"certificateUrl"
]
},
"winRM": {
"properties": {
"listeners": {
"type": "array",
"items": {
"$ref": "#/definitions/winRMListener"
}
}
},
"type": "object",
"required": [
"listeners"
]
},
"additionalUnattendContent": {
"properties": {
"pass": {
"type": "string"
},
"component": {
"type": "string"
},
"settingName": {
"type": "string"
},
"content": {
"type": "string"
}
},
"type": "object",
"required": [
"pass",
"component",
"settingName",
"content"
]
},
"windowsConfiguration": {
"properties": {
"provisionVMAgent": {
"type": "boolean"
},
"winRM": {
"$ref": "#/definitions/winRM"
},
"additionalUnattendContent": {
"type": "array",
"items": {
"$ref": "#/definitions/additionalUnattendContent"
}
},
"enableAutomaticUpdates": {
"type": "boolean"
}
},
"type": "object"
},
"publicKey": {
"properties": {
"path": {
"type": "string"
},
"keyData": {
"type": "string"
}
},
"type": "object"
},
"ssh": {
"properties": {
"publicKeys": {
"type": "array",
"items": {
"$ref": "#/definitions/publicKey"
}
}
},
"type": "object"
},
"linuxConfiguration": {
"properties": {
"disablePasswordAuthentication": {
"type": "string"
},
"ssh": {
"$ref": "#/definitions/ssh"
}
},
"type": "object"
},
"vaultCertificateUrl": {
"properties": {
"certificateUrl": {
"type": "string"
}
},
"type": "object",
"required": [
"certificateUrl"
]
},
"secret": {
"properties": {
"sourceVault": {
"$ref": "#/definitions/id"
},
"vaultCertificates": {
"type": "array",
"items": {
"$ref": "#/definitions/vaultCertificateUrl"
}
}
},
"type": "object",
"required": [
"sourceVault",
"vaultCertificates"
]
},
"osProfile": {
"properties": {
"computerName": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "string"
},
"customData": {
"type": "string"
},
"windowsConfiguration": {
"$ref": "#/definitions/windowsConfiguration"
},
"linuxConfiguration": {
"$ref": "#/definitions/linuxConfiguration"
},
"secrets": {
"type": "array",
"items": {
"$ref": "#/definitions/secret"
}
}
},
"type": "object",
"required": [
"computerName",
"adminUsername",
"adminPassword"
]
},
"networkProfile": {
"properties": {
"networkInterfaces": {
"type": "array",
"items": {
"$ref": "#/definitions/networkInterfaces"
}
}
},
"type": "object",
"required": [
"networkInterfaces"
]
},
"sku": {
"properties": {
"name": {
"type": "string"
},
"tier": {
"type": "string"
},
"capacity": {
"type": "integer"
}
},
"type": "object",
"required": [
"name",
"capacity"
]
},
"upgradePolicy": {
"properties": {
"mode": {
"type": "string"
}
},
"type": "object",
"required": [
"mode"
]
},
"virtualMachineScaleSetOsProfile": {
"properties": {
"computerNamePrefix": {
"type": "string"
},
"adminUsername": {
"type": "string"
},
"adminPassword": {
"type": "string"
},
"customData": {
"type": "string"
},
"windowsConfiguration": {
"$ref": "#/definitions/windowsConfiguration"
},
"linuxConfiguration": {
"$ref": "#/definitions/linuxConfiguration"
},
"secrets": {
"type": "array",
"items": {
"$ref": "#/definitions/secret"
}
}
},
"type": "object",
"required": [
"computerNamePrefix",
"adminUsername",
"adminPassword"
]
},
"virtualMachineScaleSetOSDisk": {
"properties": {
"osType": {
"type": "string"
},
"name": {
"type": "string"
},
"vhdContainers": {
"type": "array",
"items": {
"type": "string"
}
},
"caching": {
"type": "string"
},
"createOption": {
"type": "string"
}
},
"type": "object",
"required": [
"name",
"createOption"
]
},
"virtualMachineScaleSetStorageProfile": {
"properties": {
"imageReference": {
"oneOf": [
{
"$ref": "#/definitions/imageReference"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
]
},
"osDisk": {
"$ref": "#/definitions/virtualMachineScaleSetOSDisk"
}
},
"type": "object",
"required": [
"osDisk"
]
},
"virtualMachineScaleSetExtension": {
"properties": {
"name": {
"type": "string"
},
"properties": {
"properties": {
"publisher": {
"type": "string"
},
"type": {
"type": "string"
},
"typeHandlerVersion": {
"type": "string"
},
"settings": {
"type": "object"
}
},
"type": "object",
"required": [
"publisher",
"type",
"typeHandlerVersion"
]
}
}
},
"virtualMachineScaleSetExtensionProfile": {
"properties": {
"extensions": {
"type": "array",
"items": {
"$ref": "#/definitions/virtualMachineScaleSetExtension"
}
}
},
"type": "object"
},
"ipConfiguration": {
"properties": {
"name": {
"type": "string"
},
"subnet": {
"$ref": "#/definitions/id"
},
"loadBalancerBackendAddressPools": {
"type": "array",
"items": {
"$ref": "#/definitions/id"
}
}
},
"type": "object",
"required": [
"name",
"properties"
]
},
"networkInterfaceConfiguration": {
"properties": {
"name": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"primary": {
"type": "boolean"
},
"ipConfigurations": {
"type": "array",
"items": {
"$ref": "#/definitions/ipConfiguration"
}
}
},
"required": [
"primary",
"ipConfigurations"
]
}
},
"type": "object",
"required": [
"name",
"properties"
]
},
"virtualMachineScaleSetNetworkProfile": {
"properties": {
"networkInterfaceConfigurations": {
"type": "array",
"items": {
"$ref": "#/definitions/networkInterfaceConfiguration"
}
}
},
"type": "object",
"required": [
"networkInterfaceConfigurations"
]
},
"virtualMachineProfile": {
"properties": {
"osProfile": {
"$ref": "#/definitions/virtualMachineScaleSetOsProfile"
},
"storageProfile": {
"$ref": "#/definitions/virtualMachineScaleSetStorageProfile"
},
"extensionProfile": {
"$ref": "#/definitions/virtualMachineScaleSetExtensionProfile"
},
"networkProfile": {
"$ref": "#/definitions/virtualMachineScaleSetNetworkProfile"
}
},
"type": "object",
"required": [
"osProfile",
"storageProfile",
"networkProfile"
]
}
}
}

View File

@@ -0,0 +1,179 @@
{
"id": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Microsoft.Resources",
"description": "Microsoft Resources Resource Types",
"definitions": {
"deployments": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Resources/deployments"
]
},
"apiVersion": {
"enum": [
"2015-01-01"
]
},
"name": {
"type": "string",
"description": "Name of the deployment"
},
"dependsOn": {
"type": "array",
"items": {
"type": "string"
},
"description": "Collection of resources this deployment depends on"
},
"properties": {
"allOf": [
{
"type": "object",
"properties": {
"mode": {
"enum": [ "Incremental" ],
"description": "Deployment mode"
}
},
"required": [ "mode" ]
},
{
"anyOf": [
{
"type": "object",
"properties": {
"templateLink": {
"$ref": "#/definitions/templateLink"
}
}
},
{
"type": "object",
"properties": {
"template": {
"type": "string"
}
}
}
]
},
{
"anyOf": [
{
"type": "object",
"properties": {
"parametersLink": {
"$ref": "#/definitions/parametersLink"
}
}
},
{
"type": "object",
"properties": {
"parameters": {
"type": "object",
"additionalProperties": {
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#/definitions/parameter"
}
}
}
}
]
}
]
}
},
"required": [
"type",
"apiVersion",
"name",
"properties"
]
},
"templateLink": {
"type": "object",
"properties": {
"uri": {
"type": "string",
"description": "URI referencing the deployment template"
},
"contentVersion": {
"type": "string",
"pattern": "(^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$)",
"description": "If included it must match the contentVersion in the template"
}
},
"required": [ "uri" ],
"description": "Template file reference in a deployment"
},
"parametersLink": {
"type": "object",
"properties": {
"uri": {
"type": "string",
"description": "URI referencing the deployment template parameters"
},
"contentVersion": {
"type": "string",
"pattern": "(^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$)",
"description": "If included it must match the contentVersion in the parameters file"
}
},
"required": [ "uri" ],
"description": "Parameter file reference in a deployment"
},
"links": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Resources/links"
]
},
"apiVersion": {
"enum": [
"2015-01-01"
]
},
"name": {
"type": "string",
"maxLength": 64,
"description": "Name of the link"
},
"dependsOn": {
"type": "array",
"items": {
"type": "string"
},
"description": "Collection of resources this link depends on"
},
"properties": {
"type": "object",
"properties": {
"targetId": {
"type": "string",
"description": "Target resource id to link to"
},
"notes": {
"type": "string",
"maxLength": 512,
"description": "Notes for this link"
}
},
"required": [
"targetId"
]
}
},
"required": [
"type",
"apiVersion",
"name",
"properties"
]
}
}
}

View File

@@ -0,0 +1,376 @@
{
"id": "http://schema.management.azure.com/schemas/2014-04-01-preview/Microsoft.Sql.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Microsoft.SQLDatabase",
"description": "Microsoft SQL Database Resource Types",
"definitions": {
"servers": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Sql/servers"
]
},
"apiVersion": {
"enum": [
"2014-04-01-preview"
]
},
"properties": {
"type": "object",
"properties": {
"version": {
"enum": [
"2.0",
"12.0"
],
"description": "Microsoft.Sql/server: Azure SQL DB server version"
},
"administratorLogin": {
"type": "string",
"description": "Microsoft.Sql/server: administrator login name"
},
"administratorLoginPassword": {
"type": "string",
"description": "Microsoft.Sql/server: administrator login password"
}
},
"required": [
"administratorLogin",
"administratorLoginPassword"
]
},
"resources": {
"type": "array",
"items": {
"allOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/resourceBase"
},
{
"oneOf": [
{ "$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Authorization.json#/definitions/locks" },
{ "$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json#/definitions/links" },
{ "$ref": "#/definitions/databasesChild" },
{ "$ref": "#/definitions/firewallrulesChild" }
]
}
]
},
"description": "Microsoft.Sql/servers: Child resources to define databases and firewall rules."
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"databasesBaseCommon": {
"type": "object",
"properties": {
"edition": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"enum": [
"Web",
"Business",
"Basic",
"Standard",
"Premium"
]
}
],
"description": "Microsoft.Sql/server/databases: Optional. Edition of the database to be created. If omitted, the default is Web on server version 2.0 or Standard on server version 12.0."
},
"collation": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"enum": [
"SQL_Latin1_General_Cp437_CS_AS_KI_WI",
"SQL_Latin1_General_Cp437_CI_AS_KI_WI",
"SQL_Latin1_General_Pref_Cp437_CI_AS_KI_WI",
"SQL_Latin1_General_Cp437_CI_AI_KI_WI",
"SQL_Latin1_General_Cp437_BIN",
"SQL_Latin1_General_Cp850_BIN",
"SQL_Latin1_General_Cp850_CS_AS_KI_WI",
"SQL_Latin1_General_Cp850_CI_AS_KI_WI",
"SQL_Latin1_General_Cp850_CI_AI_KI_WI",
"SQL_Latin1_General_Pref_Cp850_CI_AS_KI_WI",
"SQL_1xCompat_Cp850_CI_AS_KI_WI",
"SQL_Latin1_General_Cp1_CS_AS_KI_WI",
"SQL_Latin1_General_Cp1_CI_AS_KI_WI",
"SQL_Latin1_General_Pref_Cp1_CI_AS_KI_WI",
"SQL_Latin1_General_Cp1_CI_AI_KI_WI",
"SQL_AltDiction_Cp850_CS_AS_KI_WI",
"SQL_AltDiction_Pref_Cp850_CI_AS_KI_WI",
"SQL_AltDiction_Cp850_CI_AI_KI_WI",
"SQL_Scandainavian_Pref_Cp850_CI_AS_KI_WI",
"SQL_Scandainavian_Cp850_CS_AS_KI_WI",
"SQL_Scandainavian_Cp850_CI_AS_KI_WI",
"SQL_AltDiction_Cp850_CI_AS_KI_WI",
"SQL_Latin1_General_1250_BIN",
"SQL_Latin1_General_Cp1250_CS_AS_KI_WI",
"SQL_Latin1_General_Cp1250_CI_AS_KI_WI",
"SQL_Czech_Cp1250_CS_AS_KI_WI",
"SQL_Czech_Cp1250_CI_AS_KI_WI",
"SQL_Hungarian_Cp1250_CS_AS_KI_WI",
"SQL_Hungarian_Cp1250_CI_AS_KI_WI",
"SQL_Polish_Cp1250_CS_AS_KI_WI",
"SQL_Polish_Cp1250_CI_AS_KI_WI",
"SQL_Romanian_Cp1250_CS_AS_KI_WI",
"SQL_Romanian_Cp1250_CI_AS_KI_WI",
"SQL_Croatian_Cp1250_CS_AS_KI_WI",
"SQL_Croatian_Cp1250_CI_AS_KI_WI",
"SQL_Slovak_Cp1250_CS_AS_KI_WI",
"SQL_Slovak_Cp1250_CI_AS_KI_WI",
"SQL_Slovenian_Cp1250_CS_AS_KI_WI",
"SQL_Slovenian_Cp1250_CI_AS_KI_WI",
"SQL_Latin1_General_1251_BIN",
"SQL_Latin1_General_Cp1251_CS_AS_KI_WI",
"SQL_Latin1_General_Cp1251_CI_AS_KI_WI",
"SQL_Ukrainian_Cp1251_CS_AS_KI_WI",
"SQL_Ukrainian_Cp1251_CI_AS_KI_WI",
"SQL_Latin1_General_1253_BIN",
"SQL_Latin1_General_Cp1253_CS_AS_KI_WI",
"SQL_Latin1_General_Cp1253_CI_AS_KI_WI",
"SQL_Latin1_General_Cp1253_CI_AI_KI_WI",
"SQL_Latin1_General_1254_BIN",
"SQL_Latin1_General_Cp1254_CS_AS_KI_WI",
"SQL_Latin1_General_Cp1254_CI_AS_KI_WI",
"SQL_Latin1_General_1255_BIN",
"SQL_Latin1_General_Cp1255_CS_AS_KI_WI",
"SQL_Latin1_General_Cp1255_CI_AS_KI_WI",
"SQL_Latin1_General_1256_BIN",
"SQL_Latin1_General_Cp1256_CS_AS_KI_WI",
"SQL_Latin1_General_Cp1256_CI_AS_KI_WI",
"SQL_Latin1_General_1257_BIN",
"SQL_Latin1_General_Cp1257_CS_AS_KI_WI",
"SQL_Latin1_General_Cp1257_CI_AS_KI_WI",
"SQL_Estonian_Cp1257_CS_AS_KI_WI",
"SQL_Estonian_Cp1257_CI_AS_KI_WI",
"SQL_Latvian_Cp1257_CS_AS_KI_WI",
"SQL_Latvian_Cp1257_CI_AS_KI_WI",
"SQL_Lithuanian_Cp1257_CS_AS_KI_WI",
"SQL_Lithuanian_Cp1257_CI_AS_KI_WI",
"SQL_Danish_Pref_Cp1_CI_AS_KI_WI",
"SQL_SwedishPhone_Pref_Cp1_CI_AS_KI_WI",
"SQL_SwedishStd_Pref_Cp1_CI_AS_KI_WI",
"SQL_Icelandic_Pref_Cp1_CI_AS_KI_WI"
]
}
],
"description": "Microsoft.Sql/server/databases: Database collation"
},
"maxSizeBytes": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"enum": [
"104857600",
"524288000",
"1073741824",
"2147483648",
"5368709120",
"10737418240",
"21474836480",
"32212254720",
"42949672960",
"53687091200",
"107374182400",
"161061273600",
"214748364800",
"268435456000",
"322122547200",
"429496729600",
"536870912000"
]
}
],
"description": "Microsoft.Sql/server/databases: Sets the maximum size, in bytes, for the database. This value must be within the range of allowed values for Edition."
},
"requestedServiceObjectiveId": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"enum": [
"910B4FCB-8A29-4C3E-958F-F7BA794388B2",
"DD6D99BB-F193-4EC1-86F2-43D3BCCBC49C",
"F1173C43-91BD-4AAA-973C-54E79E15235B",
"1B1EBD4D-D903-4BAA-97F9-4EA675F5E928",
"455330E1-00CD-488B-B5FA-177C226F28B7",
"789681B8-CA10-4EB0-BDF2-E0B050601B40",
"7203483A-C4FB-4304-9E9F-17C71C904F5D",
"A7D1B92D-C987-4375-B54D-2B1D0E0F5BB0",
"A7C4C615-CFB1-464B-B252-925BE0A19446"
]
}
],
"description": "Microsoft.Sql/server/databases: The GUID corresponding to the performance level for Edition. Shared = 910B4FCB-8A29-4C3E-958F-F7BA794388B2, Basic = DD6D99BB-F193-4EC1-86F2-43D3BCCBC49C, S0 = F1173C43-91BD-4AAA-973C-54E79E15235B, S1 = 1B1EBD4D-D903-4BAA-97F9-4EA675F5E928, S2 = 455330E1-00CD-488B-B5FA-177C226F28B7, S3 = 789681B8-CA10-4EB0-BDF2-E0B050601B40, P1 = 7203483A-C4FB-4304-9E9F-17C71C904F5D, P2 = A7D1B92D-C987-4375-B54D-2B1D0E0F5BB0, P3 = A7C4C615-CFB1-464B-B252-925BE0A19446"
}
}
},
"databasesBaseAll": {
"type": "object",
"properties": {
"createMode": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"enum": [
"Copy",
"OnlineSecondary",
"OfflineSecondary",
"Recovery",
"PointInTimeRestore",
"Restore"
]
}
],
"description": "Microsoft.Sql/server/databases: Defines that databases is created as a Point-In-Time restoration of another database."
},
"sourceDatabaseId": {
"type": "string",
"description": "Microsoft.Sql/server/databases: The URI of the source database."
},
"restorePointInTime": {
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/UTC",
"description": "Microsoft.Sql/server/databases: The point in time for the restore."
},
"sourceDatabaseDeletionDate": {
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/UTC",
"description": "Microsoft.Sql/server/databases: The deletion date time of the source database."
}
}
},
"databasesBase": {
"allOf": [
{
"$ref": "#/definitions/databasesBaseCommon"
},
{
"$ref": "#/definitions/databasesBaseAll"
}
]
},
"databasesChild": {
"type": "object",
"properties": {
"type": {
"enum": [
"databases"
]
},
"apiVersion": {
"enum": [
"2014-04-01-preview"
]
},
"properties": {
"$ref": "#/definitions/databasesBase"
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"databases": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Sql/servers/databases"
]
},
"apiVersion": {
"enum": [
"2014-04-01-preview"
]
},
"properties": {
"$ref": "#/definitions/databasesBase"
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"firewallrulesBase": {
"type": "object",
"properties": {
"endIpAddress": {
"type": "string",
"description": "Microsoft.Sql/server/firewallrules: ending IP address"
},
"startIpAddress": {
"type": "string",
"description": "Microsoft.Sql/server/firewallrules: starting IP address"
}
}
},
"firewallrulesChild": {
"type": "object",
"properties": {
"type": {
"enum": [
"firewallrules"
]
},
"apiVersion": {
"enum": [
"2014-04-01-preview"
]
},
"properties": {
"$ref": "#/definitions/firewallrulesBase"
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"firewallrules": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Sql/servers/firewallrules"
]
},
"apiVersion": {
"enum": [
"2014-04-01-preview"
]
},
"properties": {
"$ref": "#/definitions/firewallrulesBase"
}
},
"required": [
"type",
"apiVersion",
"properties"
]
}
}
}

View File

@@ -0,0 +1,332 @@
{
"id": "http://schema.management.azure.com/schemas/2014-06-01/Microsoft.Web.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Microsoft.Web",
"description": "Microsoft Web Resource Types",
"definitions": {
"serverfarms": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Web/serverfarms"
]
},
"apiVersion": {
"enum": [
"2014-06-01"
]
},
"properties": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Microsoft.Web/serverfarms: Name of the server farm."
},
"sku": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"enum": [
"Free",
"Shared",
"Basic",
"Standard"
]
}
],
"description": "Microsoft.Web/serverfarms: Server farm sku."
},
"workerSize": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"enum": [
"Small",
"Medium",
"Large"
]
},
{
"type": "integer",
"minimum": 0,
"maximum": 2
}
],
"description": "Microsoft.Web/serverfarms: The instance size."
},
"numberOfWorkers": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"type": "integer",
"minimum": 0,
"maximum": 10
}
],
"description": "Microsoft.Web/serverfarms: The instance count, which is the number of virtual machines dedicated to the farm. Supported values are 1-10."
}
}
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"config": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Web/sites/config",
"config"
]
},
"apiVersion": {
"enum": [
"2014-06-01"
]
},
"properties": {
"type": "object",
"properties": {
"connectionStrings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"ConnectionString": {
"type": "string",
"description": "Microsoft.Web/sites/config: connection string"
},
"Name": {
"type": "string",
"description": "Microsoft.Web/sites/config: connection string name"
},
"Type": {
"type": "integer",
"description": "Microsoft.Web/sites/config: connection string type"
}
}
},
"uniqueItems": true,
"description": "Microsoft.Web/sites/config: Connection strings for database and other external resources."
},
"phpVersion": {
"type": "string",
"description": "Microsoft.Web/sites/config: PHP version (an empty string disables PHP)."
},
"netFrameworkVersion": {
"type": "string",
"description": "Microsoft.Web/sites/config: The .Net Framework version."
}
}
}
},
"description": "Microsoft.Web/sites: Configuration settings for a web site.",
"required": [
"type",
"apiVersion",
"properties"
]
},
"extensions": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Web/sites/extensions",
"extensions"
]
},
"apiVersion": {
"enum": [
"2014-06-01"
]
},
"properties": {
"type": "object",
"properties": {
"packageUri": {
"type": "string",
"description": "Microsoft.Web/sites/extensions: uri of package"
},
"dbType": {
"type": "string",
"description": "Microsoft.Web/sites/extensions: type of database"
},
"connectionString": {
"type": "string",
"description": "Microsoft.Web/sites/extensions: connection string"
},
"setParameters": {
"type": "object",
"description": "Microsoft.Web/sites/extensions: parameters"
}
}
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"sites": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Web/sites"
]
},
"apiVersion": {
"enum": [
"2014-06-01"
]
},
"properties": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Microsoft.Web/sites: The name of web site."
},
"serverFarm": {
"type": "string",
"description": "Microsoft.Web/sites: The name of server farm site belongs to."
},
"hostnames": {
"type": "array",
"items": {
"type": "string"
},
"description": "Microsoft.Web/sites: An array of strings that contains the public hostnames for the site, including custom domains."
},
"enabledHostnames": {
"type": "array",
"items": {
"type": "string"
},
"description": "Microsoft.Web/sites: An array of strings that contains enabled hostnames for the site. By default, these are <SiteName>.azurewebsites.net and <SiteName>.scm.azurewebsites.net."
},
"hostNameSslStates": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Microsoft.Web/sites/hostNameSslStates: The URL of the web site."
},
"sslState": {
"oneOf": [
{
"enum": [
"Disabled",
"IpBasedEnabled",
"SniEnabled"
]
},
{
"type": "integer",
"minimum": 0,
"maximum": 2
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
],
"description": "Microsoft.Web/sites/hostNameSslStates. The SSL state."
},
"thumbprint": {
"type": "string",
"description": "Microsoft.Web/sites/hostNameSslStates: A string that contains the thumbprint of the SSL certificate."
},
"ipBasedSslState": {
"oneOf": [
{
"enum": [
"Disabled",
"IpBasedEnabled",
"SniEnabled"
]
},
{
"type": "integer",
"minimum": 0,
"maximum": 2
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
],
"description": "Microsoft.Web/sites/hostNameSslStates: IP Based SSL state"
}
}
},
"description": "Microsoft.Web/sites: Container for SSL states."
}
}
},
"resources": {
"type": "array",
"items": {
"allOf": [
{ "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/resourceBase" },
{
"oneOf": [
{"$ref": "#/definitions/config"},
{"$ref": "#/definitions/extensions"}
]
}
],
"description": "Microsoft.Web/sites: Child resources to define configuration and extensions."
}
}
},
"required": [
"type",
"apiVersion",
"properties"
]
},
"certificates": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Web/certificates"
]
},
"apiVersion": {
"enum": [
"2014-06-01"
]
},
"properties": {
"type": "object",
"properties": {
"pfxBlob": {
"type": "string",
"description": "Microsoft.Web/certificates: A base64Binary value that contains the PfxBlob of the certificate."
},
"password": {
"type": "string",
"description": "Microsoft.Web/certficates: A string that contains the password for the certificate."
}
}
}
}
}
}
}

View File

@@ -0,0 +1,51 @@
{
"id": "http://schema.management.azure.com/schemas/2014-04-01/SuccessBricks.ClearDB.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "SuccessBricks.ClearDB",
"description": "SuccessBricks ClearDB Resource Types",
"definitions": {
"databases": {
"type":"object",
"properties": {
"type": {
"enum": [
"SuccessBricks.ClearDB/databases"
]
},
"apiVersion": {
"enum": [
"2014-04-01"
]
},
"plan": {
"type": "object",
"properties": {
"name": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
},
{
"enum": [
"Free",
"Jupiter",
"Saturn",
"Venus"
]
}
],
"description": "Name of the plan"
}
},
"required": ["name"],
"description": "ClearDB database plan"
}
},
"required": [
"type",
"apiVersion",
"plan"
]
}
}
}

View File

@@ -0,0 +1,47 @@
{
"id": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Parameters",
"description": "An Azure deployment parameter file",
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"contentVersion": {
"type": "string",
"pattern": "(^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$)",
"description": "A 4 number format for the version number of this parameter file. For example, 1.0.0.0"
},
"parameters": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/parameter"
},
"description": "Collection of parameters to pass into a template"
}
},
"required": [
"$schema",
"contentVersion",
"parameters"
],
"definitions": {
"parameter": {
"type": "object",
"properties": {
"value": {
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/parameterValueTypes",
"description": "Input value to template"
},
"metadata": {
"type": "object",
"description": "Client specific metadata"
}
},
"required": [
"value"
]
}
}
}

View File

@@ -0,0 +1,382 @@
{
"id": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Template",
"description": "An Azure deployment template",
"type": "object",
"properties": {
"$schema": {
"type": "string",
"description": "JSON schema reference"
},
"contentVersion": {
"type": "string",
"pattern": "(^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$)",
"description": "A 4 number format for the version number of this template file. For example, 1.0.0.0"
},
"variables": {
"type": "object",
"description": "Variable definitions"
},
"parameters": {
"type": "object",
"description": "Input parameter definitions",
"additionalProperties": {
"$ref": "#/definitions/parameter"
}
},
"resources": {
"type": "array",
"description": "Collection of resources to be deployed",
"items": {
"oneOf": [
{
"allOf": [
{
"$ref": "#/definitions/resourceBase"
},
{
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2014-06-01/Microsoft.Web.json#/definitions/certificates"
},
{
"$ref": "http://schema.management.azure.com/schemas/2014-06-01/Microsoft.Web.json#/definitions/serverfarms"
}
]
}
]
},
{
"allOf": [
{
"$ref": "#/definitions/resourceBaseForParentResources"
},
{
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2014-06-01/Microsoft.Web.json#/definitions/sites"
},
{
"$ref": "http://schema.management.azure.com/schemas/2014-04-01-preview/Microsoft.Sql.json#/definitions/servers"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-08-01/Microsoft.Compute.json#/resourceDefinitions/virtualMachines"
}
]
}
]
},
{
"allOf": [
{
"$ref": "#/definitions/resourceBaseExternal"
},
{
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2014-04-01/SuccessBricks.ClearDB.json#/definitions/databases"
}
]
}
]
},
{
"allOf": [
{
"$ref": "#/definitions/ARMResourceBase"
},
{
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json#/definitions/deployments"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json#/definitions/links"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Authorization.json#/definitions/locks"
}
]
}
]
}
]
},
"minItems": 1
},
"outputs": {
"type": "object",
"description": "Output parameter definitions",
"additionalProperties": {
"$ref": "#/definitions/output"
}
}
},
"additionalProperties": false,
"required": [
"$schema",
"contentVersion",
"resources"
],
"definitions": {
"resourceBase": {
"allOf": [
{
"$ref": "#/definitions/resourceBaseForParentResources"
},
{
"properties": {
"resources": {
"$ref": "#/definitions/childResources"
}
}
}
]
},
"ARMResourceBase": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of the resource"
},
"type": {
"type": "string",
"description": "Resource type"
},
"apiVersion": {
"type": "string",
"description": "API Version of the resource type"
},
"dependsOn": {
"type": "array",
"items": {
"type": "string"
},
"description": "Collection of resources this resource depends on"
}
},
"required": [
"name",
"type",
"apiVersion"
]
},
"proxyResourceBase": {
"allOf": [
{
"$ref": "#/definitions/ARMResourceBase"
},
{
"properties": {
"resources": {
"$ref": "#/definitions/childResources"
},
"location": {
"$ref": "#/definitions/resourceLocations",
"description": "Location to deploy resource to"
}
}
}
]
},
"resourceBaseForParentResources": {
"allOf": [
{
"$ref": "#/definitions/ARMResourceBase"
},
{
"properties": {
"kind": {
"type": "string",
"maxLength": 64,
"pattern": "(^[a-zA-Z0-9_.()-]+$)",
"description": "Kind of resource"
},
"location": {
"$ref": "#/definitions/resourceLocations",
"description": "Location to deploy resource to"
},
"tags": {
"type": "object",
"description": "Name-value pairs to add to the resource"
},
"plan": {
"$ref": "#/definitions/resourcePlan"
}
},
"required": [
"location"
]
}
]
},
"resourceBaseExternal": {
"$ref": "#/definitions/resourceBase",
"required": [
"plan"
]
},
"childResources": {
"type": "array",
"items": {
"$ref": "#/definitions/ARMChildResources"
}
},
"ARMChildResources": {
"oneOf": [
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Authorization.json#/definitions/locks"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json#/definitions/links"
}
]
},
"resourcePlan": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of the plan"
},
"promotionCode": {
"type": "string",
"description": "Plan promotion code"
},
"publisher": {
"type": "string",
"description": "Name of the publisher"
},
"product": {
"type": "string",
"description": "Name of the product"
}
},
"required": [
"name"
],
"description": "Plan of the resource"
},
"resourceLocations": {
"anyOf": [
{
"type": "string"
},
{
"enum": [
"East Asia",
"Southeast Asia",
"Central US",
"East US",
"East US 2",
"West US",
"North Central US",
"South Central US",
"North Europe",
"West Europe",
"Japan West",
"Japan East",
"Brazil South",
"Australia East",
"Australia Southeast",
"Central India",
"West India",
"South India"
]
}
]
},
"parameter": {
"type": "object",
"properties": {
"type": {
"$ref": "#/definitions/parameterTypes",
"description": "Type of input parameter"
},
"defaultValue": {
"$ref": "#/definitions/parameterValueTypes",
"description": "Default value to be used if one is not provided"
},
"allowedValues": {
"type": "array",
"description": "Value can only be one of these values"
},
"minLength": {
"type": "integer",
"description": "Minimum number of characters that must be used"
},
"maxLength": {
"type": "integer",
"description": "Maximum number of characters that can be used"
},
"metadata": {
"type": "object",
"description": "Metadata for the parameter"
}
},
"required": [
"type"
],
"description": "Input parameter definitions"
},
"output": {
"type": "object",
"properties": {
"type": {
"$ref": "#/definitions/parameterTypes",
"description": "Type of output value"
},
"value": {
"$ref": "#/definitions/parameterValueTypes",
"description": "Value assigned for output"
}
},
"required": [
"type",
"value"
],
"description": "Set of output parameters"
},
"parameterTypes": {
"enum": [
"string",
"securestring",
"int",
"bool",
"object",
"array"
]
},
"parameterValueTypes": {
"type": [
"string",
"boolean",
"integer",
"number",
"object",
"array",
"null"
]
},
"expression": {
"type": "string",
"pattern": "^\\[(concat|parameters|variables|reference|resourceId|resourceGroup|subscription|listKeys|listPackage|base64|providers|copyIndex|padLeft)\\(.*\\).*\\]$",
"description": "Deployment template expression. Expressions are enclosed in [] and must start with a function of concat(), parameters(), variables(), reference(), resourceId(), resourceGroup(), subscription(), listKeys(), listPackage(), base64(), providers(), copyIndex(), padLeft()"
},
"Iso8601Duration": {
"type": "string",
"pattern": "^P(\\d+Y)?(\\d+M)?(\\d+D)?(T(((\\d+H)(\\d+M)?(\\d+(\\.\\d{1,2})?S)?)|((\\d+M)(\\d+(\\.\\d{1,2})?S)?)|((\\d+(\\.\\d{1,2})?S))))?$"
},
"UTC": {
"type": "string",
"pattern": "^\\d{4}(-(0[1-9]|1[0-2])(-([012]\\d|3[01])(T((([01]\\d|2[0123]):[0-5]\\d)|(24:00))(:(([0-5]\\d)|60)(\\.\\d{1,}){0,1}){0,1}){0,1}((Z)|([+-]((([01]\\d|2[0123]):[0-5]\\d)|(24:00)))){0,1}){0,1}){0,1}$"
},
"apiVersion": {
"type": "string",
"pattern": "(^((\\d\\d\\d\\d-\\d\\d-\\d\\d)|([0-9]+(\\.[0-9]+)?))(-[a-zA-Z][a-zA-Z0-9]*)?$)",
"description": "API version of the resource type"
}
}
}

View File

@@ -0,0 +1,437 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import Json = require('../json-toolbox/json');
import {
ITextDocument, DocumentFormattingParams, Range, Position, FormattingOptions, TextEdit
} from 'vscode-languageserver';
import {LinesModel, create as createLinesModel} from '../utils/lines';
import Formatter = require('../jsonFormatter');
import assert = require('assert');
suite('JSON Formatter', () => {
function format(unformatted: string, expected: string, insertSpaces = true) {
let range: Range = null;
let uri = 'test://test.json';
let lines = createLinesModel(unformatted);
let rangeStart = unformatted.indexOf('|');
let rangeEnd = unformatted.lastIndexOf('|');
if (rangeStart !== -1 && rangeEnd !== -1) {
// remove '|'
unformatted = unformatted.substring(0, rangeStart) + unformatted.substring(rangeStart + 1, rangeEnd) + unformatted.substring(rangeEnd + 1);
let startPos = lines.positionAt(rangeStart);
let endPos = lines.positionAt(rangeEnd);
range = Range.create(startPos, endPos);
lines = createLinesModel(unformatted);
}
let document = {
getText: () => unformatted,
uri: uri
}
let edits = Formatter.format(document, lines, range, { tabSize: 2, insertSpaces: insertSpaces });
let formatted = unformatted;
let sortedEdits = edits.sort((a, b) => lines.offsetAt(b.range.start) - lines.offsetAt(a.range.start));
let lastOffset = formatted.length;
sortedEdits.forEach(e => {
let startOffset = lines.offsetAt(e.range.start);
let endOffset = lines.offsetAt(e.range.end);
assert.ok(startOffset <= endOffset);
assert.ok(endOffset <= lastOffset);
formatted = formatted.substring(0, startOffset) + e.newText + formatted.substring(endOffset, formatted.length);
lastOffset = startOffset;
})
assert.equal(formatted, expected);
}
test('object - single property', () => {
var content = [
'{"x" : 1}'
].join('\n');
var expected = [
'{',
' "x": 1',
'}'
].join('\n');
format(content, expected);
});
test('object - multiple properties', () => {
var content = [
'{"x" : 1, "y" : "foo", "z" : true}'
].join('\n');
var expected = [
'{',
' "x": 1,',
' "y": "foo",',
' "z": true',
'}'
].join('\n');
format(content, expected);
});
test('object - no properties ', () => {
var content = [
'{"x" : { }, "y" : {}}'
].join('\n');
var expected = [
'{',
' "x": {},',
' "y": {}',
'}'
].join('\n');
format(content, expected);
});
test('object - nesting', () => {
var content = [
'{"x" : { "y" : { "z" : { }}, "a": true}}'
].join('\n');
var expected = [
'{',
' "x": {',
' "y": {',
' "z": {}',
' },',
' "a": true',
' }',
'}'
].join('\n');
format(content, expected);
});
test('array - single items', () => {
var content = [
'["[]"]'
].join('\n');
var expected = [
'[',
' "[]"',
']'
].join('\n');
format(content, expected);
});
test('array - multiple items', () => {
var content = [
'[true,null,1.2]'
].join('\n');
var expected = [
'[',
' true,',
' null,',
' 1.2',
']'
].join('\n');
format(content, expected);
});
test('array - no items', () => {
var content = [
'[ ]'
].join('\n');
var expected = [
'[]'
].join('\n');
format(content, expected);
});
test('array - nesting', () => {
var content = [
'[ [], [ [ {} ], "a" ] ]'
].join('\n');
var expected = [
'[',
' [],',
' [',
' [',
' {}',
' ],',
' "a"',
' ]',
']',
].join('\n');
format(content, expected);
});
test('syntax errors', () => {
var content = [
'[ null 1.2 ]'
].join('\n');
var expected = [
'[',
' null 1.2',
']',
].join('\n');
format(content, expected);
});
test('empty lines', () => {
var content = [
'{',
'"a": true,',
'',
'"b": true',
'}',
].join('\n');
var expected = [
'{',
'\t"a": true,',
'\t"b": true',
'}',
].join('\n');
format(content, expected, false);
});
test('single line comment', () => {
var content = [
'[ ',
'//comment',
'"foo", "bar"',
'] '
].join('\n');
var expected = [
'[',
' //comment',
' "foo",',
' "bar"',
']',
].join('\n');
format(content, expected);
});
test('block line comment', () => {
var content = [
'[{',
' /*comment*/ ',
'"foo" : true',
'}] '
].join('\n');
var expected = [
'[',
' {',
' /*comment*/',
' "foo": true',
' }',
']',
].join('\n');
format(content, expected);
});
test('single line comment on same line', () => {
var content = [
' { ',
' "a": {}// comment ',
' } '
].join('\n');
var expected = [
'{',
' "a": {} // comment ',
'}',
].join('\n');
format(content, expected);
});
test('block comment on same line', () => {
var content = [
'{ "a": {}, /*comment*/ ',
' /*comment*/ "b": {}, ',
' "c": {/*comment*/} } ',
].join('\n');
var expected = [
'{',
' "a": {}, /*comment*/',
' /*comment*/ "b": {},',
' "c": { /*comment*/}',
'}',
].join('\n');
format(content, expected);
});
test('block comment on same line advanced', () => {
var content = [
' { "d": [',
' null',
' ] /*comment*/',
' ,"e": /*comment*/ [null] }',
].join('\n');
var expected = [
'{',
' "d": [',
' null',
' ] /*comment*/,',
' "e": /*comment*/ [',
' null',
' ]',
'}',
].join('\n');
format(content, expected);
});
test('multiple block comments on same line', () => {
var content = [
'{ "a": {} /*comment*/, /*comment*/ ',
' /*comment*/ "b": {} /*comment*/ } '
].join('\n');
var expected = [
'{',
' "a": {} /*comment*/, /*comment*/',
' /*comment*/ "b": {} /*comment*/',
'}',
].join('\n');
format(content, expected);
});
test('range', () => {
var content = [
'{ "a": {},',
'|"b": [null, null]|',
'} '
].join('\n');
var expected = [
'{ "a": {},',
'"b": [',
' null,',
' null',
']',
'} ',
].join('\n');
format(content, expected);
});
test('range with existing indent', () => {
var content = [
'{ "a": {},',
' |"b": [null],',
'"c": {}',
'} |'
].join('\n');
var expected = [
'{ "a": {},',
' "b": [',
' null',
' ],',
' "c": {}',
'}',
].join('\n');
format(content, expected);
});
test('range with existing indent - tabs', () => {
var content = [
'{ "a": {},',
'| "b": [null], ',
'"c": {}',
'} | '
].join('\n');
var expected = [
'{ "a": {},',
'\t"b": [',
'\t\tnull',
'\t],',
'\t"c": {}',
'}',
].join('\n');
format(content, expected, false);
});
test('block comment none-line breaking symbols', () => {
var content = [
'{ "a": [ 1',
'/* comment */',
', 2',
'/* comment */',
']',
'/* comment */',
',',
' "b": true',
'/* comment */',
'}'
].join('\n');
var expected = [
'{',
' "a": [',
' 1',
' /* comment */',
' ,',
' 2',
' /* comment */',
' ]',
' /* comment */',
' ,',
' "b": true',
' /* comment */',
'}',
].join('\n');
format(content, expected);
});
test('line comment after none-line breaking symbols', () => {
var content = [
'{ "a":',
'// comment',
'null,',
' "b"',
'// comment',
': null',
'// comment',
'}'
].join('\n');
var expected = [
'{',
' "a":',
' // comment',
' null,',
' "b"',
' // comment',
' : null',
' // comment',
'}',
].join('\n');
format(content, expected);
});
});

View File

@@ -0,0 +1,109 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import Parser = require('../jsonParser');
import SchemaService = require('../jsonSchemaService');
import JsonSchema = require('../json-toolbox/jsonSchema');
import {JSONCompletion} from '../jsonCompletion';
import {IXHROptions, IXHRResponse} from '../utils/httpRequest';
import {create as createLinesModel} from '../utils/lines';
import {JSONHover} from '../jsonHover';
import {Hover, ITextDocument, TextDocumentIdentifier, TextDocumentPosition, Range, Position, TextEdit} from 'vscode-languageserver';
suite('JSON Hover', () => {
function testComputeInfo(value: string, schema: JsonSchema.IJSONSchema, position: Position): Promise<Hover> {
var uri = 'test://test.json';
var schemaService = new SchemaService.JSONSchemaService(requestService);
var hoverProvider = new JSONHover(schemaService);
var id = "http://myschemastore/test1";
schemaService.registerExternalSchema(id, ["*.json"], schema);
var document = {
getText: () => value,
uri: uri
}
var textDocumentLocation = TextDocumentPosition.create(uri, position);
var lines = createLinesModel(value);
var jsonDoc = Parser.parse(value);
return hoverProvider.doHover(document, textDocumentLocation, lines, jsonDoc);
}
var requestService = function(options: IXHROptions): Promise<IXHRResponse> {
return Promise.reject<IXHRResponse>({ responseText: '', status: 404 });
}
test('Simple schema', function(testDone) {
var content = '{"a": 42, "b": "hello", "c": false}';
var schema: JsonSchema.IJSONSchema = {
type: 'object',
description: 'a very special object',
properties: {
'a': {
type: 'number',
description: 'A'
},
'b': {
type: 'string',
description: 'B'
},
'c': {
type: 'boolean',
description: 'C'
}
}
};
Promise.all([
testComputeInfo(content, schema, { line: 0, character: 0 }).then((result) => {
assert.deepEqual(result.contents, ['a very special object']);
}),
testComputeInfo(content, schema, { line: 0, character: 1 }).then((result) => {
assert.deepEqual(result.contents, ['A']);
}),
testComputeInfo(content, schema, { line: 0, character: 32 }).then((result) => {
assert.deepEqual(result.contents, ['C']);
}),
testComputeInfo(content, schema, { line: 0, character: 7 }).then((result) => {
assert.deepEqual(result.contents, ['A']);
})
]).then(() => testDone(), (error) => testDone(error));
});
test('Nested schema', function(testDone) {
var content = '{"a": 42, "b": "hello"}';
var schema: JsonSchema.IJSONSchema = {
oneOf: [{
type: 'object',
description: 'a very special object',
properties: {
'a': {
type: 'number',
description: 'A'
},
'b': {
type: 'string',
description: 'B'
},
}
}, {
type: 'array'
}]
};
Promise.all([
testComputeInfo(content, schema, { line: 0, character: 9 }).then((result) => {
assert.deepEqual(result.contents, ['a very special object']);
}),
testComputeInfo(content, schema, { line: 0, character: 1 }).then((result) => {
assert.deepEqual(result.contents, ['A']);
})
]).then(() => testDone(), (error) => testDone(error));
});
})

View File

@@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import lines = require('../utils/lines');
import {Position} from 'vscode-languageserver';
suite('Lines Model Validator', () => {
test('single line', () => {
var str = "Hello World";
var lm = lines.create(str);
assert.equal(lm.lineCount, 1);
for (var i = 0; i < str.length; i++) {
assert.equal(lm.offsetAt(Position.create(0, i)), i);
assert.deepEqual(lm.positionAt(i), Position.create(0, i));
}
});
test('Mutiple lines', () => {
var str = "ABCDE\nFGHIJ\nKLMNO\n";
var lm = lines.create(str);
assert.equal(lm.lineCount, 4);
for (var i = 0; i < str.length; i++) {
var line = Math.floor(i / 6);
var column = i % 6;
assert.equal(lm.offsetAt(Position.create(line, column)), i);
assert.deepEqual(lm.positionAt(i), Position.create(line, column));
}
assert.equal(lm.offsetAt(Position.create(3, 0)), 18);
assert.equal(lm.offsetAt(Position.create(3, 1)), 18);
assert.deepEqual(lm.positionAt(18), Position.create(3, 0));
assert.deepEqual(lm.positionAt(19), Position.create(3, 0));
});
test('New line characters', () => {
var str = "ABCDE\rFGHIJ";
assert.equal(lines.create(str).lineCount, 2);
var str = "ABCDE\nFGHIJ";
assert.equal(lines.create(str).lineCount, 2);
var str = "ABCDE\r\nFGHIJ";
assert.equal(lines.create(str).lineCount, 2);
str = "ABCDE\n\nFGHIJ";
assert.equal(lines.create(str).lineCount, 3);
str = "ABCDE\r\rFGHIJ";
assert.equal(lines.create(str).lineCount, 3);
str = "ABCDE\n\rFGHIJ";
assert.equal(lines.create(str).lineCount, 3);
})
test('invalid inputs', () => {
var str = "Hello World";
var lm = lines.create(str);
// invalid position
assert.equal(lm.offsetAt(Position.create(0, str.length)), str.length);
assert.equal(lm.offsetAt(Position.create(0, str.length + 3)), str.length);
assert.equal(lm.offsetAt(Position.create(2, 3)), str.length);
assert.equal(lm.offsetAt(Position.create(-1, 3)), 0);
assert.equal(lm.offsetAt(Position.create(0, -3)), 0);
assert.equal(lm.offsetAt(Position.create(1, -3)), str.length);
// invalid offsets
assert.deepEqual(lm.positionAt(-1), Position.create(0, 0));
assert.deepEqual(lm.positionAt(str.length), Position.create(0, str.length));
assert.deepEqual(lm.positionAt(str.length + 3), Position.create(0, str.length));
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,532 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import assert = require('assert');
import SchemaService = require('../jsonSchemaService');
import JsonSchema = require('../json-toolbox/jsonSchema');
import Json = require('../json-toolbox/json');
import Parser = require('../jsonParser');
import fs = require('fs');
import path = require('path');
import {IXHROptions, IXHRResponse} from '../utils/httpRequest';
suite('JSON Schema', () => {
var fixureDocuments = {
'http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json': 'deploymentTemplate.json',
'http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json': 'deploymentParameters.json',
'http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Authorization.json': 'Microsoft.Authorization.json',
'http://schema.management.azure.com/schemas/2015-01-01/Microsoft.Resources.json': 'Microsoft.Resources.json',
'http://schema.management.azure.com/schemas/2014-04-01-preview/Microsoft.Sql.json': 'Microsoft.Sql.json',
'http://schema.management.azure.com/schemas/2014-06-01/Microsoft.Web.json': 'Microsoft.Web.json',
'http://schema.management.azure.com/schemas/2014-04-01/SuccessBricks.ClearDB.json': 'SuccessBricks.ClearDB.json',
'http://schema.management.azure.com/schemas/2015-08-01/Microsoft.Compute.json': 'Microsoft.Compute.json'
}
var requestServiceMock = function (options:IXHROptions) : Promise<IXHRResponse> {
var uri = options.url;
if (uri.length && uri[uri.length - 1] === '#') {
uri = uri.substr(0, uri.length - 1);
}
var fileName = fixureDocuments[uri];
if (fileName) {
return new Promise<IXHRResponse>((c, e) => {
var fixturePath = path.join(__dirname, '../../../server/src/tests/fixtures', fileName);
fs.readFile(fixturePath, 'UTF-8', (err, result) => {
err ? e({ responseText: '', status: 404 }) : c({ responseText: result.toString(), status: 200 })
});
});
}
return Promise.reject<IXHRResponse>({ responseText: '', status: 404 });
}
test('Resolving $refs', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
service.setSchemaContributions({ schemas: {
"https://myschemastore/main" : {
id: 'https://myschemastore/main',
type: 'object',
properties: {
child: {
'$ref': 'https://myschemastore/child'
}
}
},
"https://myschemastore/child" :{
id: 'https://myschemastore/child',
type: 'bool',
description: 'Test description'
}
}});
service.getResolvedSchema('https://myschemastore/main').then(fs => {
assert.deepEqual(fs.schema.properties['child'], {
id: 'https://myschemastore/child',
type: 'bool',
description: 'Test description'
});
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('FileSchema', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
service.setSchemaContributions({ schemas: {
"main" : {
id: 'main',
type: 'object',
properties: {
child: {
type: 'object',
properties: {
'grandchild': {
type: 'number',
description: 'Meaning of Life'
}
}
}
}
}
}});
service.getResolvedSchema('main').then(fs => {
var section = fs.getSection(['child', 'grandchild']);
assert.equal(section.description, 'Meaning of Life');
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Array FileSchema', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
service.setSchemaContributions({ schemas: {
"main" : {
id: 'main',
type: 'object',
properties: {
child: {
type: 'array',
items: {
'type': 'object',
'properties': {
'grandchild': {
type: 'number',
description: 'Meaning of Life'
}
}
}
}
}
}
}});
service.getResolvedSchema('main').then(fs => {
var section = fs.getSection(['child','0', 'grandchild']);
assert.equal(section.description, 'Meaning of Life');
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Missing subschema', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
service.setSchemaContributions({ schemas: {
"main" : {
id: 'main',
type: 'object',
properties: {
child: {
type: 'object'
}
}
}
}});
service.getResolvedSchema('main').then(fs => {
var section = fs.getSection(['child','grandchild']);
assert.strictEqual(section, null);
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Preloaded Schema', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
var id = 'https://myschemastore/test1';
var schema : JsonSchema.IJSONSchema = {
type: 'object',
properties: {
child: {
type: 'object',
properties: {
'grandchild': {
type: 'number',
description: 'Meaning of Life'
}
}
}
}
};
service.registerExternalSchema(id, [ '*.json' ], schema);
service.getSchemaForResource('test.json', null).then((schema) => {
var section = schema.getSection(['child','grandchild']);
assert.equal(section.description, 'Meaning of Life');
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('External Schema', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
var id = 'https://myschemastore/test1';
var schema : JsonSchema.IJSONSchema = {
type: 'object',
properties: {
child: {
type: 'object',
properties: {
'grandchild': {
type: 'number',
description: 'Meaning of Life'
}
}
}
}
};
service.registerExternalSchema(id, [ '*.json' ], schema);
service.getSchemaForResource('test.json', null).then((schema) => {
var section = schema.getSection(['child','grandchild']);
assert.equal(section.description, 'Meaning of Life');
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Resolving in-line $refs', function (testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
var id = 'https://myschemastore/test1';
var schema:JsonSchema.IJSONSchema = {
id: 'main',
type: 'object',
definitions: {
'grandchild': {
type: 'number',
description: 'Meaning of Life'
}
},
properties: {
child: {
type: 'array',
items: {
'type': 'object',
'properties': {
'grandchild': {
$ref: '#/definitions/grandchild'
}
}
}
}
}
};
service.registerExternalSchema(id, [ '*.json' ], schema);
service.getSchemaForResource('test.json', null).then((fs) => {
var section = fs.getSection(['child', '0', 'grandchild']);
assert.equal(section.description, 'Meaning of Life');
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Resolving in-line $refs automatically for external schemas', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
var id = 'https://myschemastore/test1';
var schema:JsonSchema.IJSONSchema = {
id: 'main',
type: 'object',
definitions: {
'grandchild': {
type: 'number',
description: 'Meaning of Life'
}
},
properties: {
child: {
type: 'array',
items: {
'type': 'object',
'properties': {
'grandchild': {
$ref: '#/definitions/grandchild'
}
}
}
}
}
};
var fsm = service.registerExternalSchema(id, [ '*.json' ], schema);
fsm.getResolvedSchema().then((fs) => {
var section = fs.getSection(['child','0', 'grandchild']);
assert.equal(section.description, 'Meaning of Life');
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Clearing External Schemas', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
var id1 = 'http://myschemastore/test1';
var schema1:JsonSchema.IJSONSchema = {
type: 'object',
properties: {
child: {
type: 'number'
}
}
};
var id2 = 'http://myschemastore/test2';
var schema2:JsonSchema.IJSONSchema = {
type: 'object',
properties: {
child: {
type: 'string'
}
}
};
service.registerExternalSchema(id1, [ 'test.json', 'bar.json' ], schema1);
service.getSchemaForResource('test.json', null).then((schema) => {
var section = schema.getSection(['child']);
assert.equal(section.type, 'number');
service.clearExternalSchemas();
service.registerExternalSchema(id2, [ '*.json' ], schema2);
return service.getSchemaForResource('test.json', null).then((schema) => {
var section = schema.getSection(['child']);
assert.equal(section.type, 'string');
});
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Schema contributions', function(testDone) {
var service = new SchemaService.JSONSchemaService(requestServiceMock);
service.setSchemaContributions({ schemas: {
"http://myschemastore/myschemabar" : {
id: 'main',
type: 'object',
properties: {
foo: {
type: 'string'
}
}
}
}, schemaAssociations: {
'*.bar': ['http://myschemastore/myschemabar', 'http://myschemastore/myschemafoo']
}});
var id2 = 'http://myschemastore/myschemafoo';
var schema2:JsonSchema.IJSONSchema = {
type: 'object',
properties: {
child: {
type: 'string'
}
}
};
service.registerExternalSchema(id2, null, schema2);
service.getSchemaForResource('main.bar', null).then(resolvedSchema => {
assert.deepEqual(resolvedSchema.errors, []);
assert.equal(2, resolvedSchema.schema.allOf.length);
service.clearExternalSchemas();
return service.getSchemaForResource('main.bar', null).then(resolvedSchema => {
assert.equal(resolvedSchema.errors.length, 1);
assert.ok(resolvedSchema.errors[0].indexOf("Problems loading reference 'http://myschemastore/myschemafoo'") === 0);
service.clearExternalSchemas();
service.registerExternalSchema(id2, null, schema2);
return service.getSchemaForResource('main.bar', null).then(resolvedSchema => {
assert.equal(resolvedSchema.errors.length, 0);
});
});
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Resolving circular $refs', function(testDone) {
var service : SchemaService.IJSONSchemaService = new SchemaService.JSONSchemaService(requestServiceMock);
var input = {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"name": "SQLServer",
"type": "Microsoft.Sql/servers",
"location": "West US",
"apiVersion": "2014-04-01-preview",
"dependsOn": [ ],
"tags": {
"displayName": "SQL Server"
},
"properties": {
"administratorLogin": "asdfasd",
"administratorLoginPassword": "asdfasdfasd"
}
}
]
}
var document = Parser.parse(JSON.stringify(input));
service.getSchemaForResource('file://doc/mydoc.json', document).then(resolveSchema => {
assert.deepEqual(resolveSchema.errors, []);
var content = JSON.stringify(resolveSchema.schema);
assert.equal(content.indexOf('$ref'), -1); // no more $refs
var matchingSchemas = [];
document.validate(resolveSchema.schema, matchingSchemas);
assert.deepEqual(document.errors, []);
assert.deepEqual(document.warnings, []);
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Resolving circular $refs, invalid document', function(testDone) {
var service : SchemaService.IJSONSchemaService = new SchemaService.JSONSchemaService(requestServiceMock);
var input = {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"name": "foo",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2015-01-01",
}
]
}
var document = Parser.parse(JSON.stringify(input));
service.getSchemaForResource('file://doc/mydoc.json', document).then(resolveSchema => {
assert.deepEqual(resolveSchema.errors, []);
var content = JSON.stringify(resolveSchema.schema);
assert.equal(content.indexOf('$ref'), -1); // no more $refs
var matchingSchemas = [];
document.validate(resolveSchema.schema, matchingSchemas);
assert.deepEqual(document.errors, []);
assert.equal(document.warnings.length, 1);
}).then(() => testDone(), (error) => {
testDone(error);
});
});
test('Validate Azure Resource Dfinition', function(testDone) {
var service : SchemaService.IJSONSchemaService = new SchemaService.JSONSchemaService(requestServiceMock);
var input = {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Compute/virtualMachines",
"name": "a",
"location": "West US",
"properties": {
"hardwareProfile": {
"vmSize": "Small"
},
"osProfile": {
"computername": "a",
"adminUsername": "a",
"adminPassword": "a"
},
"storageProfile": {
"imageReference": {
"publisher": "a",
"offer": "a",
"sku": "a",
"version": "latest"
},
"osDisk": {
"name": "osdisk",
"vhd": {
"uri": "[concat('http://', 'b','.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/',variables('OSDiskName'),'.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": "true",
"storageUri": "[concat('http://',parameters('newStorageAccountName'),'.blob.core.windows.net')]"
}
}
}
}
]
}
var document = Parser.parse(JSON.stringify(input));
service.getSchemaForResource('file://doc/mydoc.json', document).then(resolvedSchema => {
assert.deepEqual(resolvedSchema.errors, []);
document.validate(resolvedSchema.schema);
assert.equal(document.warnings.length, 1);
assert.equal(document.warnings[0].message, 'Missing property "computerName"');
}).then(() => testDone(), (error) => {
testDone(error);
});
});
});