Skip to content

Commit

Permalink
Merge pull request #22 from sonatype-nexus-community/fix/response-sch…
Browse files Browse the repository at this point in the history
…ema-remediation-api

fix: response schema for `POST /api/v2/components/remediation/{ownerType}/{ownerId}`
  • Loading branch information
madpah authored Nov 20, 2024
2 parents 0bf1174 + 77a6f66 commit 3c66410
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 4 additions & 13 deletions spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4720,19 +4720,10 @@ paths:
$ref: '#/components/schemas/ApiComponentDTOV2'
responses:
'200':
description: 'The response returns details for components that can be used
for remediation. Details for the recommended component are grouped under
type in the response.<ul><li>Type <i>next-no-violations</i> indicates
that the component version has no violations.</li><li>Type <i>next-non-failing</i>
indicates that the component version does not fail policy violations.
The response will contain this type only if stageId is provided in the
method call.</li><li>Type <i>next-no-violations-with-dependencies</i>
indicates that the component, along-with its dependencies does not any
violate any policies.</li><li>Type <i>next-non-failing-with-dependencies</i>
indicates that the component and its dependencies will not fail a build
for the stageId provided.</li></ul><p>Hash values returned here are truncated
and are not intended to be used as checksums. They can be used as identifiers
to pass to other REST API calls. '
content:
application/json:
schema:
$ref: '#/components/schemas/ApiComponentRemediationValueDTO'
tags:
- Components
/api/v2/components/versions:
Expand Down
17 changes: 16 additions & 1 deletion update-spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,28 @@
for content_type in json_spec['paths'][path][method]['requestBody']['content']:
if '$ref' in json_spec['paths'][path][method]['requestBody']['content'][content_type]['schema']:
if json_spec['paths'][path][method]['requestBody']['content'][content_type]['schema'][
'$ref'] == ref_to_find:
'$ref'] == ref_to_find:
json_spec['paths'][path][method]['requestBody']['content'][content_type]['schema'][
'$ref'] = ref_to_replace_with

# v184 Updates
# ------------------------------------------------------------------------

# Fix Response schema for POST /api/v2/components/remediation/{ownerType}/{ownerId}
if 'paths' in json_spec and '/api/v2/components/remediation/{ownerType}/{ownerId}' in json_spec['paths']:
if 'post' in json_spec['paths']['/api/v2/components/remediation/{ownerType}/{ownerId}']:
print('Fixing POST /api/v2/components/remediation/{ownerType}/{ownerId}...')
json_spec['paths']['/api/v2/components/remediation/{ownerType}/{ownerId}']['post']['responses'][
'200'] = {
'content': {
'application/json': {
'schema': {
'$ref': '#/components/schemas/ApiComponentRemediationValueDTO'
}
}
}
}

# Coerce `default` responses to be `200`
for path in json_spec['paths']:
for method in json_spec['paths'][path]:
Expand Down

0 comments on commit 3c66410

Please sign in to comment.