Skip to content

Commit

Permalink
Merge pull request #108 from swinslow/docs-cleanup
Browse files Browse the repository at this point in the history
Minor fixes for json documentation
  • Loading branch information
swinslow committed Mar 13, 2022
2 parents b38edad + ccd297a commit 9eeb46e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
17 changes: 8 additions & 9 deletions docs/jsonloader.md
@@ -1,24 +1,23 @@
SPDX-License-Identifier: CC-BY-4.0

## Working
## Usage

A UnmarshallJSON function on the spdx.Document2_2 struct is defined so that when the JSON is unmarshalled in it the function is called and we can implement the process in a custom way . Then a new map[string]interface{} is deifined which temporarily holds the unmarshalled json . The map is then parsed into the spdx.Document2_2 using functions defined for it’s different sections .
A json.Unmarshal function on the spdx.Document2_2 struct is defined so that when the JSON is unmarshalled, the function is called and the JSON can be processed in a custom way. Then a new map[string]interface{} is defined which temporarily holds the unmarshalled JSON. The map is then parsed into the spdx.Document2_2 using functions defined for each different section.

JSON map[string]interface{} spdx.Document2_2
JSON => map[string]interface{} => spdx.Document2_2

## Some Key Points

- The packages have a property "hasFiles" defined in the schema which is an array of the SPDX Identifiers of the files of that pacakge . The parses first parses all the files into the Unpackaged files map of the document and then when it parses the packages , it removes the respective files from the unpackaged files map and places it inside the files map of that package .
- The packages have a property "hasFiles" defined in the schema which is an array of the SPDX Identifiers of the files of that package. The parser first parses all the files into the UnpackagedFiles map of the document and then when it parses the Packages, it removes the respective files from the UnpackagedFiles map and places them inside the Files map of the corresponding package.

- The snippets have a property "snippetFromFile" which has the SPDX identiifer of the file to which the snippet is related . Thus the snippets require the files to be parsed before them . Then the snippets are parsed one by one and inserted into the respective files using this property .
- The snippets have a property "snippetFromFile" which has the SPDX identifier of the file to which the snippet is related. Thus the snippets require the files to be parsed before them. Then the snippets are parsed one by one and inserted into the respective files using this property.

## Assumptions

The json file loader in `package jsonloader` makes the following assumptions:


### Order of appearance of the properties
* The parser does not make any pre-assumptions based on the order in which the properties appear .

* The parser does not make any assumptions based on the order in which the properties appear.

### Annotations
* The json spdx schema does not define the SPDX Identifier property for the annotation object . The parser assumes the spdx Identifier of the parent property of the currently being parsed annotation array to be the SPDX Identifer for all the annotation objects of that array.
* The JSON SPDX schema does not define the SPDX Identifier property for the annotation object. The parser assumes the SPDX Identifier of the parent property of the currently-being-parsed annotation array to be the SPDX Identifer for all the annotation objects of that array.
20 changes: 10 additions & 10 deletions docs/jsonsaver.md
Expand Up @@ -2,27 +2,27 @@ SPDX-License-Identifier: CC-BY-4.0

## Working

The spdx document is converted to map[string]interface{} and then the entire map is converted to json using a single json Marshall function call . The saver uses a tempoarary storage to store all the files (Paackaged and Unpackaged) together in a single data structure in order to comply with the json schema defined by spdx .
The SPDX document is converted to map[string]interface{} and then the entire map is converted to JSON using a single json.MarshalIndent function call. The saver uses temporary memory to store all the files (Packaged and Unpackaged) together in a single data structure in order to comply with the JSON schema defined by SPDX.

spdx.Document2_2 map[string]interface{} JSON
spdx.Document2_2 => map[string]interface{} => JSON

## Some Key Points

- The packages have a property "hasFiles" defined in the schema which is an array of the SPDX Identifiers of the files of that pacakge . The saver iterates through the files of a package and inserted all the SPDX Identifiers of the files in the "hasFiles" array . In addition it adds the file to a temporary storage map to store all the files of the entire document at a single place .
- The packages have a property "hasFiles" defined in the schema which is an array of the SPDX Identifiers of the files of that package. The saver iterates through the files of a package and inserts all the SPDX Identifiers of the files in the "hasFiles" array. In addition it adds each file to a temporary storage map to store all the files of the entire document at a single place.

- The files require the packages to be saved before them in order to ensure that the packaged files are added to the temporary storage before the files are saved .
- The files require the packages to be saved before them in order to ensure that the packaged files are added to the temporary storage before the files are saved.

- The snippets are saved after the files and a property "snippetFromFile" identifies the file of the snippets.
- The snippets are saved after the files and a property "snippetFromFile" identifies the file containing each snippet.

The json file loader in `package jsonsaver` makes the following assumptions:
## Assumptions

The json file loader in `package jsonsaver` makes the following assumptions:

### Order of appearance of the properties
* The saver does not make any pre-assumptions based on the order in which the properties are saved .

* The saver does not make any pre-assumptions based on the order in which the properties are saved.

### Annotations
* The json spdx schema does not define the SPDX Identifier property for the annotation object . The saver inserts the annotation inside the element who spdx identifier mathches the annotation SPDX identifier .
* The JSON SPDX schema does not define the SPDX Identifier property for the annotation object. The saver inserts the annotation inside the element whose SPDX Identifier matches the annotation's SPDX Identifier.

### Indentation
* The jsonsaver uses the marshall indent function with "" as he prefix and "\t" as the indent character , passed as funtion parameters .
* The jsonsaver uses the MarshalIndent function with "" as the prefix and "\t" as the indent character, passed as function parameters.

0 comments on commit 9eeb46e

Please sign in to comment.