addressing part of CR feedback and semantic validation impact
This commit is contained in:
Родитель
da2a3df1f5
Коммит
021fa30f6b
|
@ -55,7 +55,7 @@ exports.builder = {
|
|||
},
|
||||
n: {
|
||||
alias: 'nullable',
|
||||
describe: 'Should nullable be resolved?',
|
||||
describe: 'Should nullable types be resolved?',
|
||||
boolean: true,
|
||||
default: false
|
||||
},
|
||||
|
|
|
@ -611,15 +611,14 @@ exports.allowNullType = function allowNullType(entity, isPropRequired) {
|
|||
}
|
||||
}
|
||||
|
||||
// handling nullable parameters
|
||||
let isPropNullable = entity['x-nullable'] && typeof entity['x-nullable'] === 'boolean';
|
||||
if ((isPropNullable === undefined && !isPropRequired) || isPropNullable) {
|
||||
let savedEntity = entity
|
||||
if (savedEntity.in) {
|
||||
entity.oneOf = [{ "type": entity.type }, { "type": "null" }];
|
||||
delete entity.type
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
entity = {};
|
||||
entity.oneOf = [savedEntity, { "type": "null" }];
|
||||
}
|
||||
|
|
|
@ -66,6 +66,10 @@ exports.validateSpec = function validateSpec(specPath, options) {
|
|||
// validation as that would not match the path parameters defined in the path template
|
||||
// and cause the semantic validation to fail.
|
||||
options.shouldResolveParameterizedHost = false;
|
||||
|
||||
// We shoudln't be resolving nullable types for semantic validaiton as we'll replace nodes
|
||||
// with oneof arrays which are not semantically valid in swagger 2.0 schema.
|
||||
options.shouldResolveNullableTypes = false;
|
||||
let validator = new SpecValidator(specPath, null, options);
|
||||
exports.finalValidationResult[specPath] = validator.specValidationResult;
|
||||
return validator.initialize().then(function () {
|
||||
|
|
|
@ -80,19 +80,16 @@ class SpecResolver {
|
|||
if (options.shouldResolveDiscriminator === null || options.shouldResolveDiscriminator === undefined) {
|
||||
options.shouldResolveDiscriminator = true;
|
||||
}
|
||||
if (options.shouldResolveNullableTypes === null || options.shouldResolveNullableTypes === undefined) {
|
||||
options.shouldResolveNullableTypes = true;
|
||||
}
|
||||
|
||||
if (options.shouldResolveParameterizedHost === null || options.shouldResolveParameterizedHost === undefined) {
|
||||
options.shouldResolveParameterizedHost = true;
|
||||
}
|
||||
|
||||
// Resolving allOf is a neccessary precondition for resolving discriminators. Hence hard setting this to true
|
||||
if (options.shouldResolveDiscriminator) {
|
||||
options.shouldResolveAllOf = true;
|
||||
}
|
||||
|
||||
if (options.shouldResolveNullableTypes === null || options.shouldResolveNullableTypes === undefined) {
|
||||
options.shouldResolveNullableTypes = true;
|
||||
}
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
|
@ -163,7 +160,6 @@ class SpecResolver {
|
|||
} else {
|
||||
return Promise.resolve(self);
|
||||
}
|
||||
// }).catch(function (err) {
|
||||
}).then(() => {
|
||||
if (self.options.shouldResolveNullableTypes) {
|
||||
return self.resolveNullableTypes();
|
||||
|
|
|
@ -46,6 +46,8 @@ class SpecValidator {
|
|||
*
|
||||
* @param {object} [options.shouldResolveParameterizedHost] Should 'x-ms-parameterized-host' be resolved? Default: true
|
||||
*
|
||||
* @param {object} [options.shouldResolveNullableTypes] Should we allow null values to match any type? Default: true
|
||||
*
|
||||
* @return {object} An instance of the SpecValidator class.
|
||||
*/
|
||||
constructor(specPath, specInJson, options) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче