Instantiation of patterns: generation from a pattern file, or pre-written template files? #71
Closed
willosborne
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
@rocketstack-matt @jpgough-ms Interested in your thoughts here |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As we think about instantiating patterns for the CALM CLI proposed in Issue #53, we have a couple of options. Wanted to get people's opinions on how to approach this.
What do people think?
Option 1: Generate an instantiation by inspecting the pattern file
This is a flexible approach that takes a pattern, traverses the spec and generates a JSON file as output.
For example, if it sees a property with
... it would simply insert this into the generated text.
If it saw a type with no value specified a placeholder such as
{{ PROPERTY_NAME }}
would be inserted so we can easily template later.One library that looks promising here is the
json-schema-faker
library here that takes a schema and generates a JSON document. Our use case isn't exactly the same from a quick look at the docs but this is worth investigating.Option 2: Pattern files come with a template for instantiating it
In this model a pattern is two files: the pattern itself as a JSON schema, and an instantiation of the pattern with {{ PLACEHOLDER }} values in all the slots that needs to be filled.
This is a lot simpler, but requires two files. This would make fetching the pattern from some kind of schema repository more complex. Pattern files could also potentially reference their template.
It also requires maintenance to ensure there is no drift between the instantiation and the template.
Beta Was this translation helpful? Give feedback.
All reactions