def add_disable_execute_api_endpoint_extension()

in samtranslator/swagger/swagger.py [0:0]


    def add_disable_execute_api_endpoint_extension(self, disable_execute_api_endpoint: PassThrough) -> None:
        """Add endpoint configuration to _X_APIGW_ENDPOINT_CONFIG in open api definition as extension
        Following this guide:
        https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-endpoint-configuration.html
        :param boolean disable_execute_api_endpoint: Specifies whether clients can invoke your API by using the default execute-api endpoint.
        """

        disable_execute_api_endpoint_path = f"{self._X_ENDPOINT_CONFIG}.{self._DISABLE_EXECUTE_API_ENDPOINT}"

        # Check if the OpenAPI version is 3.0, if it is then the extension needs to added to the Servers field,
        # if not then it gets added to the top level (same level as "paths" and "info")
        if self._doc.get("openapi") and self.validate_open_api_version_3(self._doc["openapi"]):
            # Add the x-amazon-apigateway-endpoint-configuration extension to the Servers objects
            servers_configurations = self._doc.get(self._SERVERS, [Py27Dict()])
            for index, config in enumerate(servers_configurations):
                try:
                    dict_deep_set(config, disable_execute_api_endpoint_path, disable_execute_api_endpoint)
                except InvalidValueType as ex:
                    raise InvalidDocumentException(
                        [InvalidTemplateException(f"Invalid OpenAPI definition of '{self._SERVERS}[{index}]': {ex!s}.")]
                    ) from ex

            self._doc[self._SERVERS] = servers_configurations
        else:
            try:
                dict_deep_set(self._doc, disable_execute_api_endpoint_path, disable_execute_api_endpoint)
            except InvalidValueType as ex:
                raise InvalidDocumentException(
                    [InvalidTemplateException(f"Invalid OpenAPI definition: {ex!s}.")]
                ) from ex