提交 3da2e1c4 编写于 作者: M Martin Aeschlimann

[json] Uncaught TypeError: Cannot read property 'getResolvedSchema' of undefined #668

上级 055168dd
......@@ -4,6 +4,8 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import nls = require('vs/nls');
// Methods
export var GET = 'GET';
export var POST = 'POST';
......@@ -129,4 +131,31 @@ export function parseChunkedData(request:IXHRResponse, collection:IDataChunk[],
collection.push(newDataChunk(responseText, offset, contentLengthPattern.lastIndex - 2, contentLength));
offset = contentLengthPattern.lastIndex + contentLength;
}
}
export function getErrorStatusDescription(status: number) : string {
if (status < 400) {
return void 0;
}
switch (status) {
case 400: return nls.localize('status.400', 'Bad request. The request cannot be fulfilled due to bad syntax.');
case 401: return nls.localize('status.401', 'Unauthorized. The server is refusing to respond.');
case 403: return nls.localize('status.403', 'Forbidden. The server is refusing to respond.');
case 404: return nls.localize('status.404', 'Not Found. The requested location could not be found.');
case 405: return nls.localize('status.405', 'Method not allowed. A request was made using a request method not supported by that location.');
case 406: return nls.localize('status.406', 'Not Acceptable. The server can only generate a response that is not accepted by the client.');
case 407: return nls.localize('status.407', 'Proxy Authentication Required. The client must first authenticate itself with the proxy.');
case 408: return nls.localize('status.408', 'Request Timeout. The server timed out waiting for the request.');
case 409: return nls.localize('status.409', 'Conflict. The request could not be completed because of a conflict in the request.');
case 410: return nls.localize('status.410', 'Gone. The requested page is no longer available.');
case 411: return nls.localize('status.411', 'Length Required. The "Content-Length" is not defined.');
case 412: return nls.localize('status.412', 'Precondition Failed. The precondition given in the request evaluated to false by the server.');
case 413: return nls.localize('status.413', 'Request Entity Too Large. The server will not accept the request, because the request entity is too large.');
case 414: return nls.localize('status.414', 'Request-URI Too Long. The server will not accept the request, because the URL is too long.');
case 415: return nls.localize('status.415', 'Unsupported Media Type. The server will not accept the request, because the media type is not supported.');
case 500: return nls.localize('status.500', 'Internal Server Error.');
case 501: return nls.localize('status.501', 'Not Implemented. The server either does not recognize the request method, or it lacks the ability to fulfill the request.');
case 503: return nls.localize('status.503', 'Service Unavailable. The server is currently unavailable (overloaded or down).');
default: return nls.localize('status.416', 'HTTP status code {0}', status);
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
import nls = require('vs/nls');
import Objects = require('vs/base/common/objects');
import Json = require('vs/base/common/json');
import http = require('vs/base/common/http');
import {IJSONSchema} from 'vs/base/common/jsonSchema';
import Strings = require('vs/base/common/strings');
import URI from 'vs/base/common/uri';
......@@ -332,6 +333,7 @@ export class JSONSchemaService implements IJSONSchemaService {
}
for (var pattern in this.contributionAssociations) {
var fpa = this.getOrAddFilePatternAssociation(pattern);
this.contributionAssociations[pattern].forEach(schemaId => fpa.addSchema(schemaId));
}
}
......@@ -351,7 +353,7 @@ export class JSONSchemaService implements IJSONSchemaService {
schemaURL: url
});
}
return this.requestService.makeRequest({ url: url }).then(
request => {
var content = request.responseText;
......@@ -366,8 +368,8 @@ export class JSONSchemaService implements IJSONSchemaService {
var errors = jsonErrors.length ? [ nls.localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': {1}.', toDisplayString(url), jsonErrors[0])] : [];
return new UnresolvedSchema(schemaContent, errors);
},
error => {
var errorMessage = nls.localize('json.schema.unabletoload', 'Unable to load schema from \'{0}\': {1}', toDisplayString(url), error.responseText || error.toString());
(error : http.IXHRResponse) => {
var errorMessage = nls.localize('json.schema.unabletoload', 'Unable to load schema from \'{0}\': {1}', toDisplayString(url), error.responseText || http.getErrorStatusDescription(error.status) || error.toString());
return new UnresolvedSchema(<IJSONSchema> {}, [ errorMessage ]);
}
);
......@@ -403,7 +405,8 @@ export class JSONSchemaService implements IJSONSchemaService {
var resolveExternalLink = (node: any, uri: string, linkPath: string): WinJS.Promise => {
return this.getOrAddSchemaHandle(uri).getUnresolvedSchema().then(unresolvedSchema => {
if (unresolvedSchema.errors.length) {
resolveErrors.push(nls.localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}.', uri + '#' + linkPath, unresolvedSchema.errors[0]));
var loc = linkPath ? uri + '#' + linkPath : uri;
resolveErrors.push(nls.localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
}
resolveLink(node, unresolvedSchema.schema, linkPath);
return resolveRefs(node, unresolvedSchema.schema);
......@@ -479,7 +482,7 @@ export class JSONSchemaService implements IJSONSchemaService {
public createCombinedSchema(combinedSchemaId: string, schemaIds: string[]) : ISchemaHandle {
if (schemaIds.length === 1) {
return this.schemasById[schemaIds[0]];
return this.getOrAddSchemaHandle(schemaIds[0]);
} else {
var combinedSchema: IJSONSchema = {
allOf: schemaIds.map(schemaId => ({ $ref: schemaId }))
......
......@@ -335,6 +335,55 @@ suite('JSON - schema', () => {
});
});
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);
});
});
}).done(() => testDone(), (error) => {
testDone(error);
});
});
test('Resolving circular $refs', function(testDone) {
var service : SchemaService.IJSONSchemaService = new SchemaService.JSONSchemaService(requestServiceMock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册