Skip to content

Commit

Permalink
adding ability for the user to quit validation quickly through typesc…
Browse files Browse the repository at this point in the history
…ript
  • Loading branch information
shaselton-usds committed Oct 25, 2024
1 parent 56af4ef commit 92868f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
validator: schemavalidator.cpp
g++ -O3 --std=c++17 -I ./rapidjson/include -I ./tclap/include/ schemavalidator.cpp -o validator -lstdc++fs
validatordebug: schemavalidator.cpp
g++ -g --std=c++17 -I ./rapidjson/include -I ./tclap/include/ schemavalidator.cpp -o validator -lstdc++fs
10 changes: 10 additions & 0 deletions schemavalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ int main(int argc, char *argv[])
string outputPath;
int bufferSize = 4069;
string schemaName;
bool failFast;

try
{
Expand All @@ -291,17 +292,20 @@ int main(int argc, char *argv[])
TCLAP::ValueArg<string> outputArg("o", "output-path", "path to output directory", false, "/output", "path");
TCLAP::ValueArg<int> bufferArg("b", "buffer-size", "buffer size in bytes", false, 4069, "integer");
TCLAP::ValueArg<string> schemaNameArg("s", "schema-name", "schema name", false, "", "string");
TCLAP::SwitchArg failFastArg("f", "fail-fast", "if set, stop validating after the first error");
cmd.add(schemaArg);
cmd.add(dataArg);
cmd.add(outputArg);
cmd.add(bufferArg);
cmd.add(schemaNameArg);
cmd.add(failFastArg);
cmd.parse(argc, argv);
schemaPath = schemaArg.getValue();
dataPath = dataArg.getValue();
outputPath = outputArg.getValue();
bufferSize = bufferArg.getValue();
schemaName = schemaNameArg.getValue();
failFast = failFastArg.getValue();
}
catch (TCLAP::ArgException &e)
{
Expand Down Expand Up @@ -383,6 +387,12 @@ int main(int argc, char *argv[])
// SchemaValidator validator(sd);
MessageHandler handler(schemaName);
GenericSchemaValidator<SchemaDocument, MessageHandler> validator(sd, handler);

if (!failFast)
{
validator.SetValidateFlags(kValidateContinueOnErrorFlag);
}

Reader reader;
FILE *fp2 = fopen(dataPath.c_str(), "r");
if (!fp2)
Expand Down
1 change: 1 addition & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export async function validate(dataFile: string, options: OptionValues) {
await schemaManager.ensureRepo();
schemaManager.strict = options.strict;
schemaManager.shouldDetectVersion = options.schemaVersion == null;
schemaManager.isFailFast = options.failFast;
let versionToUse: string;
try {
const detectedVersion = await schemaManager.determineVersion(dataFile);
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async function main() {
.usage('<data-file> [options]')
.argument('<data-file>', 'path to data file to validate')
.option('--schema-version <version>', 'version of schema to use for validation')
.option('-f, --fail-fast', 'quit validating file after the first error is encountered')
.option('-o, --out <out>', 'output path')
.addOption(
new Option('-t, --target <schema>', 'name of schema to use')
Expand All @@ -48,6 +49,7 @@ async function main() {
.usage('<data-url> [options]')
.argument('<data-url>', 'URL to data file to validate')
.option('--schema-version <version>', 'version of schema to use for validation')
.option('-f', 'quit validating file after the first error is encountered')
.option('-o, --out <out>', 'output path')
.addOption(
new Option('-t, --target <schema>', 'name of schema to use')
Expand Down

0 comments on commit 92868f3

Please sign in to comment.