def _generate_restapi()

in chalice/package.py [0:0]


    def _generate_restapi(self, resource, template):
        # type: (models.RestAPI, Dict[str, Any]) -> None

        # typechecker happiness
        swagger_doc = cast(Dict, resource.swagger_doc)
        template['locals']['chalice_api_swagger'] = json.dumps(
            swagger_doc)

        template['resource'].setdefault('aws_api_gateway_rest_api', {})[
            resource.resource_name] = {
            'body': '${local.chalice_api_swagger}',
            # Terraform will diff explicitly configured attributes
            # to the current state of the resource. Attributes configured
            # via swagger on the REST api need to be duplicated here, else
            # terraform will set them back to empty.
            'name': swagger_doc['info']['title'],
            'binary_media_types': swagger_doc[
                'x-amazon-apigateway-binary-media-types'],
            'endpoint_configuration': {'types': [resource.endpoint_type]}
        }

        if 'x-amazon-apigateway-policy' in swagger_doc:
            template['resource'][
                'aws_api_gateway_rest_api'][
                resource.resource_name]['policy'] = json.dumps(
                swagger_doc['x-amazon-apigateway-policy'])
        if resource.minimum_compression.isdigit():
            template['resource'][
                'aws_api_gateway_rest_api'][
                resource.resource_name][
                'minimum_compression_size'] = int(
                resource.minimum_compression)

        template['resource'].setdefault('aws_api_gateway_deployment', {})[
            resource.resource_name] = {
            'stage_name': resource.api_gateway_stage,
            # Ensure that the deployment gets redeployed if we update
            # the swagger description for the api by using its checksum
            # in the stage description.
            'stage_description': (
                "${md5(local.chalice_api_swagger)}"),
            'rest_api_id': '${aws_api_gateway_rest_api.%s.id}' % (
                resource.resource_name),
            'lifecycle': {'create_before_destroy': True}
        }

        template['resource'].setdefault('aws_lambda_permission', {})[
            resource.resource_name + '_invoke'] = {
            'function_name': self._fref(resource.lambda_function),
            'action': 'lambda:InvokeFunction',
            'principal': self._options.service_principal('apigateway'),
            'source_arn':
                "${aws_api_gateway_rest_api.%s.execution_arn}/*" % (
                    resource.resource_name)
        }

        template.setdefault('output', {})[
            'EndpointURL'] = {
            'value': '${aws_api_gateway_deployment.%s.invoke_url}' % (
                resource.resource_name)
        }
        template.setdefault('output', {})[
            'RestAPIId'] = {
            'value': '${aws_api_gateway_rest_api.%s.id}' % (
                resource.resource_name)
        }

        for auth in resource.authorizers:
            template['resource']['aws_lambda_permission'][
                auth.resource_name + '_invoke'] = {
                'function_name': self._fref(auth),
                'action': 'lambda:InvokeFunction',
                'principal': self._options.service_principal('apigateway'),
                'source_arn': (
                    "${aws_api_gateway_rest_api.%s.execution_arn}" % (
                        resource.resource_name) + "/*"
                )
            }
        self._add_domain_name(resource, template)