Skip to content

Commit

Permalink
Merge pull request #21 from EasyDynamics/EGRC-401
Browse files Browse the repository at this point in the history
EGRC-401: Workaround for Unresolvable NIST JSON Schemas
  • Loading branch information
rgauss authored Jun 15, 2021
2 parents 95b8629 + ac08fc0 commit 2f8bf3a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.project

node_modules/
43 changes: 9 additions & 34 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions utils/convert-json-schema-path/README.md
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
```
37 changes: 37 additions & 0 deletions utils/convert-json-schema-path/app.js
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);

27 changes: 27 additions & 0 deletions utils/convert-json-schema-path/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions utils/convert-json-schema-path/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"node-fetch": "^2.6.1"
}
}

0 comments on commit 2f8bf3a

Please sign in to comment.