-
Notifications
You must be signed in to change notification settings - Fork 204
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
Add documentation of Bulk Search API #400
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e4c30d
Added documentation of /api/package/bulk_search/ API
AmitGupta7580 2ff0749
Fix various importer errors
sbs2001 de5301a
Update test_api.py
AmitGupta7580 f06b7d8
Update test_api.py
AmitGupta7580 79ee35a
Update api.py
AmitGupta7580 2fc87f8
Merge branch 'main' into add-bulk-api-docs
AmitGupta7580 befc6b3
Merge branch 'main' into add-bulk-api-docs
AmitGupta7580 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -46,7 +46,7 @@ def cleaned_response(response): | |
- sort lists with a stable order | ||
""" | ||
cleaned_response = [] | ||
response_copy = sorted(response, key=lambda x: x.get("purl", "")) | ||
response_copy = sorted(response["result"], key=lambda x: x.get("purl", "")) | ||
for package_data in response_copy: | ||
package_data["unresolved_vulnerabilities"] = sorted( | ||
package_data["unresolved_vulnerabilities"], key=lambda x: x["vulnerability_id"] | ||
|
@@ -256,56 +256,57 @@ def test_bulk_packages_api(self): | |
content_type="application/json", | ||
).json() | ||
|
||
expected_response = [ | ||
{ | ||
"purl": "pkg:deb/debian/[email protected]?distro=jessie", | ||
"name": "doesnotexist", | ||
"namespace": "debian", | ||
"qualifiers": {"distro": "jessie"}, | ||
"resolved_vulnerabilities": [], | ||
"subpath": None, | ||
"type": "deb", | ||
"unresolved_vulnerabilities": [], | ||
"version": "0.9.7-10", | ||
}, | ||
{ | ||
"name": "datadog-api-client", | ||
"namespace": "com.datadoghq", | ||
"purl": "pkg:maven/com.datadoghq/[email protected]", | ||
"qualifiers": {}, | ||
"resolved_vulnerabilities": [], | ||
"subpath": "", | ||
"type": "maven", | ||
"unresolved_vulnerabilities": [ | ||
{ | ||
"references": [ | ||
{ | ||
"reference_id": "", | ||
"scores": [], | ||
"source": "", | ||
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-21331", | ||
}, | ||
{ | ||
"reference_id": "GHSA-2cxf-6567-7pp6", | ||
"scores": [{"scoring_system": "cvssv3.1_qr", "value": "LOW"}], | ||
"source": "", | ||
"url": "https://github.com/DataDog/datadog-api-client-java/security/advisories/GHSA-2cxf-6567-7pp6", | ||
}, | ||
{ | ||
"reference_id": "GHSA-2cxf-6567-7pp6", | ||
"scores": [], | ||
"source": "", | ||
"url": "https://github.com/advisories/GHSA-2cxf-6567-7pp6", | ||
}, | ||
], | ||
"url": "http://testserver/api/vulnerabilities/60", | ||
"vulnerability_id": "CVE-2021-21331", | ||
} | ||
], | ||
"url": "http://testserver/api/packages/3467", | ||
"version": "1.0.0-beta.7", | ||
}, | ||
] | ||
expected_response = { | ||
"result": [ | ||
{ | ||
"name": "doesnotexist", | ||
"namespace": "debian", | ||
"qualifiers": {"distro": "jessie"}, | ||
"resolved_vulnerabilities": [], | ||
"subpath": None, | ||
"type": "deb", | ||
"unresolved_vulnerabilities": [], | ||
"version": "0.9.7-10", | ||
}, | ||
{ | ||
"name": "datadog-api-client", | ||
"namespace": "com.datadoghq", | ||
"purl": "pkg:maven/com.datadoghq/[email protected]", | ||
"qualifiers": {}, | ||
"resolved_vulnerabilities": [], | ||
"subpath": "", | ||
"type": "maven", | ||
"unresolved_vulnerabilities": [ | ||
{ | ||
"references": [ | ||
{ | ||
"reference_id": "", | ||
"scores": [], | ||
"source": "", | ||
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-21331", | ||
}, | ||
{ | ||
"reference_id": "GHSA-2cxf-6567-7pp6", | ||
"scores": [{"scoring_system": "cvssv3.1_qr", "value": "LOW"}], | ||
"source": "", | ||
"url": "https://github.com/DataDog/datadog-api-client-java/security/advisories/GHSA-2cxf-6567-7pp6", | ||
}, | ||
{ | ||
"reference_id": "GHSA-2cxf-6567-7pp6", | ||
"scores": [], | ||
"source": "", | ||
"url": "https://github.com/advisories/GHSA-2cxf-6567-7pp6", | ||
}, | ||
], | ||
"url": "http://testserver/api/vulnerabilities/60", | ||
"vulnerability_id": "CVE-2021-21331", | ||
} | ||
], | ||
"url": "http://testserver/api/packages/3467", | ||
"version": "1.0.0-beta.7", | ||
}, | ||
] | ||
} | ||
assert cleaned_response(expected_response) == cleaned_response(response) | ||
|
||
def test_invalid_request_bulk_packages(self): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still nested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned here https://drf-spectacular.readthedocs.io/en/latest/drf_spectacular.html#drf_spectacular.utils.extend_schema
to listing object we can use
Serializer(many=True)
@extend_schema(request=PackageBulkRequestSerializer, responses=PackageSerializer(many=True))
When I am trying to return a list of Packages then it automatically convert it into paginator view.
Output :
And I also tried to remove pagination from
setting.py
file and add a custom paginator in other API's but then it adds unwanted parameters in bulk_api as it fetches directly from the Package Model.Preview :
Still trying some other options..