def _add_description(self):
        """Add description to DefinitionBody if Description property is set in SAM"""
        if not self.description:
            return

        if not self.definition_body:
            raise InvalidResourceException(
                self.logical_id,
                "Description works only with inline OpenApi specified in the 'DefinitionBody' property.",
            )
        if self.definition_body.get("info", {}).get("description"):
            raise InvalidResourceException(
                self.logical_id,
                "Unable to set Description because it is already defined within inline OpenAPI specified in the "
                "'DefinitionBody' property.",
            )

        open_api_editor = OpenApiEditor(self.definition_body)
        open_api_editor.add_description(self.description)
        self.definition_body = open_api_editor.openapi
Exemple #2
0
 def test_must_not_add_description_if_already_defined(self):
     editor = OpenApiEditor(self.original_openapi_with_description)
     editor.add_description("New Description")
     self.assertEqual(editor.openapi["info"]["description"], "Existing Description")