-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add validator warning for binary string in "application/json" o…
…r parameter - added a findOctetSequences function to handle the logic of finding schema type: string, format: binary for cases of nested arrays, objects, nested arrays of type object, objects with properties that are nested arrays, and objects with properties that are objects, and the simple case where a schema uses type: string, format: binary directly. This function takes a schema object from a resolvedSpec and returns a list of paths to octet sequences (empty list if none found). - added logic to handle application/json request bodies that use schema type: string, format: binary - added logic to handle application/json response bodies of type: string, format: binary - added logic to handle parameters of type: string, format: binary - removed 'binary' as a valid format for type: string parameters. parameters of type: string, format: binary will result in "type+format not well-defined" error - added tests to ensure warnings are issued for request bodies, response bodies, and parameters with schema, type: string, format: binary - added complex tests to exercise combinations of nested arrays and objects that contain schema type: string, format: binary (complex tests done on response bodies) - added "json_or_param_binary_string" as to .defaultsForValidator as a warning in the oas3.schemas section - added "json_or_param_binary_string" configuration option to the README.md rules and defaults sections in the oas3 schemas section
- Loading branch information
Barrett Schonefeld
committed
Feb 17, 2020
1 parent
ab2bc90
commit b36b036
Showing
11 changed files
with
1,089 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Finds octet sequences (type: string, format: binary) in schemas including | ||
// nested arrays, objects, nested arrays of type object, objects with properties | ||
// that are nested arrays, and objects with properties that are objects This | ||
// function takes a resolved schema object (no refs) and returns a list of | ||
// paths to octet sequences (empty list if none found). | ||
|
||
const findOctetSequencePaths = (resolvedSchema, path) => { | ||
if (!resolvedSchema) { | ||
// schema is empty, no octet sequence | ||
return []; | ||
} | ||
|
||
const pathsToOctetSequence = []; | ||
|
||
if (resolvedSchema.type === 'string' && resolvedSchema.format === 'binary') { | ||
pathsToOctetSequence.push(path); | ||
} else if (resolvedSchema.type === 'array') { | ||
pathsToOctetSequence.push(...arrayOctetSequences(resolvedSchema, path)); | ||
} else if (resolvedSchema.type === 'object') { | ||
pathsToOctetSequence.push(...objectOctetSequences(resolvedSchema, path)); | ||
} | ||
|
||
return pathsToOctetSequence; | ||
}; | ||
|
||
function arrayOctetSequences(resolvedSchema, path) { | ||
const arrayPathsToOctetSequence = []; | ||
const arrayItems = resolvedSchema.items; | ||
if (arrayItems !== undefined) { | ||
const arrayPath = `${path}.items`; | ||
if (arrayItems.type === 'string' && arrayItems.format === 'binary') { | ||
arrayPathsToOctetSequence.push(arrayPath); | ||
} else if (arrayItems.type === 'object' || arrayItems.type === 'array') { | ||
arrayPathsToOctetSequence.push( | ||
...findOctetSequencePaths(arrayItems, arrayPath) | ||
); | ||
} | ||
} | ||
return arrayPathsToOctetSequence; | ||
} | ||
|
||
function objectOctetSequences(resolvedSchema, path) { | ||
const objectPathsToOctetSequence = []; | ||
const objectProperties = resolvedSchema.properties; | ||
if (objectProperties) { | ||
Object.keys(objectProperties).forEach(function(prop) { | ||
const propPath = `${path}.properties.${prop}`; | ||
if ( | ||
objectProperties[prop].type === 'string' && | ||
objectProperties[prop].format === 'binary' | ||
) { | ||
objectPathsToOctetSequence.push(propPath); | ||
} else if ( | ||
objectProperties[prop].type === 'object' || | ||
objectProperties[prop].type === 'array' | ||
) { | ||
objectPathsToOctetSequence.push( | ||
...findOctetSequencePaths(objectProperties[prop], propPath) | ||
); | ||
} | ||
}); | ||
} | ||
return objectPathsToOctetSequence; | ||
} | ||
|
||
module.exports.findOctetSequencePaths = findOctetSequencePaths; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.