cloudformation-cli icon indicating copy to clipboard operation
cloudformation-cli copied to clipboard

Resource generation outstanding issues

Open johnttompkins opened this issue 7 years ago • 2 comments

The current resource generator in #104 handles simpler cases of resource generation. The below items are necessary to bring the generator to a more operable state that can handle most if not all valid resource definition schemas.

  • [x] Refs are not handled. This is fine, but needs some kind of step prior to make sure it works
  • [ ] Type keywords. Keywords that can be specified in jsonschema draft 07 for primitive types should be accounted for in resource generation. #104 handles some of this but not all (e.g. minLength and maxLength is not supported for arrays).
  • [ ] Assuming type is a string. We assume the schema type is a string and cannot be an array. Arrays are valid values for type keys and we need to generate values based off all of the types listed.
  • [ ] String formats. jsonschema has a "format" keyword that allows for specific string formats like json pointers, domain names, email addresses, etc. that should be able to be generated by the resource generator. The logic to do this is in place, but we need to construct regular expression strategies that we can map to format names.
  • [x] Options to generate more than the required properties. Currently the generator only generates those that are required. Having an option to generate a maximal set of properties would be beneficial for testing the robustness of handlers.
  • [x] Combiners. Currently allOf and anyOf are not supported by the generator. anyOf should be a simple addition because it is handled in the same way as oneOf. allOf will require to merge the child schemas.
  • [x] Const and enum. Constant values and enum schemas are not supported currently.
  • [x] Needs to only generate a resource blob (i.e. the stuff under properties)
  • [x] Refactor generation functions for readability.
  • [ ] https://github.com/aws-cloudformation/cloudformation-cli/issues/287

Also, some research needs to be done to see if the flattener and resource generator can be combined in some way. They are both walking the schema in a similar way, so it would be nice to remove duplicate implementations of this to lessen the amount of code to be maintained.

johnttompkins avatar Nov 20 '18 20:11 johnttompkins

Relating to type is string / type keywords, here's the trace for when type is an array of simpleTypes:

[2019-12-09T03:35:45Z] DEBUG    - Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/rpdk/core/cli.py", line 98, in main
    args.command(args)
  File "/usr/local/lib/python3.7/site-packages/rpdk/core/generate.py", line 15, in generate
    project.generate()
  File "/usr/local/lib/python3.7/site-packages/rpdk/core/project.py", line 243, in generate
    return self._plugin.generate(self)
  File "/usr/local/lib/python3.7/site-packages/rpdk/go/codegen.py", line 151, in generate
    contents = template.render(models=models)
  File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.7/site-packages/rpdk/go/templates/types.go.tple", line 18, in top-level template code
    {{ name|uppercase_first_letter }} {{ type|translate_type }} `json:"{{ name }},omitempty"`
  File "/usr/local/lib/python3.7/site-packages/rpdk/go/resolver.py", line 16, in translate_type
    return PRIMITIVE_TYPES[resolved_type.type]
TypeError: unhashable type: 'list'

iann0036 avatar Dec 09 '19 03:12 iann0036

We should investigate https://pypi.org/project/hypothesis-jsonschema/


update: test resource generation itself was unfortunately mostly abandoned for years (until some regex work in https://github.com/aws-cloudformation/cloudformation-cli/pull/930, https://github.com/aws-cloudformation/cloudformation-cli/issues/939) in favor of developers providing hardcoded property values

PatMyron avatar Jun 01 '21 21:06 PatMyron