-
Notifications
You must be signed in to change notification settings - Fork 85
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 hasOctetSequence module 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 "binary_string" as to .defaultsForValidator as a warning in the shared.schemas section - added "binary_string" configuration option to the README.md rules and defaults sections in the schemas section
- Loading branch information
Barrett Schonefeld
committed
Feb 14, 2020
1 parent
7a05a41
commit 37d6184
Showing
11 changed files
with
1,378 additions
and
51 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,62 @@ | ||
// 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 schema object from a resolvedSpec and returns a list of | ||
// paths to octet sequences (empty list if none found). | ||
|
||
const hasOctetSequence = (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') { | ||
arrayOctetSequences(resolvedSchema, pathsToOctetSequence, path); | ||
} else if (resolvedSchema.type === 'object') { | ||
objectOctetSequences(resolvedSchema, pathsToOctetSequence, path); | ||
} | ||
|
||
return pathsToOctetSequence; | ||
}; | ||
|
||
function arrayOctetSequences(resolvedSchema, pathsToOctetSequence, path) { | ||
let arrayItems = resolvedSchema.items; | ||
let arrayPath = `${path}.items`; | ||
while (arrayItems !== undefined) { | ||
if (arrayItems.type === 'string' && arrayItems.format === 'binary') { | ||
pathsToOctetSequence.push(arrayPath); | ||
} else if (arrayItems.type === 'object') { | ||
pathsToOctetSequence.push(...hasOctetSequence(arrayItems, arrayPath)); | ||
} | ||
arrayItems = arrayItems.items; | ||
arrayPath += '.items'; | ||
} | ||
} | ||
|
||
function objectOctetSequences(resolvedSchema, pathsToOctetSequence, path) { | ||
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' | ||
) { | ||
pathsToOctetSequence.push(propPath); | ||
} else if ( | ||
objectProperties[prop].type === 'object' || | ||
objectProperties[prop].type === 'array' | ||
) { | ||
pathsToOctetSequence.push( | ||
...hasOctetSequence(objectProperties[prop], propPath) | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports.octetSequences = hasOctetSequence; |
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.