Skip to content

Commit

Permalink
fix: Overwrote operation ids for S3 Blob Stores
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Horton <phorton@sonatype.com>
  • Loading branch information
madpah committed May 17, 2024
1 parent 82c5a82 commit 74c656b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 195 deletions.
10 changes: 5 additions & 5 deletions spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3856,12 +3856,12 @@ info:
name: Sonatype Community Maintainers
url: https://github.com/sonatype-nexus-community
description: This documents the available APIs into [Sonatype Nexus Repository Manager](https://www.sonatype.com/products/sonatype-nexus-repository)
as of version 3.67.1-01.
as of version 3.68.1-02.
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
title: Sonatype Nexus Repository Manager
version: 3.67.1-01
version: 3.68.1-02
openapi: 3.0.1
paths:
/v1/assets:
Expand Down Expand Up @@ -4260,7 +4260,7 @@ paths:
x-codegen-request-body-name: body
/v1/blobstores/s3:
post:
operationId: createBlobStore
operationId: CreateS3BlobStore
requestBody:
content:
application/json:
Expand All @@ -4283,7 +4283,7 @@ paths:
x-codegen-request-body-name: body
/v1/blobstores/s3/{name}:
get:
operationId: getBlobStore
operationId: GetS3BlobStore
parameters:
- description: Name of the blob store configuration to fetch
in: path
Expand Down Expand Up @@ -4311,7 +4311,7 @@ paths:
tags:
- Blob store
put:
operationId: updateBlobStore
operationId: UpdateS3BlobStore
parameters:
- description: Name of the blob store to update
in: path
Expand Down
203 changes: 13 additions & 190 deletions update-spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,196 +145,19 @@ def parse_version_from_server_header(header: str) -> str:
'type': 'boolean'
}

# # Fix Response schema for GET /api/v2/applications
# if 'paths' in json_spec and '/api/v2/applications' in json_spec['paths']:
# if 'get' in json_spec['paths']['/api/v2/applications']:
# print('Fixing GET /api/v2/application...')
# json_spec['paths']['/api/v2/applications']['get']['responses'] = {
# 'default': {
# 'description': 'default response',
# 'content': {
# 'application/json': {
# 'schema': {
# '$ref': '#/components/schemas/ApiApplicationListDTO'
# }
# }
# }
# }
# }
#
# # Add schemas for /api/v2/config
# if 'components' in json_spec and 'schemas' in json_spec['components'] \
# and 'SystemConfig' not in json_spec['components']:
# print('Injecting schema: SystemConfigProperty...')
# json_spec['components']['schemas']['SystemConfigProperty'] = {
# 'type': 'string',
# 'enum': [
# 'baseUrl',
# 'forceBaseUrl'
# ]
# }
#
# print('Injecting schema: SystemConfig...')
# json_spec['components']['schemas']['SystemConfig'] = {
# 'properties': {
# 'baseUrl': {
# 'nullable': True,
# 'type': 'string'
# },
# 'forceBaseUrl': {
# 'nullable': True,
# 'type': 'boolean'
# }
# }
# }
#
# # Fix Response schema for GET /api/v2/config
# if 'paths' in json_spec and '/api/v2/config' in json_spec['paths']:
# if 'delete' in json_spec['paths']['/api/v2/config']:
# print('Fixing DELETE /api/v2/config...')
# json_spec['paths']['/api/v2/config']['delete']['parameters'][0].update({
# 'schema': {
# 'items': {
# '$ref': '#/components/schemas/SystemConfigProperty'
# },
# 'type': 'array',
# 'uniqueItems': True
# }
# })
# json_spec['paths']['/api/v2/config']['delete']['responses'] = {
# 204: {
# 'description': 'System Configuration removed',
# 'content': {}
# }
# }
#
# if 'get' in json_spec['paths']['/api/v2/config']:
# print('Fixing GET /api/v2/config...')
# json_spec['paths']['/api/v2/config']['get']['parameters'][0].update({
# 'schema': {
# 'items': {
# '$ref': '#/components/schemas/SystemConfigProperty'
# },
# 'type': 'array',
# 'uniqueItems': True
# }
# })
# json_spec['paths']['/api/v2/config']['get']['responses'] = {
# 200: {
# 'description': 'System Configuration retrieved',
# 'content': {
# 'application/json': {
# 'schema': {
# '$ref': '#/components/schemas/SystemConfig'
# }
# }
# }
# }
# }
# if 'put' in json_spec['paths']['/api/v2/config']:
# print('Fixing GET /api/v2/config...')
# json_spec['paths']['/api/v2/config']['put']['requestBody'] = {
# 'content': {
# 'application/json': {
# 'schema': {
# '$ref': '#/components/schemas/SystemConfig'
# }
# }
# }
# }
# json_spec['paths']['/api/v2/config']['put']['responses'] = {
# 204: {
# 'description': 'System Configuration updated',
# 'content': {}
# }
# }
#
# # Fix `ApiComponentDetailsDTOV2` schema
# if 'components' in json_spec and 'schemas' in json_spec['components'] \
# and 'ApiComponentDetailsDTOV2' in json_spec['components']['schemas']:
# print('Fixing schema: ApiComponentDetailsDTOV2...')
# new_api_component_details_dto_v2 = json_spec['components']['schemas']['ApiComponentDetailsDTOV2']
#
# new_api_component_details_dto_v2['properties']['hygieneRating'].update({'nullable': True})
# new_api_component_details_dto_v2['properties']['integrityRating'].update({'nullable': True})
# new_api_component_details_dto_v2['properties']['relativePopularity'].update({'nullable': True})
#
# json_spec['components']['schemas']['ApiComponentDetailsDTOV2'] = new_api_component_details_dto_v2
#
# # Fix `ApiComponentEvaluationResultDTOV2` schema
# if 'components' in json_spec and 'schemas' in json_spec['components'] \
# and 'ApiComponentEvaluationResultDTOV2' in json_spec['components']['schemas']:
# print('Fixing schema: ApiComponentEvaluationResultDTOV2...')
# new_api_cer_dto = json_spec['components']['schemas']['ApiComponentEvaluationResultDTOV2']
#
# new_api_cer_dto['properties']['errorMessage'].update({'nullable': True})
#
# json_spec['components']['schemas']['ApiComponentEvaluationResultDTOV2'] = new_api_cer_dto
#
# # Fix `ApiMailConfigurationDTO` schema
# if 'components' in json_spec and 'schemas' in json_spec['components'] \
# and 'ApiMailConfigurationDTO' in json_spec['components']['schemas']:
# print('Fixing schema: ApiMailConfigurationDTO...')
# new_api_mail_configuration_dto = json_spec['components']['schemas']['ApiMailConfigurationDTO']
#
# new_api_mail_configuration_dto['properties']['password'] = {
# 'type': 'string'
# }
#
# json_spec['components']['schemas']['ApiMailConfigurationDTO'] = new_api_mail_configuration_dto
#
# # Fix `ApiProxyServerConfigurationDTO` schema
# if 'components' in json_spec and 'schemas' in json_spec['components'] \
# and 'ApiProxyServerConfigurationDTO' in json_spec['components']['schemas']:
# print('Fixing schema: ApiProxyServerConfigurationDTO...')
# new_api_proxy_server_configuration_dto = json_spec['components']['schemas']['ApiProxyServerConfigurationDTO']
#
# new_api_proxy_server_configuration_dto['properties']['password'] = {
# 'type': 'string'
# }
#
# json_spec['components']['schemas']['ApiProxyServerConfigurationDTO'] = new_api_proxy_server_configuration_dto
#
# # Add missing schema `ApiThirdPartyScanTicketDTO`
# if 'components' in json_spec and 'schemas' in json_spec['components'] \
# and 'ApiThirdPartyScanTicketDTO' not in json_spec['components']['schemas']:
# print('Adding schema: ApiThirdPartyScanTicketDTO...')
#
# json_spec['components']['schemas']['ApiThirdPartyScanTicketDTO'] = {
# 'properties': {
# 'statusUrl': {
# 'type': 'string'
# }
# }
# }
#
# # Fix Response schema for POST /api/v2/scan/applications/{applicationId}/sources/{source}
# if 'paths' in json_spec and '/api/v2/scan/applications/{applicationId}/sources/{source}' in json_spec['paths']:
# if 'post' in json_spec['paths']['/api/v2/scan/applications/{applicationId}/sources/{source}']:
# print('Fixing POST /api/v2/scan/applications/{applicationId}/sources/{source}...')
# json_spec['paths']['/api/v2/scan/applications/{applicationId}/sources/{source}']['post']['responses'][
# 'default']['content']['application/json'].update({
# 'schema': {
# '$ref': '#/components/schemas/ApiThirdPartyScanTicketDTO'
# }
# })
#
# # Remove APIs with incomplete schemas
# API_PATHS_TO_REMOVE = {
# '/api/v2/licenseLegalMetadata/customMultiApplication/report': [],
# '/api/v2/product/license': [],
# '/api/v2/config/saml': ['put']
# }
# if 'paths' in json_spec:
# print('Removing paths...')
# for path, methods in API_PATHS_TO_REMOVE.items():
# print(f' Removing: {path} : {methods}')
# if path in json_spec['paths']:
# if len(methods) == 0:
# json_spec['paths'].pop(path)
# else:
# for method in methods:
# json_spec['paths'][path].pop(method)
# Fix OperationID for some requests
operations_to_fix = [
{'path': '/v1/blobstores/s3', 'method': 'post', 'operation_id': 'CreateS3BlobStore'},
{'path': '/v1/blobstores/s3/{name}', 'method': 'get', 'operation_id': 'GetS3BlobStore'},
{'path': '/v1/blobstores/s3/{name}', 'method': 'put', 'operation_id': 'UpdateS3BlobStore'},
]
i = 0
print('Overriding operation IDs...')
for o in operations_to_fix:
print(f' Setting OperationID to {o['operation_id']} for {o['method']}:{o['path']}')
json_spec['paths'][o['path']][o['method']]['operationId'] = o['operation_id']
i = i + 1
print(f'Overwrote {i} Operation IDs')

with open('./spec/openapi.yaml', 'w') as output_yaml_specfile:
output_yaml_specfile.write(yaml_dump(json_spec))

0 comments on commit 74c656b

Please sign in to comment.