Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metaschema Schema Gen Subcommand Throws Error unless --as argument is specified #227

Open
nikitawootten-nist opened this issue Nov 30, 2023 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@nikitawootten-nist
Copy link
Contributor

Describe the bug

Calling the metaschema schema gen subcommand throws a runtime error:

An uncaught runtime error occured. Cannot invoke "String.toUpperCase(java.util.Locale)" because "toFormatText" is null

Who is the bug affecting?

Those using the oscal-cli metaschema generate-schema subcommand

What is affected by this bug?

User DX

When does this occur?

When running the oscal-cli metaschema generate-schema subcommand without the --as argument.

How do we replicate the issue?

metaschema-xslt on  upstream_develop:develop [!?] 
 ➜ nix run github:nikitawootten/infra#oscal-cli -- metaschema generate-schema src/testing/models_metaschema.xml output.json
An uncaught runtime error occured. Cannot invoke "String.toUpperCase(java.util.Locale)" because "toFormatText" is null
metaschema-xslt on  upstream_develop:develop [!?] 
 ✗ nix run github:nikitawootten/infra#oscal-cli -- metaschema generate-schema src/testing/models_metaschema.xml --as=json output.json
Loading metaschema 'file:///Users/naw2/Documents/repos/metaschema-xslt/src/testing/models_metaschema.xml'
Generating JSON schema for 'src/testing/models_metaschema.xml'.
Generated JSON schema file: /Users/naw2/Documents/repos/metaschema-xslt/output.json

Expected behavior (i.e. solution)

The --as argument to be inferred, or a clear error requiring the user to specify it.

@nikitawootten-nist nikitawootten-nist added the bug Something isn't working label Nov 30, 2023
@aj-stein-nist
Copy link
Collaborator

Thanks, @nikitawootten-nist. I will open up a cross-ref issue metaschema-java, as this is an issue with its embedded metaschema-cli usage as a subcommand.

@aj-stein-nist aj-stein-nist moved this from Needs Triage to Todo in NIST OSCAL Work Board Nov 30, 2023
@aj-stein-nist
Copy link
Collaborator

Nevermind, I am going to hold off on that. Interesting, when running it on the WIP metaschema snapshot version, without embedding in oscal-cli, it seems to properly return a message saying --as is required and not throw this stack trace. The plot thickens.

$ tmpdir=$(mktemp -d)
$ pushd $tmpdir
$ curl -L -O https://oss.sonatype.org/content/repositories/snapshots/gov/nist/secauto/metaschema/metaschema-cli/1.0.0-M2-SNAPSHOT/metaschema-cli-1.0.0-M2-20231020.200351-14-metaschema-cli.zip
$ curl -L -O https://raw.githubusercontent.com/usnistgov/metaschema-xslt/develop/src/testing/models_metaschema.xml
$ ./bin/metaschema-cli generate-schema models_metaschema.xml 
usage: metaschema-cli generate-schema --as=FORMAT [<options>] <metaschema-module-file> [<destination-schema-file>]
    --as=<FORMAT>        source format: xml, json, or yaml
 -h,--help               display this help message
    --inline-types       definitions declared inline will be generated as inline types
    --no-color           do not colorize output
    --overwrite          overwrite the destination if it exists
 -q,--quiet              minimize output to include only errors
    --show-stack-trace   display the stack trace associated with an error
    --version            display the application version
Missing required option: as
# Obviously giving it `--as=xml` makes it dump a ton of correct output.

@aj-stein-nist aj-stein-nist moved this from Todo to Further Analysis Needed in NIST OSCAL Work Board Nov 30, 2023
@aj-stein-nist
Copy link
Collaborator

It appears after debugging and experimentation that required() fluent builder argument was not added during the v0.12.2 release of the MetaschemaCommand().

https://github.com/usnistgov/metaschema-java/blob/v0.12.2/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateSchemaCommand.java#L82-L88

https://github.com/usnistgov/metaschema-java/blob/f629ac0d7ad26e599607e3765f0cd3d6c3f740e6/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/GenerateSchemaCommand.java#L82-L89

As develop of metaschema-java is being used to prep an upcoming 1.0.0 of the framework library and the CLI, we cannot immediately test this due to dependency hell scenarios with maven enforcer plugin with varying versions of metaschema-java, liboscal-java, and oscal-cli (even when using the SNAPSHOT builds of the first two), but it looks like it was fixed upstream before the next release, but we need to wait on this. Thanks to @nikitawootten-nist for the help.

/cc @david-waltermire-nist @Arminta-Jenkins-NIST

@aj-stein-nist
Copy link
Collaborator

This needs to be handled like usnistgov/metaschema-java#293 (comment), and that issue is tracking this fix. Will need handle it in that codebase and then update the dependency in here.

@aj-stein-nist aj-stein-nist moved this from Further Analysis Needed to Blocked in NIST OSCAL Work Board Jan 31, 2024
@aj-stein-nist aj-stein-nist added this to the Future milestone Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Blocked
Development

No branches or pull requests

2 participants