diff --git a/data/SPDXXmlExample.xml b/data/SPDXXmlExample.xml index 9707b9832..98ee4d544 100644 --- a/data/SPDXXmlExample.xml +++ b/data/SPDXXmlExample.xml @@ -1,5 +1,4 @@ - This is a sample spreadsheet Sample_Document-V2.1 @@ -261,4 +260,3 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. CONTAINS - \ No newline at end of file diff --git a/spdx/parsers/xmlparser.py b/spdx/parsers/xmlparser.py index 3fed3cdb7..3880c9985 100644 --- a/spdx/parsers/xmlparser.py +++ b/spdx/parsers/xmlparser.py @@ -50,7 +50,7 @@ def parse(self, file): file.read(), strip_whitespace=False, encoding="utf-8" ) fixed_object = self._set_in_list(parsed_xml, self.LIST_LIKE_FIELDS) - self.document_object = fixed_object.get("SpdxDocument").get("Document") + self.document_object = fixed_object.get("Document") return super(Parser, self).parse() def _set_in_list(self, data, keys): diff --git a/spdx/writers/jsonyamlxml.py b/spdx/writers/jsonyamlxml.py index 4cc3bde25..cc6fd9d0e 100644 --- a/spdx/writers/jsonyamlxml.py +++ b/spdx/writers/jsonyamlxml.py @@ -513,7 +513,7 @@ def create_document(self): if self.document.relationships: self.document_object["relationships"] = self.create_relationship_info() - return {"Document": self.document_object} + return self.document_object def flatten_document(document_object): diff --git a/spdx/writers/xml.py b/spdx/writers/xml.py index 9e4cb9b09..684f7ea7d 100644 --- a/spdx/writers/xml.py +++ b/spdx/writers/xml.py @@ -38,6 +38,6 @@ def write_document(document, out, validate=True): raise InvalidDocumentError(messages) writer = XMLWriter(document) - document_object = {"SpdxDocument": writer.create_document()} + document_object = {"Document": writer.create_document()} xmltodict.unparse(document_object, out, encoding="utf-8", pretty=True) diff --git a/tests/data/doc_write/json-simple-multi-package.json b/tests/data/doc_write/json-simple-multi-package.json index 9785bd3ab..6d0f72f9e 100644 --- a/tests/data/doc_write/json-simple-multi-package.json +++ b/tests/data/doc_write/json-simple-multi-package.json @@ -1,98 +1,96 @@ { - "Document": { - "spdxVersion": "SPDX-2.1", - "documentNamespace": "https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301", - "creationInfo": { - "creators": [ - "Tool: ScanCode" - ], - "created": "2021-10-21T17:09:37Z", - "licenseListVersion": "3.6" + "spdxVersion": "SPDX-2.1", + "documentNamespace": "https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301", + "creationInfo": { + "creators": [ + "Tool: ScanCode" + ], + "created": "2021-10-21T17:09:37Z", + "licenseListVersion": "3.6" + }, + "dataLicense": "CC0-1.0", + "SPDXID": "SPDXRef-DOCUMENT", + "name": "Sample_Document-V2.1", + "documentDescribes": [ + { + "Package": { + "SPDXID": "SPDXRef-Package1", + "name": "some/path1", + "downloadLocation": "NOASSERTION", + "filesAnalyzed": false, + "licenseConcluded": "NOASSERTION", + "licenseDeclared": "NOASSERTION", + "copyrightText": "Some copyright" + } }, - "dataLicense": "CC0-1.0", - "SPDXID": "SPDXRef-DOCUMENT", - "name": "Sample_Document-V2.1", - "documentDescribes": [ - { - "Package": { - "SPDXID": "SPDXRef-Package1", - "name": "some/path1", - "downloadLocation": "NOASSERTION", - "filesAnalyzed": false, - "licenseConcluded": "NOASSERTION", - "licenseDeclared": "NOASSERTION", - "copyrightText": "Some copyright" - } - }, - { - "Package": { - "SPDXID": "SPDXRef-Package2", - "name": "some/path2", - "downloadLocation": "NOASSERTION", - "packageVerificationCode": { - "packageVerificationCodeValue": "SOME code" - }, - "licenseInfoFromFiles": [ - "LGPL-2.1-or-later" - ], - "licenseConcluded": "NOASSERTION", - "licenseDeclared": "NOASSERTION", - "copyrightText": "Some copyright", - "files": [ - { - "File": { - "name": "./some/path/tofile", - "SPDXID": "SPDXRef-File", - "checksums": [ - { - "algorithm": "checksumAlgorithm_sha1", - "checksumValue": "SOME-SHA1" - } - ], - "licenseConcluded": "NOASSERTION", - "licenseInfoFromFiles": [ - "LGPL-2.1-or-later" - ], - "copyrightText": "NOASSERTION", - "sha1": "SOME-SHA1" - } + { + "Package": { + "SPDXID": "SPDXRef-Package2", + "name": "some/path2", + "downloadLocation": "NOASSERTION", + "packageVerificationCode": { + "packageVerificationCodeValue": "SOME code" + }, + "licenseInfoFromFiles": [ + "LGPL-2.1-or-later" + ], + "licenseConcluded": "NOASSERTION", + "licenseDeclared": "NOASSERTION", + "copyrightText": "Some copyright", + "files": [ + { + "File": { + "name": "./some/path/tofile", + "SPDXID": "SPDXRef-File", + "checksums": [ + { + "algorithm": "checksumAlgorithm_sha1", + "checksumValue": "SOME-SHA1" + } + ], + "licenseConcluded": "NOASSERTION", + "licenseInfoFromFiles": [ + "LGPL-2.1-or-later" + ], + "copyrightText": "NOASSERTION", + "sha1": "SOME-SHA1" } - ] - } - }, - { - "Package": { - "SPDXID": "SPDXRef-Package3", - "name": "some/path3", - "downloadLocation": "NOASSERTION", - "licenseInfoFromFiles": [ - "LGPL-2.1-or-later" - ], - "licenseConcluded": "NOASSERTION", - "licenseDeclared": "NOASSERTION", - "copyrightText": "Some copyright", - "files": [ - { - "File": { - "name": "./some/path/tofile", - "SPDXID": "SPDXRef-File", - "checksums": [ - { - "algorithm": "checksumAlgorithm_sha1", - "checksumValue": "SOME-SHA1" - } - ], - "licenseConcluded": "NOASSERTION", - "licenseInfoFromFiles": [ - "LGPL-2.1-or-later" - ], - "copyrightText": "NOASSERTION", - "sha1": "SOME-SHA1" - } + } + ] + } + }, + { + "Package": { + "SPDXID": "SPDXRef-Package3", + "name": "some/path3", + "downloadLocation": "NOASSERTION", + "licenseInfoFromFiles": [ + "LGPL-2.1-or-later" + ], + "licenseConcluded": "NOASSERTION", + "licenseDeclared": "NOASSERTION", + "copyrightText": "Some copyright", + "files": [ + { + "File": { + "name": "./some/path/tofile", + "SPDXID": "SPDXRef-File", + "checksums": [ + { + "algorithm": "checksumAlgorithm_sha1", + "checksumValue": "SOME-SHA1" + } + ], + "licenseConcluded": "NOASSERTION", + "licenseInfoFromFiles": [ + "LGPL-2.1-or-later" + ], + "copyrightText": "NOASSERTION", + "sha1": "SOME-SHA1" } - ] - } + } + ] } - ] - } -} \ No newline at end of file + } + ] + } \ No newline at end of file diff --git a/tests/data/doc_write/xml-simple-multi-package.xml b/tests/data/doc_write/xml-simple-multi-package.xml index eadaba0fc..6e62a8e65 100644 --- a/tests/data/doc_write/xml-simple-multi-package.xml +++ b/tests/data/doc_write/xml-simple-multi-package.xml @@ -1,79 +1,77 @@ - - - SPDX-2.1 - https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301 - - Tool: ScanCode - 2021-10-21T17:02:23Z - 3.6 - - CC0-1.0 - SPDXRef-DOCUMENT - Sample_Document-V2.1 - - - SPDXRef-Package1 - some/path1 - NOASSERTION - false - NOASSERTION - NOASSERTION - Some copyright - - - - - SPDXRef-Package2 - some/path2 - NOASSERTION - - SOME code - - LGPL-2.1-or-later - NOASSERTION - NOASSERTION - Some copyright - - - ./some/path/tofile - SPDXRef-File - - checksumAlgorithm_sha1 - SOME-SHA1 - - NOASSERTION - LGPL-2.1-or-later - NOASSERTION - SOME-SHA1 - - - - - - - SPDXRef-Package3 - some/path3 - NOASSERTION - LGPL-2.1-or-later - NOASSERTION - NOASSERTION - Some copyright - - - ./some/path/tofile - SPDXRef-File - - checksumAlgorithm_sha1 - SOME-SHA1 - - NOASSERTION - LGPL-2.1-or-later - NOASSERTION - SOME-SHA1 - - - - - - \ No newline at end of file + + SPDX-2.1 + https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301 + + Tool: ScanCode + 2021-10-21T17:02:23Z + 3.6 + + CC0-1.0 + SPDXRef-DOCUMENT + Sample_Document-V2.1 + + + SPDXRef-Package1 + some/path1 + NOASSERTION + false + NOASSERTION + NOASSERTION + Some copyright + + + + + SPDXRef-Package2 + some/path2 + NOASSERTION + + SOME code + + LGPL-2.1-or-later + NOASSERTION + NOASSERTION + Some copyright + + + ./some/path/tofile + SPDXRef-File + + checksumAlgorithm_sha1 + SOME-SHA1 + + NOASSERTION + LGPL-2.1-or-later + NOASSERTION + SOME-SHA1 + + + + + + + SPDXRef-Package3 + some/path3 + NOASSERTION + LGPL-2.1-or-later + NOASSERTION + NOASSERTION + Some copyright + + + ./some/path/tofile + SPDXRef-File + + checksumAlgorithm_sha1 + SOME-SHA1 + + NOASSERTION + LGPL-2.1-or-later + NOASSERTION + SOME-SHA1 + + + + + \ No newline at end of file diff --git a/tests/data/doc_write/xml-simple-plus.xml b/tests/data/doc_write/xml-simple-plus.xml index b69c29f79..9be2ca994 100644 --- a/tests/data/doc_write/xml-simple-plus.xml +++ b/tests/data/doc_write/xml-simple-plus.xml @@ -1,5 +1,4 @@ - SPDX-2.1 CC0-1.0 @@ -39,5 +38,4 @@ SOME-SHA1 - - \ No newline at end of file + \ No newline at end of file diff --git a/tests/data/doc_write/xml-simple.xml b/tests/data/doc_write/xml-simple.xml index 2eb292fe8..15b8bdc90 100644 --- a/tests/data/doc_write/xml-simple.xml +++ b/tests/data/doc_write/xml-simple.xml @@ -1,6 +1,5 @@ - - + SPDX-2.1 CC0-1.0 Sample_Document-V2.1 @@ -39,5 +38,4 @@ SOME-SHA1 - - \ No newline at end of file + \ No newline at end of file diff --git a/tests/data/doc_write/yaml-simple-multi-package.yaml b/tests/data/doc_write/yaml-simple-multi-package.yaml index d7c4b134e..5f9ee90e7 100644 --- a/tests/data/doc_write/yaml-simple-multi-package.yaml +++ b/tests/data/doc_write/yaml-simple-multi-package.yaml @@ -1,65 +1,63 @@ ---- -Document: - SPDXID: SPDXRef-DOCUMENT - creationInfo: - created: '2021-10-21T16:46:56Z' - creators: - - 'Tool: ScanCode' - licenseListVersion: '3.6' - dataLicense: CC0-1.0 - documentDescribes: - - Package: - SPDXID: SPDXRef-Package1 - copyrightText: Some copyright - downloadLocation: NOASSERTION - filesAnalyzed: false +SPDXID: SPDXRef-DOCUMENT +creationInfo: +created: '2021-10-21T16:46:56Z' +creators: +- 'Tool: ScanCode' +licenseListVersion: '3.6' +dataLicense: CC0-1.0 +documentDescribes: +- Package: + SPDXID: SPDXRef-Package1 + copyrightText: Some copyright + downloadLocation: NOASSERTION + filesAnalyzed: false + licenseConcluded: NOASSERTION + licenseDeclared: NOASSERTION + name: some/path1 +- Package: + SPDXID: SPDXRef-Package2 + copyrightText: Some copyright + downloadLocation: NOASSERTION + files: + - File: + SPDXID: SPDXRef-File + checksums: + - algorithm: checksumAlgorithm_sha1 + checksumValue: SOME-SHA1 + copyrightText: NOASSERTION licenseConcluded: NOASSERTION - licenseDeclared: NOASSERTION - name: some/path1 - - Package: - SPDXID: SPDXRef-Package2 - copyrightText: Some copyright - downloadLocation: NOASSERTION - files: - - File: - SPDXID: SPDXRef-File - checksums: - - algorithm: checksumAlgorithm_sha1 - checksumValue: SOME-SHA1 - copyrightText: NOASSERTION - licenseConcluded: NOASSERTION - licenseInfoFromFiles: - - LGPL-2.1-or-later - name: ./some/path/tofile - sha1: SOME-SHA1 - licenseConcluded: NOASSERTION - licenseDeclared: NOASSERTION licenseInfoFromFiles: - LGPL-2.1-or-later - name: some/path2 - packageVerificationCode: - packageVerificationCodeValue: SOME code - - Package: - SPDXID: SPDXRef-Package3 - copyrightText: Some copyright - downloadLocation: NOASSERTION - files: - - File: - SPDXID: SPDXRef-File - checksums: - - algorithm: checksumAlgorithm_sha1 - checksumValue: SOME-SHA1 - copyrightText: NOASSERTION - licenseConcluded: NOASSERTION - licenseInfoFromFiles: - - LGPL-2.1-or-later - name: ./some/path/tofile - sha1: SOME-SHA1 + name: ./some/path/tofile + sha1: SOME-SHA1 + licenseConcluded: NOASSERTION + licenseDeclared: NOASSERTION + licenseInfoFromFiles: + - LGPL-2.1-or-later + name: some/path2 + packageVerificationCode: + packageVerificationCodeValue: SOME code +- Package: + SPDXID: SPDXRef-Package3 + copyrightText: Some copyright + downloadLocation: NOASSERTION + files: + - File: + SPDXID: SPDXRef-File + checksums: + - algorithm: checksumAlgorithm_sha1 + checksumValue: SOME-SHA1 + copyrightText: NOASSERTION licenseConcluded: NOASSERTION - licenseDeclared: NOASSERTION licenseInfoFromFiles: - LGPL-2.1-or-later - name: some/path3 - documentNamespace: https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301 - name: Sample_Document-V2.1 - spdxVersion: SPDX-2.1 + name: ./some/path/tofile + sha1: SOME-SHA1 + licenseConcluded: NOASSERTION + licenseDeclared: NOASSERTION + licenseInfoFromFiles: + - LGPL-2.1-or-later + name: some/path3 +documentNamespace: https://spdx.org/spdxdocs/spdx-example-444504E0-4F89-41D3-9A0C-0305E82C3301 +name: Sample_Document-V2.1 +spdxVersion: SPDX-2.1 diff --git a/tests/data/formats/SPDXXmlExample.xml b/tests/data/formats/SPDXXmlExample.xml index 1c557b281..2f9d82750 100644 --- a/tests/data/formats/SPDXXmlExample.xml +++ b/tests/data/formats/SPDXXmlExample.xml @@ -1,5 +1,4 @@ - This is a sample spreadsheet Sample_Document-V2.1 @@ -261,4 +260,3 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. CONTAINS - \ No newline at end of file diff --git a/tests/utils_test.py b/tests/utils_test.py index 876b57000..dd9482a03 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -238,8 +238,8 @@ def load_and_clean_xml(location): content = l.read() data = xmltodict.parse(content, encoding='utf-8') - if 'creationInfo' in data['SpdxDocument']['Document']: - del(data['SpdxDocument']['Document']['creationInfo']) + if 'creationInfo' in data['Document']: + del(data['Document']['creationInfo']) return sort_nested(data)