зеркало из https://github.com/Azure/sway.git
adding symbol info to semantic errors (#46)
* adding symbol info to semantic errors * updating package version * fixing quotes in require * Update validators.js
This commit is contained in:
Родитель
8ead61390a
Коммит
0afda4f64e
|
@ -29,6 +29,7 @@ var helpers = require('../helpers');
|
|||
var JsonRefs = require('json-refs');
|
||||
var supportedHttpMethods = require('swagger-methods');
|
||||
var swaggerSchema = require('swagger-schema-official/schema');
|
||||
var jsonSymbol = require('@ts-common/z-schema').jsonSymbol;
|
||||
|
||||
function getSchemaProperties (schema) {
|
||||
var properties = _.keys(schema.properties); // Start with the defined properties
|
||||
|
@ -130,6 +131,7 @@ function validateStructure (api) {
|
|||
}
|
||||
|
||||
error.message = 'Not a valid ' + defType + ' definition';
|
||||
error[jsonSymbol] = api.definitionFullyResolved
|
||||
}
|
||||
|
||||
return error;
|
||||
|
@ -144,7 +146,8 @@ function validateStructure (api) {
|
|||
err = {
|
||||
code: 'UNRESOLVABLE_REFERENCE',
|
||||
message: 'Reference could not be resolved: ' + refDetails.uri,
|
||||
path: refPath.concat('$ref')
|
||||
path: refPath.concat('$ref'),
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
};
|
||||
|
||||
if (_.has(refDetails, 'error')) {
|
||||
|
@ -156,14 +159,16 @@ function validateStructure (api) {
|
|||
results.errors.push({
|
||||
code: 'INVALID_REFERENCE',
|
||||
message: refDetails.error || 'Invalid JSON Reference',
|
||||
path: refPath.concat('$ref')
|
||||
path: refPath.concat('$ref'),
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
} else if (_.has(refDetails, 'warning')) {
|
||||
// json-refs only creates warnings for JSON References with superfluous properties which will be ignored
|
||||
results.warnings.push({
|
||||
code: 'EXTRA_REFERENCE_PROPERTIES',
|
||||
message: refDetails.warning,
|
||||
path: refPath
|
||||
path: refPath,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -178,7 +183,8 @@ function validateArrayTypeItemsExistence (api, response, schema, path) {
|
|||
response.errors.push({
|
||||
code: 'OBJECT_MISSING_REQUIRED_PROPERTY',
|
||||
message: 'Missing required property: items',
|
||||
path: path
|
||||
path: path,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -191,12 +197,14 @@ function validateDefaultValue (api, response, schema, path) {
|
|||
|
||||
_.forEach(result.errors, function (error) {
|
||||
error.path = path.concat(error.path.concat('default'));
|
||||
error[jsonSymbol]= api.definitionFullyResolved;
|
||||
|
||||
response.errors.push(error);
|
||||
});
|
||||
|
||||
_.forEach(result.warnings, function (warning) {
|
||||
warning.path = path.concat(warning.path.push('default'));
|
||||
warning[jsonSymbol]= api.definitionFullyResolved;
|
||||
|
||||
response.warnings.push(warning);
|
||||
});
|
||||
|
@ -208,7 +216,8 @@ function validateSchemaProperties (api, response, schema, path) {
|
|||
response.errors.push({
|
||||
code: 'OBJECT_MISSING_REQUIRED_PROPERTY_DEFINITION',
|
||||
message: 'Missing required property definition: ' + name,
|
||||
path: path
|
||||
path: path,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -273,7 +282,8 @@ function validateReferences (api) {
|
|||
response.errors.push({
|
||||
code: 'UNRESOLVABLE_REFERENCE',
|
||||
message: 'Security definition could not be resolved: ' + name,
|
||||
path: srPath
|
||||
path: srPath,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
} else {
|
||||
addReference(sdPtr, JsonRefs.pathToPtr(srPath));
|
||||
|
@ -286,7 +296,8 @@ function validateReferences (api) {
|
|||
response.errors.push({
|
||||
code: 'UNRESOLVABLE_REFERENCE',
|
||||
message: 'Security scope definition could not be resolved: ' + scope,
|
||||
path: ssrPath
|
||||
path: ssrPath,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
} else {
|
||||
addReference(JsonRefs.pathToPtr(sdPath.concat(['scopes', scope])), ssrPtr);
|
||||
|
@ -361,7 +372,8 @@ function validateReferences (api) {
|
|||
code: 'CIRCULAR_INHERITANCE',
|
||||
lineage: [ptr].concat(details.lineage),
|
||||
message: 'Schema object inherits from itself: ' + ptr,
|
||||
path: JsonRefs.pathFromPtr(ptr)
|
||||
path: JsonRefs.pathFromPtr(ptr),
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -390,7 +402,8 @@ function validateReferences (api) {
|
|||
response.warnings.push({
|
||||
code: 'UNUSED_DEFINITION',
|
||||
message: 'Definition is not used: ' + ptr,
|
||||
path: JsonRefs.pathFromPtr(ptr)
|
||||
path: JsonRefs.pathFromPtr(ptr),
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -528,7 +541,8 @@ function validatePathsAndOperations (api) {
|
|||
response.errors.push({
|
||||
code: 'DUPLICATE_PARAMETER',
|
||||
message: 'Operation cannot have duplicate parameters: ' + JsonRefs.pathToPtr(path),
|
||||
path: path
|
||||
path: path,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
} else {
|
||||
seenParameters.push(pName);
|
||||
|
@ -555,7 +569,8 @@ function validatePathsAndOperations (api) {
|
|||
response.errors.push({
|
||||
code: 'EMPTY_PATH_PARAMETER_DECLARATION',
|
||||
message: 'Path parameter declaration cannot be empty: ' + path,
|
||||
path: ['paths', path]
|
||||
path: ['paths', path],
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -564,7 +579,8 @@ function validatePathsAndOperations (api) {
|
|||
response.errors.push({
|
||||
code: 'EQUIVALENT_PATH',
|
||||
message: 'Equivalent path already exists: ' + path,
|
||||
path: pPath
|
||||
path: pPath,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
} else {
|
||||
metadata.paths.push(normalizedPath);
|
||||
|
@ -593,7 +609,8 @@ function validatePathsAndOperations (api) {
|
|||
response.errors.push({
|
||||
code: 'DUPLICATE_OPERATIONID',
|
||||
message: 'Cannot have multiple operations with the same operationId: ' + operationId,
|
||||
path: oPath.concat(['operationId'])
|
||||
path: oPath.concat(['operationId']),
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
} else {
|
||||
metadata.operationIds.push(operationId);
|
||||
|
@ -626,7 +643,8 @@ function validatePathsAndOperations (api) {
|
|||
response.errors.push({
|
||||
code: 'MULTIPLE_BODY_PARAMETERS',
|
||||
message: 'Operation cannot have multiple body parameters',
|
||||
path: oPath
|
||||
path: oPath,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -635,7 +653,8 @@ function validatePathsAndOperations (api) {
|
|||
response.errors.push({
|
||||
code: 'INVALID_PARAMETER_COMBINATION',
|
||||
message: 'Operation cannot have a body parameter and a formData parameter',
|
||||
path: oPath
|
||||
path: oPath,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -644,7 +663,8 @@ function validatePathsAndOperations (api) {
|
|||
response.errors.push({
|
||||
code: 'MISSING_PATH_PARAMETER_DEFINITION',
|
||||
message: 'Path parameter is declared but is not defined: ' + name,
|
||||
path: oPath
|
||||
path: oPath,
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -653,7 +673,8 @@ function validatePathsAndOperations (api) {
|
|||
response.errors.push({
|
||||
code: 'MISSING_PATH_PARAMETER_DECLARATION',
|
||||
message: 'Path parameter is defined but is not declared: ' + name,
|
||||
path: JsonRefs.pathFromPtr(definedPathParameters[name])
|
||||
path: JsonRefs.pathFromPtr(definedPathParameters[name]),
|
||||
[jsonSymbol]: api.definitionFullyResolved
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "yasway",
|
||||
"version": "1.0.11",
|
||||
"version": "1.0.12",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "yasway",
|
||||
"version": "1.0.11",
|
||||
"version": "1.0.12",
|
||||
"description": "A library that simplifies Swagger integrations.",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
|
|
Загрузка…
Ссылка в новой задаче