-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from EasyDynamics/EGRC-401
EGRC-401: Workaround for Unresolvable NIST JSON Schemas
- Loading branch information
Showing
6 changed files
with
101 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ info: | |
description: An early draft proposal from Easy Dynamics for a REST API specification for interacting with OSCAL models. | ||
contact: | ||
email: [email protected] | ||
version: 1.0.0 | ||
version: 0.1.0 | ||
externalDocs: | ||
description: Find out more about OSCAL | ||
url: https://pages.nist.gov/OSCAL | ||
|
@@ -1825,46 +1825,21 @@ paths: | |
components: | ||
schemas: | ||
OSCALCatalog: | ||
$ref: 'https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/json/schema/oscal_catalog_schema.json' | ||
$ref: 'https://raw.githubusercontent.com/EasyDynamics/OSCAL/json-schema-ref-by-path/json/schema/oscal_catalog_schema.json#/definitions/assembly_oscal-catalog_catalog' | ||
OSCALProfile: | ||
$ref: 'https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/json/schema/oscal_profile_schema.json' | ||
$ref: 'https://raw.githubusercontent.com/EasyDynamics/OSCAL/json-schema-ref-by-path/json/schema/oscal_profile_schema.json#/definitions/assembly_oscal-profile_profile' | ||
OSCALComponentDefinition: | ||
$ref: 'https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/json/schema/oscal_component_schema.json' | ||
$ref: 'https://raw.githubusercontent.com/EasyDynamics/OSCAL/json-schema-ref-by-path/json/schema/oscal_component_schema.json#/definitions/assembly_oscal-component-definition_component-definition' | ||
OSCALComponentDefinitionComponent: | ||
$ref: 'https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/json/schema/oscal_component_schema.json#/definitions/component' | ||
$ref: 'https://raw.githubusercontent.com/EasyDynamics/OSCAL/json-schema-ref-by-path/json/schema/oscal_component_schema.json#/definitions/assembly_oscal-component-definition_defined-component' | ||
OSCALComponentDefinitionComponentControlImplementation: | ||
$ref: 'https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/json/schema/oscal_component_schema.json#/definitions/component/control-implementation' | ||
$ref: 'https://raw.githubusercontent.com/EasyDynamics/OSCAL/json-schema-ref-by-path/json/schema/oscal_component_schema.json#/definitions/assembly_oscal-component-definition_control-implementation' | ||
OSCALSsp: | ||
$ref: 'https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/json/schema/oscal_ssp_schema.json' | ||
$ref: 'https://raw.githubusercontent.com/EasyDynamics/OSCAL/json-schema-ref-by-path/json/schema/oscal_ssp_schema.json#/definitions/assembly_oscal-ssp_system-security-plan' | ||
OSCALRole: | ||
type: object | ||
properties: | ||
id: | ||
title: Role Identifier | ||
type: string | ||
title: | ||
title: Title | ||
type: string | ||
short-name: | ||
title: Role Short Name | ||
type: string | ||
$ref: 'https://raw.githubusercontent.com/EasyDynamics/OSCAL/json-schema-ref-by-path/json/schema/oscal_catalog_schema.json#/definitions/assembly_oscal-metadata_party' | ||
OSCALParty: | ||
type: object | ||
properties: | ||
uuid: | ||
title: Party Universally Unique Identifier | ||
description: A unique identifier that can be used to reference this defined location elsewhere in an OSCAL document. A UUID should be consistantly used for a given party across revisions of the document. | ||
type: string | ||
pattern: ^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$ | ||
type: | ||
title: Party Type | ||
description: A collection of parties representing people, teams, and organizations. | ||
type: string | ||
enum: [person, organization] | ||
name: | ||
title: Party Name | ||
description: The full name of the party. This is typically the legal name associated with the party. | ||
type: string | ||
$ref: 'https://raw.githubusercontent.com/EasyDynamics/OSCAL/json-schema-ref-by-path/json/schema/oscal_catalog_schema.json#/definitions/assembly_oscal-metadata_role' | ||
securitySchemes: | ||
oscal_auth: | ||
type: oauth2 | ||
|
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,21 @@ | ||
# Overview | ||
|
||
Node.js app that will convert [OSCAL JSON Schemas](https://github.com/usnistgov/OSCAL/tree/main/json/schema) references to other objects (`$ref` values) to references by path | ||
|
||
This is intended to be a temporary workaround until either [Swagger supports OpenAPI v3.1](https://github.com/swagger-api/swagger-ui/issues/5891) or NIST's OSCAL tooling supports [generating JSON schemas with reference by path](https://github.com/usnistgov/metaschema/issues/160). | ||
|
||
# Usage | ||
You'll first need to install the dependencies: | ||
``` | ||
npm install | ||
``` | ||
|
||
The syntax of the command is: | ||
``` | ||
node app.js <oscal-json-schema-url> <output-file> | ||
``` | ||
|
||
For example: | ||
``` | ||
node app.js https://raw.githubusercontent.com/usnistgov/OSCAL/v1.0.0/json/schema/oscal_catalog_schema.json ~/Desktop/oscal_catalog_schema.json | ||
``` |
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,37 @@ | ||
fetch = require("node-fetch"); | ||
fs = require('fs'); | ||
|
||
const convertPaths = (jsonSchema) => { | ||
Object.entries(jsonSchema.definitions).map(([key, definition], index) => { | ||
const newKey = definition["$id"].replace("#", ""); | ||
const newRef = definition | ||
jsonSchema.definitions[newKey] = definition; | ||
delete jsonSchema.definitions[key]; | ||
}); | ||
}; | ||
|
||
const loadJsonSchema = (jsonSchemaUrl, outputFile) => { | ||
console.log("Loading URL " + jsonSchemaUrl); | ||
fetch(jsonSchemaUrl) | ||
.then((res) => res.json()) | ||
.then( | ||
(result) => { | ||
convertPaths(result); | ||
let output = JSON.stringify(result, null, 2); | ||
output = output.replace(/#assembly_/g, "#/definitions/assembly_"); | ||
output = output.replace(/#field_/g, "#/definitions/field_"); | ||
fs.writeFile(outputFile, output, function (err) { | ||
if (err) return console.log(err); | ||
}); | ||
console.log("Converted output in " + outputFile); | ||
}, | ||
(error) => { | ||
console.error(error); | ||
} | ||
); | ||
}; | ||
|
||
const jsonSchemaUrl = process.argv[2]; | ||
const outputFile = process.argv[3]; | ||
const jsonSchema = loadJsonSchema(jsonSchemaUrl, outputFile); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
{ | ||
"dependencies": { | ||
"node-fetch": "^2.6.1" | ||
} | ||
} |