diff --git a/api_deploy/cli.py b/api_deploy/cli.py index 2e4be09..dc52a60 100644 --- a/api_deploy/cli.py +++ b/api_deploy/cli.py @@ -69,6 +69,9 @@ def deploy(config_file, # Always remove scopes when deploying to Amazon API Gateway config['gateway']['remove_scopes'] = True + # Always remove descriptions when deploying to Amazon API Gateway + config['gateway']['remove_descriptions'] = True + target_schema = _compile(source_schema, config) click.secho('Successfully compiled OpenAPI file.\n', fg='green') diff --git a/api_deploy/config.py b/api_deploy/config.py index 5995f7f..af5a874 100644 --- a/api_deploy/config.py +++ b/api_deploy/config.py @@ -31,6 +31,7 @@ def __init__(self, config_file: ConfigFile, file_path) -> None: config_file.get('gateway', {}).get('integrationHost', '')) default_config['gateway'].setdefault('connection_id', config_file.get('gateway', {}).get('connectionId', '')) default_config['gateway'].setdefault('remove_scopes', config_file.get('gateway', {}).get('removeScopes', False)) + default_config['gateway'].setdefault('remove_descriptions', config_file.get('gateway', {}).get('removeDescriptions', False)) default_config['cors'].setdefault('allow_origin', config_file.get('cors', {}).get('origin', '*')) diff --git a/api_deploy/converters.py b/api_deploy/converters.py index 562c431..141c909 100644 --- a/api_deploy/converters.py +++ b/api_deploy/converters.py @@ -203,11 +203,12 @@ def merge_all_of(self, node, schema: Schema): class ApiGatewayProcessor(AbstractProcessor): - def __init__(self, config: Config, integration_host, connection_id, remove_scopes, **kwargs) -> None: + def __init__(self, config: Config, integration_host, connection_id, remove_scopes, remove_descriptions, **kwargs) -> None: super().__init__(config) self.integration_host = integration_host self.connection_id = connection_id self.remove_scopes = remove_scopes + self.remove_descriptions = remove_descriptions def process(self, schema: Schema) -> Schema: for path in schema['paths']: @@ -231,6 +232,11 @@ def process(self, schema: Schema) -> Schema: # remove all scopes from authorizer, not supported in API Gateway security[authorizer] = [] + # Remove all descriptions from models + if self.remove_descriptions: + for model_name in schema['components'].get('schemas', {}): + self._remove_descriptions(schema['components']['schemas'][model_name]) + # Replace all authorizers with API key type for authorizer in schema['components'].get('securitySchemes', {}): scheme = schema['components']['securitySchemes'][authorizer] @@ -242,6 +248,22 @@ def process(self, schema: Schema) -> Schema: return schema + + def _remove_descriptions(self, schema: object): + if isinstance(schema, dict): + schema.pop('description', None) + + if 'properties' in schema: + for property_name in schema['properties']: + self._remove_descriptions(schema['properties'][property_name]) + + if 'items' in schema: + self._remove_descriptions(schema['items']) + if 'properties' in schema['items']: + for property_name in schema['items']['properties']: + self._remove_descriptions(schema['items']['properties'][property_name]) + + def _get_response_codes(self, schema, path, method): responses = { 'default': { diff --git a/tests/functional/api.yml b/tests/functional/api.yml index 3d16ec1..3be97a6 100644 --- a/tests/functional/api.yml +++ b/tests/functional/api.yml @@ -2,6 +2,7 @@ gateway: integrationHost: https://integration.com connectionId: 1234567890 removeScopes: true + removeDescriptions: true headers: request: - host diff --git a/tests/openapi/complex_target.yml b/tests/openapi/complex_target.yml index 439c1f5..cfb368e 100644 --- a/tests/openapi/complex_target.yml +++ b/tests/openapi/complex_target.yml @@ -1109,26 +1109,19 @@ components: datetime: type: string format: date-time - description: Current date and time of the server name: type: string - description: Name of the application environment: type: string - description: Name of the environment the app is running in uptime: type: string - description: Duration of how long the app is running startup: type: string format: date-time - description: Date and time when the application started hostname: type: string - description: Hostname of the application host or container version: type: string - description: Current release version required: - datetime - name @@ -1161,15 +1154,11 @@ components: type: string readOnly: true example: lorem-ipsum - description: Alphanumeric version of the label without spaces - or special chars. name: type: string example: Lorem Ipsum - description: Human readable name color: type: string - description: Color of the label enum: - red - green @@ -1195,19 +1184,15 @@ components: additionalProperties: false properties: count: - description: Number of fetched items type: integer default: 10 total: - description: Total number of items available in the list type: integer default: 15 limit: - description: Maximum number of items to fetch type: integer default: 50 offset: - description: Number if items skipped (for pagination) type: integer default: 0 required: @@ -1269,25 +1254,20 @@ components: format: uuid attachments: type: array - description: Array of file attachments items: type: object nullable: true - description: File attachment details additionalProperties: false properties: name: type: string - description: Human readable file name example: example.pdf path: type: string - description: Relative file path of the attachment example: /vendors/1234567890/some.pdf uploadedAt: type: string format: date-time - description: Date and time of when the attachment was uploaded uploadedBy: type: string format: uuid @@ -1302,7 +1282,6 @@ components: example: User generated info about the offer state: type: string - description: The current state of the offer readOnly: true enum: - draft @@ -1429,26 +1408,20 @@ components: format: uuid attachments: type: array - description: Array of file attachments items: type: object nullable: true - description: File attachment details additionalProperties: false properties: name: type: string - description: Human readable file name example: example.pdf path: type: string - description: Relative file path of the attachment example: /vendors/1234567890/some.pdf uploadedAt: type: string format: date-time - description: Date and time of when the attachment - was uploaded uploadedBy: type: string format: uuid @@ -1462,16 +1435,12 @@ components: additionalProperties: false properties: name: - description: name of the company type: string example: Company AY email: - description: primary contact email of the company type: string example: mail@server.com phoneNumber: - description: primary contact phone number of the - company type: string example: +49 (30) 1234567890 nullable: true @@ -1480,31 +1449,22 @@ components: additionalProperties: false properties: streetAddress: - description: Full street address component, - which MAY include house number, street name, - Post Office Box, and multi-line extended street - address information. type: string example: My Street 123 nullable: true postalCode: - description: Zip code or postal code component. type: string minLength: 1 example: '10119' locality: - description: City or locality component. type: string example: Berlin nullable: true region: - description: State, province, prefecture, or - region component. type: string example: Berlin nullable: true country: - description: Country name component. type: string minLength: 1 maxLength: 2 @@ -1523,15 +1483,12 @@ components: description: type: string example: This is an example project - description: A human readable project description nullable: true title: type: string example: Example project - description: A custom, human readable project title state: type: string - description: The current state of the project readOnly: true enum: - new @@ -1657,19 +1614,15 @@ components: additionalProperties: false properties: count: - description: Number of fetched items type: integer default: 10 total: - description: Total number of items available in the list type: integer default: 15 limit: - description: Maximum number of items to fetch type: integer default: 50 offset: - description: Number if items skipped (for pagination) type: integer default: 0 required: @@ -1721,25 +1674,20 @@ components: format: uuid attachments: type: array - description: Array of file attachments items: type: object nullable: true - description: File attachment details additionalProperties: false properties: name: type: string - description: Human readable file name example: example.pdf path: type: string - description: Relative file path of the attachment example: /vendors/1234567890/some.pdf uploadedAt: type: string format: date-time - description: Date and time of when the attachment was uploaded uploadedBy: type: string format: uuid @@ -1754,7 +1702,6 @@ components: example: User generated info about the offer state: type: string - description: The current state of the offer readOnly: true enum: - draft @@ -1881,25 +1828,20 @@ components: format: uuid attachments: type: array - description: Array of file attachments items: type: object nullable: true - description: File attachment details additionalProperties: false properties: name: type: string - description: Human readable file name example: example.pdf path: type: string - description: Relative file path of the attachment example: /vendors/1234567890/some.pdf uploadedAt: type: string format: date-time - description: Date and time of when the attachment was uploaded uploadedBy: type: string format: uuid @@ -1913,15 +1855,12 @@ components: additionalProperties: false properties: name: - description: name of the company type: string example: Company AY email: - description: primary contact email of the company type: string example: mail@server.com phoneNumber: - description: primary contact phone number of the company type: string example: +49 (30) 1234567890 nullable: true @@ -1930,29 +1869,22 @@ components: additionalProperties: false properties: streetAddress: - description: Full street address component, which MAY - include house number, street name, Post Office Box, - and multi-line extended street address information. type: string example: My Street 123 nullable: true postalCode: - description: Zip code or postal code component. type: string minLength: 1 example: '10119' locality: - description: City or locality component. type: string example: Berlin nullable: true region: - description: State, province, prefecture, or region component. type: string example: Berlin nullable: true country: - description: Country name component. type: string minLength: 1 maxLength: 2 @@ -1971,15 +1903,12 @@ components: description: type: string example: This is an example project - description: A human readable project description nullable: true title: type: string example: Example project - description: A custom, human readable project title state: type: string - description: The current state of the project readOnly: true enum: - new diff --git a/tests/openapi/external_ref_target.yml b/tests/openapi/external_ref_target.yml index 41193fc..adc47c5 100644 --- a/tests/openapi/external_ref_target.yml +++ b/tests/openapi/external_ref_target.yml @@ -736,25 +736,19 @@ components: id: type: string example: 5d4470a6-121b-40d2-aff9-00f24aa4a110 - description: Unique identifier, optionally in UUID format readOnly: true urn: type: string pattern: ^urn:[\w-]+:[\w.-]*:[\w.-]*:[\w-]+\/[^\/]+$ - description: Uniform Resource Name example: urn:pm:service::foobar/d9a6fc2e-a4b3-4fba-9f20-c5bd2fdb5071 tenant: type: string pattern: ^[a-z]{2,}(?:\.[a-z]{1}[a-z-]*[a-z]{1})*$ example: pm.foobar - description: Globally unique tenant reverse domain name readOnly: true packmaticId: type: string pattern: ^[A-Z]{2}-[A-Z0-9]{5,7}$ - description: Human friendly entity reference code, consisting of a type - indicating prefix and a unique identifier, consisting of uppercase letters - and digits. example: PJ-123ABC readOnly: true createdAt: @@ -763,7 +757,6 @@ components: createdBy: type: string pattern: ^urn:[\w-]+:[\w.-]*:[\w.-]*:[\w-]+\/[^\/]+$ - description: Uniform Resource Name example: urn:pm:service::foobar/d9a6fc2e-a4b3-4fba-9f20-c5bd2fdb5071 modifiedAt: type: string @@ -772,7 +765,6 @@ components: modifiedBy: type: string pattern: ^urn:[\w-]+:[\w.-]*:[\w.-]*:[\w-]+\/[^\/]+$ - description: Uniform Resource Name example: urn:pm:service::foobar/d9a6fc2e-a4b3-4fba-9f20-c5bd2fdb5071 nullable: true TestTwo: @@ -791,25 +783,19 @@ components: id: type: string example: 5d4470a6-121b-40d2-aff9-00f24aa4a110 - description: Unique identifier, optionally in UUID format readOnly: true urn: type: string pattern: ^urn:[\w-]+:[\w.-]*:[\w.-]*:[\w-]+\/[^\/]+$ - description: Uniform Resource Name example: urn:pm:service::foobar/d9a6fc2e-a4b3-4fba-9f20-c5bd2fdb5071 tenant: type: string pattern: ^[a-z]{2,}(?:\.[a-z]{1}[a-z-]*[a-z]{1})*$ example: pm.foobar - description: Globally unique tenant reverse domain name readOnly: true packmaticId: type: string pattern: ^[A-Z]{2}-[A-Z0-9]{5,7}$ - description: Human friendly entity reference code, consisting of a type - indicating prefix and a unique identifier, consisting of uppercase letters - and digits. example: PJ-123ABC readOnly: true createdAt: @@ -818,7 +804,6 @@ components: createdBy: type: string pattern: ^urn:[\w-]+:[\w.-]*:[\w.-]*:[\w-]+\/[^\/]+$ - description: Uniform Resource Name example: urn:pm:service::foobar/d9a6fc2e-a4b3-4fba-9f20-c5bd2fdb5071 modifiedAt: type: string @@ -827,7 +812,6 @@ components: modifiedBy: type: string pattern: ^urn:[\w-]+:[\w.-]*:[\w.-]*:[\w-]+\/[^\/]+$ - description: Uniform Resource Name example: urn:pm:service::foobar/d9a6fc2e-a4b3-4fba-9f20-c5bd2fdb5071 nullable: true securitySchemes: diff --git a/tests/openapi/one_of_target.yml b/tests/openapi/one_of_target.yml index 2aeb8e7..7289b3f 100644 --- a/tests/openapi/one_of_target.yml +++ b/tests/openapi/one_of_target.yml @@ -355,22 +355,18 @@ components: recipients: type: array minItems: 1 - description: URN of the recipient, could be a User URN or a Role URN example: - urn:pm:users:pm.demo:user/1234-123456-123456-1234 - urn:pm:users:pm.demo:role/customer items: - description: Uniform Resource Name example: urn:pm:service::foobar/d9a6fc2e-a4b3-4fba-9f20-c5bd2fdb5071 pattern: ^urn:[\w-]+:[\w.-]*:[\w.-]*:[\w-]+\/[^\/]+$ type: string subject: - description: Subject of the notification type: string message: type: string - description: Message to use for the notification enum: - UserCreated - ProjectCreated @@ -403,22 +399,18 @@ components: recipients: type: array minItems: 1 - description: URN of the recipient, could be a User URN or a Role URN example: - urn:pm:users:pm.demo:user/1234-123456-123456-1234 - urn:pm:users:pm.demo:role/customer items: - description: Uniform Resource Name example: urn:pm:service::foobar/d9a6fc2e-a4b3-4fba-9f20-c5bd2fdb5071 pattern: ^urn:[\w-]+:[\w.-]*:[\w.-]*:[\w-]+\/[^\/]+$ type: string subject: - description: Subject of the notification type: string message: type: string - description: Message to use for the notification enum: - UserCreated - ProjectCreated diff --git a/tests/openapi/simple_target.yml b/tests/openapi/simple_target.yml index f799e7d..4d4c1a1 100644 --- a/tests/openapi/simple_target.yml +++ b/tests/openapi/simple_target.yml @@ -7,7 +7,6 @@ components: example: 500 type: integer incident: - description: Unique incident identifier example: 5beb965c-7ffc-468b-a063-eb47c5b366c2 type: string message: @@ -25,7 +24,6 @@ components: example: 400 type: integer incident: - description: Unique incident identifier example: 5beb965c-7ffc-468b-a063-eb47c5b366c2 type: string message: @@ -43,7 +41,6 @@ components: example: 404 type: integer incident: - description: Unique incident identifier example: 5beb965c-7ffc-468b-a063-eb47c5b366c2 type: string message: @@ -112,7 +109,6 @@ components: format: date-time type: string pingBy: - description: Unique user identifier example: user@server.com type: string priority: @@ -184,7 +180,6 @@ components: format: date-time type: string pingBy: - description: Unique user identifier example: user@server.com type: string priority: