scaffolder: sample templates should validate component name properly
See original GitHub issueExpected Behavior
Components created through our sample templates should always be possible to register in the catalog using the default validation rules.
Current Behavior
The validation of the entity name in our sample templates is too lax, for example allowing spaces. This will break the catalog registration step when creating the new component.
Possible Solution
Validate the name field in our sample templates using the same Regex as entity names are validated by, for example here: https://github.com/backstage/backstage/blob/13f5d78b0bb079030c9c8d1d58cea2bb6bacfa38/plugins/scaffolder-backend/sample-templates/react-ssr-template/template.yaml#L20
Steps to Reproduce
- Try to create a component called
A B C
- Wait for scaffolder job to complete, which it will do succesfully
- Try to find the component in the catalog, it’s not there. Check backend logs for error:
Policy check failed; caused by Error: "metadata.name" is not valid; expected a string that is sequences of [a-zA-Z0-9] separated by any of [-_.], at most 63 characters in total but found "A B C"
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Writing Templates · Backstage Software Catalog and ...
Templates are stored in the Software Catalog under a kind Template . You can create your own templates with a small yaml definition...
Read more >[RFC] Next Steps for the Scaffolder · Issue #2771 - GitHub
My concern though is when you have multiple of these steps in one template and one calls it component_id , another component-id and...
Read more >Writing scaffolder templates - Roadie.io
Here is an example of a very basic Scaffolder template that ... would like a little validation when the user enters an Entity...
Read more >Scaffolding — Ferris Framework 2.1.0 documentation
Scaffolding can provide you with common CRUD functionality very quickly, ... It uses scaffold.singular as the template variable name. For example, if you're ......
Read more >Scaffold generator does not generate stories or tests
After generating several scaffolds for our app, I noticed that it generates very little testing and no stories.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@regicsolutions great suggestions, thanks! There’s definitely more we can do with respect to support for improved validation errors in general, especially when it comes to fields that are validated via the
pattern
property. I’d love to explore in particular how we can provide a generalized implementation oftransformErrors
that allows providing a custom error message alongside the pattern itself in the schema.For entity names specifically, I don’t think using a pattern in the templates is the right solution. Entity names are always validated the same way in a given Backstage instance, so spreading the validation rules across all the templates creates unnecessary duplication. It also prevents us from reusing the catalog validation code itself when validating entity names.
Adding the pattern used to validate entity names results in pretty ugly error messages (see screenshot below), and by copying it into the template we also leave ourselves open to the risk that the requirements for entity names change and leave the templates out of sync.
Is it perhaps worth considering introducing a new UI field for names that bakes in validation and friendly error messages?