Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ajv-errors for scaffolder validation #23435

Closed

Conversation

mbenson
Copy link
Contributor

@mbenson mbenson commented Mar 6, 2024

Hey, I just made a Pull Request!

First pass for discussion on issue #22575 . I'd love some guidance on how to formally test these changes.

I will attempt a pass at the documentation, but for now the items of note:

  • All levels of the UI schema are searched for ui:message with message template overrides for the encountered validation error
  • "message template" because embedded @{{ }} sequences may refer to the original, rewritten error object as err to support the case that the original message or other data should be exposed in the custom message.

Here is a sample template to exercise the functionality:

apiVersion: scaffolder.backstage.io/v1beta3
kind: Template

metadata:
  name: foo
  title: Foo
  description: FOO

spec:
  owner: user:bruiser
  type: testing

  parameters:
    - title: Strings
      required:
        - foo
        - bar
      properties:
        foo:
          title: Foo
          description: FOO
          type: string
          pattern: foo
          default: foo
          ui:message:
            pattern: WTF
        bar:
          title: Bar
          description: BAR
          type: string
          pattern: bar
          default: bar
        notBaz:
          title: notBaz
          description: NOT BAZ
          type: string
          not:
            pattern: baz
      ui:message:
        bar:
          pattern: WTAF
        notBaz:
          not: BAZ (@{{ err.message }})
    - title: Arrays
      properties:
        s:
          type: array
          items:
            type: string
            pattern: .{2,}
            ui:message:
              pattern: must be at least 2 characters (@{{ err.message }})
    - title: Nested
      properties:
        o:
          type: object
          properties:
            n:
              type: number
              multipleOf: 2
            a:
              type: array
              items:
                type: object
                properties:
                  s:
                    type: string
                    pattern: .{2,}
              ui:message:
                items:
                  s:
                    pattern: too short (@{{err.message}})
          ui:message:
            n:
              multipleOf: even only, dummy
  steps:
    - id: logstuff
      name: Log Stuff
      action: debug:log
      input:
        message: Nothing to see here

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@mbenson mbenson requested review from a team as code owners March 6, 2024 23:45
@github-actions github-actions bot added the area:scaffolder Everything and all things related to the scaffolder project area label Mar 6, 2024
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented Mar 6, 2024

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-scaffolder-react plugins/scaffolder-react patch v1.9.0

Copy link
Contributor

github-actions bot commented Mar 6, 2024

Uffizzi Ephemeral Environment - Virtual Cluster

Your cluster pr-23435 was successfully created. Learn more about Uffizzi virtual clusters
To connect to this cluster, follow these steps:

  1. Download and install the Uffizzi CLI from https://docs.uffizzi.com/install
  2. Login to Uffizzi, then select the backstage account and project:
uffizzi login
Select an account: 
  ‣ backstage
    jdoe

Select a project or create a new project: 
  ‣ backstage-6783521
  1. Update your kubeconfig: uffizzi cluster update-kubeconfig pr-23435 --kubeconfig=[PATH_TO_KUBECONFIG]
    After updating your kubeconfig, you can manage your cluster with kubectl, kustomize, helm, and other tools that use kubeconfig files: kubectl get namespace --kubeconfig [PATH_TO_KUBECONFIG]

Access the backstage endpoint at https://backstage-default-pr-23435-c5333.uclusters.app.uffizzi.com

@benjdlambert
Copy link
Member

See this comment too: #23283 (comment)

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 7, 2024
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Mar 14, 2024
@mbenson
Copy link
Contributor Author

mbenson commented Mar 15, 2024

bump, awaiting direction from Backstage team

@mbenson
Copy link
Contributor Author

mbenson commented Mar 15, 2024

not stale

@github-actions github-actions bot removed the stale label Mar 15, 2024
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Mar 22, 2024
@mbenson
Copy link
Contributor Author

mbenson commented Mar 22, 2024 via email

@github-actions github-actions bot removed the stale label Mar 22, 2024
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Mar 29, 2024
@freben freben removed the stale label Mar 29, 2024
@freben
Copy link
Member

freben commented Mar 29, 2024

Sorry that this is taking time. You've caught me in a pretty bad time, with KubeCon/BackstageCon, a large and important release, and PTO time all conspiring to make the review queue grow. I haven't forgotten you.

Copy link
Contributor

github-actions bot commented Apr 5, 2024

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Apr 5, 2024
@freben freben removed the stale label Apr 8, 2024
Copy link
Member

@freben freben left a comment

Choose a reason for hiding this comment

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

Mm right handing this over to the scaffolder maintainers to see how they feel about the templating and stuff

plugins/scaffolder-react/src/next/components/Form/Form.tsx Outdated Show resolved Hide resolved
@freben freben removed the documentation Improvements or additions to documentation label Apr 8, 2024
@freben freben requested a review from benjdlambert April 8, 2024 13:11
@mbenson mbenson force-pushed the issue-22575-template-param-errors branch from dec3fbe to d993d8a Compare April 8, 2024 17:57
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Apr 8, 2024
@mbenson mbenson force-pushed the issue-22575-template-param-errors branch from d993d8a to f42f31b Compare April 9, 2024 16:49
@mbenson
Copy link
Contributor Author

mbenson commented Apr 9, 2024

Mm right handing this over to the scaffolder maintainers to see how they feel about the templating and stuff

Note that this PR is also blocked by #23893 .

@mbenson mbenson force-pushed the issue-22575-template-param-errors branch from f42f31b to 43f780e Compare April 17, 2024 18:04
@lulala1126
Copy link

Hi @mbenson, I really appreciate this feature PR, as I'm also waiting for this feature.
I've also looked at how to add a custom error message in react-jsonschema-form.
It looks like in addition to the methods supported by react itself (custom-error-messages) https://rjsf-team.github.io/react-jsonschema-form/docs/usage/validation/#custom-error- messages, the ajv it dependencies on already supports custom error messages (rjsf-team/react-jsonschema-form#4119). so would you mind looking into that option? 🙏 CC @hulu-xu

@mbenson mbenson force-pushed the issue-22575-template-param-errors branch 2 times, most recently from 374f7e1 to a2c748b Compare May 3, 2024 19:06
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label May 29, 2024
@freben freben removed the stale label May 29, 2024
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Jun 12, 2024
@freben freben removed the stale label Jun 14, 2024
Signed-off-by: Matt Benson <gudnabrsam@gmail.com>
Signed-off-by: Matt Benson <gudnabrsam@gmail.com>
@mbenson mbenson force-pushed the issue-22575-template-param-errors branch from a2c748b to 9cc95ce Compare June 18, 2024 22:46
Copy link
Contributor

github-actions bot commented Jul 2, 2024

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Jul 2, 2024
@github-actions github-actions bot closed this Jul 9, 2024
@mbenson
Copy link
Contributor Author

mbenson commented Jul 10, 2024 via email

@mbenson
Copy link
Contributor Author

mbenson commented Jul 13, 2024

Hi @mbenson, I really appreciate this feature PR, as I'm also waiting for this feature. I've also looked at how to add a custom error message in react-jsonschema-form. It looks like in addition to the methods supported by react itself (custom-error-messages) https://rjsf-team.github.io/react-jsonschema-form/docs/usage/validation/#custom-error- messages, the ajv it dependencies on already supports custom error messages (rjsf-team/react-jsonschema-form#4119). so would you mind looking into that option? 🙏 CC @hulu-xu

@lulala1126 I forgot to look at this when you first mentioned it, but I [think I] agree that it makes more sense to leverage ajv-errors for this functionality, a possible caveat being that the ${} backref syntax supported by ajv-errors could potentially "sidestep" whatever nested template construct arises from #23893 @benjdlambert .

@benjdlambert
Copy link
Member

@mbenson im out on holiday at the minute, but I'll reopen this before I forget the ping.

I like the direction of using ajv-errors if we can, and using their syntax if possible. Maybe can promote that through the bep too.

More on this when I get back late next week.

@benjdlambert
Copy link
Member

Im fact I can't reopen it for some reason? 😅

@mbenson mbenson changed the title consult ui:message schema properties for custom validation messages support ajv-errors for scaffolder validation Jul 14, 2024
@mbenson
Copy link
Contributor Author

mbenson commented Jul 14, 2024

I'll just open a new PR with the ajv-errors impl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:scaffolder Everything and all things related to the scaffolder project area documentation Improvements or additions to documentation stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants