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

The JSON schema should not require 2 items for Array notation #536

Closed
trevor-vaughan opened this issue Nov 7, 2019 · 8 comments · Fixed by #627
Closed

The JSON schema should not require 2 items for Array notation #536

trevor-vaughan opened this issue Nov 7, 2019 · 8 comments · Fixed by #627
Labels
Discussion Needed This issues needs to be reviewed by the OSCAL development team. enhancement Scope: Modeling Issues targeted at development of OSCAL formats

Comments

@trevor-vaughan
Copy link

Describe the bug

While developing a component JSON file, I found that editing was made difficult due to the schema requiring two items for Array notation.

This meant that refactoring was made more difficult when I went down to a single item in the Array and then failed schema validation. Allowing Array notation for any number of items would be ideal for ease of use.

Who is the bug affecting?

JSON file content creators.

What is affected by this bug?

Schema validation and refactoring in a timely manner.

@david-waltermire david-waltermire added Discussion Needed This issues needs to be reviewed by the OSCAL development team. enhancement and removed bug labels Dec 19, 2019
@david-waltermire
Copy link
Contributor

I don't think this is a bug, as this is an intentional design feature. Changing this issue to an enhancement request instead.

We use a convention in JSON for multi-object property values that allows a single object to be used for a singleton, and an array to be used for when two or more objects are proved. The JSON schema instances for the OSCAL models enforce this. This is parsing logic supported by many commodity JSON parsers.

If we relaxed the above by allowing an array containing a single value, then a parser would face two possibilities for a singleton object value. 1) a singleton object, or 2) an array containing a single object. This complicates parsing more than the current state.

@trevor-vaughan Can you live with the existing behavior?

@david-waltermire david-waltermire added the Scope: Modeling Issues targeted at development of OSCAL formats label Jan 9, 2020
@smichelotti
Copy link

I'd actually like to go one step further than @trevor-vaughan and propose that object syntax not be allowed at all. This is causing major headaches for us.

Let's take a concrete example: the profile imports property. In the NIST SP 800-53 profiles, this is an object and in the FedRAMP profiles this is an array. This is forcing us to litter our code with IF statements like this:

if (_.isArray(this.profile.imports)) {
  _.forEach(this.profile.imports, i => this.doSomething(i));
} else {
  this.doSomething(this.profile.imports);
}

We have the exact same problem with the controls property of the groups in the catalog document.

catalog.groups[i].controls //<- at run-time need to check if this is object or array

This is a problem both for server-side languages (e.g., C#) as well as in the browser (JavaScript).

I see theoretical discussion about JSON parsers above, but I'm struggling to understand a concrete Use Case where the current behavior is desirable or advantageous. Would like to explore if this can be changed, or understand if there is a better suggestion for developers handling this than the type of IF statements identified above.

@david-waltermire
Copy link
Contributor

@smichelotti This was a requested optimization to make the JSON more concise. As you point out, this is at the cost of implementation complexity and as @trevor-vaughan has pointed out can cause problems with hand-editing. Given these factors it might be good to change to consistent use of arrays. I plan to bring this up on the next lunch with the devs to get more input and gauge consensus before we make a decision.

david-waltermire added a commit to david-waltermire/OSCAL that referenced this issue Feb 21, 2020
Removed use of json-value-key using a flag on properties.
This addresses issue usnistgov#536.
@wendellpiez
Copy link
Contributor

@david-waltermire-nist as I understand it, removing in-json='SINGLETON_OR_ARRAY" from the OSCAL metaschemas will address this issue in OSCAL.

However, it also applies to other schemas defined by Metaschema, and I am now looking at this part of the code. (usnistgov/metaschema#39)

Should I relax the rule that an assembly defined as "SINGLETON_OR_ARRAY" must require two members as an array? (Should it require any?) This issue is likely to come up again for anyone trying to use this feature....

@david-waltermire
Copy link
Contributor

Yes. PR #627 removes the use of the single object for multivalued arrays with a single instance. Arrays will be consistently used. I hope to merge this PR by CoB Wednesday.

@wendellpiez
Copy link
Contributor

Cool. In order to forestall the issue coming up again in a future (Metaschema application) context, I will (also) adjust the JSON Schema production as @trevor-vaughan requests here.

@smichelotti
Copy link

@david-waltermire-nist you mentioned were you hoping to merge this PR by CoB Wednesday - any update on status? We're actively waiting on this merge. Thanks.

@SParekh
Copy link

SParekh commented Mar 12, 2020

@david-waltermire-nist /content/fedramp.gov/json/FedRAMP_catalog.json still has old schema

david-waltermire added a commit that referenced this issue Mar 12, 2020
Removed use of json-value-key using a flag on properties.
This addresses issue #536.
aj-stein-nist pushed a commit to aj-stein-nist/OSCAL-forked that referenced this issue Jan 25, 2023
Removed use of json-value-key using a flag on properties.
This addresses issue usnistgov#536.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Needed This issues needs to be reviewed by the OSCAL development team. enhancement Scope: Modeling Issues targeted at development of OSCAL formats
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants