Skip to content

feat: support openapi yaml include validation - #3882

Closed
NickHeap2 wants to merge 2 commits into
aws:developfrom
NickHeap2:develop
Closed

NickHeap2 wants to merge 2 commits into
aws:developfrom
NickHeap2:develop

Conversation

@NickHeap2

Copy link
Copy Markdown
Contributor

Which issue(s) does this change fix?

#3041
#3676

Why is this change necessary?

If you are using OpenAPI yaml specifications it makes sense to use them for the API DefinitionBody like this:

      DefinitionBody:
        'Fn::Transform':
          Name: AWS::Include
          Parameters:
            Location: openapi.yaml

Whilst this is valid in a template it is currently not supported by sam validate.

How does it address the issue?

This change detects this pattern and replaces the DefinitionBody with the actual contents of the file allowing the validation to succeed.
This PR also includes tests to make sure that it copes with Locations that are not strings as per #3676.

What side effects does this change have?

Potentially someone could be relying on the existing behaviour where it fails for this pattern to prevent that pattern being used.

Checklist

  • Add input/output type hints to new functions/methods
  • Write design document (Do I need to write a design document?)
  • Write unit tests
  • Write/update functional tests
  • Write/update integration tests
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@aleguern

Copy link
Copy Markdown

I may be wrong but does it not miss a test with CORS enabled but without the DefinitionBody ?

@aleguern

Copy link
Copy Markdown

Any news on this @NickHeap2 ?

@NickHeap2

Copy link
Copy Markdown
Contributor Author

@aleguern last time after a week the bot applied the maintainer/need-response tag and then it got reviewed.

@torresxb1 torresxb1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your contribution!
Left a couple comments. Also, this is more of a nit, but could we make the names of tests/files specific (e.g. ...definition_body_include_local_path, ...definition_body_include_non_string, etc.)? Oh and, replacing none_string with non_string 🙏 🙏

Comment on lines +1 to +6
---
openapi: 3.0.0
paths:
/test:
get:
summary: Get test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this file needed, given that the template points to an intrinsic (which also resolves to s3 uri) and not a local file path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it in to make it clear that the test doesn't do the replace because it's not a simple string rather than because openapi.yaml doesn't exist. Will take it out though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for removing the file.

Comment on lines +61 to +63
("openapi_yaml", TemplateFileTypes.YAML), # project with template.yaml
("openapi_json", TemplateFileTypes.JSON), # project with template.json
("include_none_string", TemplateFileTypes.YAML), # project with template.yaml and none string include

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we should be adding these here. Seems like this test was meant for the default template (at least going by the name of the test), and also wouldn't these new tests be better suited for the functional tests like the other one you added (explicit_http_api_minimum_include.yaml) ?

@jfuss thoughts? (you had previously reviewed this PR but it got reverted and now this one addresses the issue)

resource_property_dict[property_key] = s3_uri_value

@staticmethod
def _replace_with_file_contents(resource_property_dict, location_prop):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the method seems generic but what it does is specific to API. Can you make the implementation generic?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add in docstring to this method as well as input parameter type hints!

Comment on lines +1 to +6
---
openapi: 3.0.0
paths:
/test:
get:
summary: Get test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for removing the file.


self.assertEqual(expected, result)

def test_payload_format_version_for_none(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test relevant to the change?

@hawflau

hawflau commented Jun 29, 2022

Copy link
Copy Markdown
Contributor

Hi @NickHeap2 would you be able to address the change requests?

@jfuss

jfuss commented Aug 9, 2022

Copy link
Copy Markdown
Contributor

Closing as inactive.

Happy to review an updated PR from the community, if someone wants to revive the PR

@jfuss jfuss closed this Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/validate sam validate command pr/external

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants