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

🐛 Bug Report: scaffolder/next setting defaults doesn't always work #20055

Closed
2 tasks done
nBerg opened this issue Sep 20, 2023 · 13 comments
Closed
2 tasks done

🐛 Bug Report: scaffolder/next setting defaults doesn't always work #20055

nBerg opened this issue Sep 20, 2023 · 13 comments
Assignees
Labels
area:scaffolder Everything and all things related to the scaffolder project area bug Something isn't working

Comments

@nBerg
Copy link
Contributor

nBerg commented Sep 20, 2023

📜 Description

I'm looking into switching over to scaffolder/next specifically to use the if/then syntax, but running into an issue where defaults are not respected for properties in the "then" block.

👍 Expected behavior

Defaults for properties in the "then" block should be set

👎 Actual Behavior with Screenshots

Default was not set as expected:
Screenshot 2023-09-20 at 12 59 30 PM

👟 Reproduction steps

Here is an example of this working in the RJSF playground

Here is an example of a scaffolder template that does not work as expected:

apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: example-if-then
  title: example-if-then
spec:
  type: service
  parameters:
    - title: Example
      type: object
      properties:
        animalInfo: # This is unrelated, but for some reason this is needed in scaffolder, but not RJSF?
          properties:
            animal:
              type: string
              default: Cat # This default works as expected
              enum:
              - Cat
              - Fish
          allOf:
            - if:
                properties:
                  animal:
                    const: Cat
              then:
                properties:
                  food:
                    type: string
                    default: meat # This default does not work as expected
                    enum:
                    - meat
                    - grass
                    - fish
                required:
                - food
            - if:
                properties:
                  animal:
                    const: Fish
              then:
                properties:
                  food:
                    type: string
                    enum:
                    - insect
                    - worms
                  water:
                    type: string
                    enum:
                    - lake
                    - sea
                required:
                - food
                - water
            - required:
              - animal
  steps: []

📃 Provide the context for the Bug.

I'm trying to use the if/then syntax with defaults for some of the "then" properties. This works today using the "oneOf" syntax as described here. I'm looking into switching to scaffolder/next and using the if/else syntax for a few reasons, but primarily to fix this bug with duplicate validation errors.

🖥️ Your Environment

browser: Chrome Version 116.0.5845.187

❯ yarn backstage-cli info
yarn run v1.22.19
$ /Users/berg/code/flex/developer-home/node_modules/.bin/backstage-cli info
OS:   Darwin 22.6.0 - darwin/arm64
node: v18.14.2
yarn: 1.22.19
cli:  0.22.12 (installed)
backstage:  1.17.5

Dependencies:
  @backstage/app-defaults                                        1.4.2
  @backstage/backend-app-api                                     0.5.2
  @backstage/backend-common                                      0.19.4
  @backstage/backend-dev-utils                                   0.1.1
  @backstage/backend-openapi-utils                               0.0.3
  @backstage/backend-plugin-api                                  0.6.2
  @backstage/backend-tasks                                       0.5.7
  @backstage/catalog-client                                      1.4.3
  @backstage/catalog-model                                       1.4.1
  @backstage/cli-common                                          0.1.12
  @backstage/cli-node                                            0.1.3
  @backstage/cli                                                 0.22.12
  @backstage/config-loader                                       1.4.0
  @backstage/config                                              1.0.8
  @backstage/core-app-api                                        1.9.1
  @backstage/core-components                                     0.13.4
  @backstage/core-plugin-api                                     1.5.3
  @backstage/dev-utils                                           1.0.20
  @backstage/errors                                              1.2.1
  @backstage/eslint-plugin                                       0.1.3
  @backstage/integration-aws-node                                0.1.5
  @backstage/integration-react                                   1.1.18
  @backstage/integration                                         1.6.2
  @backstage/plugin-app-backend                                  0.3.50
  @backstage/plugin-app-node                                     0.1.2
  @backstage/plugin-auth-backend                                 0.18.8
  @backstage/plugin-auth-node                                    0.2.19
  @backstage/plugin-catalog-backend-module-incremental-ingestion 0.4.5
  @backstage/plugin-catalog-backend-module-msgraph               0.5.9
  @backstage/plugin-catalog-backend                              1.12.4
  @backstage/plugin-catalog-common                               1.0.15
  @backstage/plugin-catalog-graph                                0.2.35
  @backstage/plugin-catalog-import                               0.9.13
  @backstage/plugin-catalog-node                                 1.4.3
  @backstage/plugin-catalog-react                                1.8.3
  @backstage/plugin-catalog                                      1.12.4
  @backstage/plugin-events-node                                  0.2.11
  @backstage/plugin-github-actions                               0.6.4
  @backstage/plugin-home-react                                   0.1.2
  @backstage/plugin-home                                         0.5.7
  @backstage/plugin-org                                          0.6.13
  @backstage/plugin-permission-common                            0.7.7
  @backstage/plugin-permission-node                              0.7.13
  @backstage/plugin-permission-react                             0.4.14
  @backstage/plugin-proxy-backend                                0.3.2
  @backstage/plugin-scaffolder-backend                           1.16.5
  @backstage/plugin-scaffolder-common                            1.4.0
  @backstage/plugin-scaffolder-node                              0.2.2
  @backstage/plugin-scaffolder-react                             1.5.4
  @backstage/plugin-scaffolder                                   1.14.4
  @backstage/plugin-search-backend-module-catalog                0.1.6
  @backstage/plugin-search-backend-module-pg                     0.5.11
  @backstage/plugin-search-backend-node                          1.2.6
  @backstage/plugin-search-backend                               1.4.2
  @backstage/plugin-search-common                                1.2.5
  @backstage/plugin-search-react                                 1.6.4
  @backstage/plugin-search                                       1.3.6
  @backstage/plugin-user-settings                                0.7.8
  @backstage/release-manifests                                   0.0.9
  @backstage/test-utils                                          1.4.2
  @backstage/theme                                               0.4.1
  @backstage/types                                               1.1.0
  @backstage/version-bridge                                      1.0.4
✨  Done in 0.83s.

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Are you willing to submit PR?

None

@nBerg nBerg added the bug Something isn't working label Sep 20, 2023
@github-actions github-actions bot added the area:scaffolder Everything and all things related to the scaffolder project area label Sep 20, 2023
@solimant
Copy link
Contributor

solimant commented Nov 7, 2023

Hey @benjdlambert - it was cool meeting you yesterday at BackstageCon. Was wondering if you could have a look at this, if you have a chance. We think it would be a blocker for being able to able to use scaffolder/next fully. Please let me know if I should provide more context.

EDIT: Based on feedback from @nBerg, this seems to be a blocker for if/then.

@BryanSLam
Copy link
Contributor

Just to chime in this is still an issue on the latest version of Backstage which makes sense given the issue is still open, but in case anyone was curious.

Screenshot 2023-11-07 at 1 36 43 PM Screenshot 2023-11-07 at 1 37 58 PM

@BryanSLam
Copy link
Contributor

@benjdlambert Hey just bumping this again since I know you just got back from Kubecon and hoping to get this on your radar. Thanks!

@benjdlambert
Copy link
Member

Hey @BryanSLam thanks for the callout.

Yep this looks like it works in the upstream library just fine.

So I wonder if #21328 is going to help here.

@benjdlambert
Copy link
Member

Actually, I take that back, it doesn't work

Looks like it works when there's no theme applied, but when we apply the material-ui theme it breaks. I think that this is an issue with the upstream library, and we should create an issue there instead.

@benjdlambert
Copy link
Member

I made an issue: rjsf-team/react-jsonschema-form#3963

@benjdlambert
Copy link
Member

Turns out that it's a duplicate of another issue - I went ahead and created a PR to fix it: rjsf-team/react-jsonschema-form#3969

@solimant
Copy link
Contributor

That's great! Thank you very much, @benjdlambert 🙏🏼

@nBerg
Copy link
Contributor Author

nBerg commented Dec 6, 2023

Thank you @benjdlambert!

@benjdlambert
Copy link
Member

So the PR has been merged, however we'll want to create a PR to use the new options that was just released in 5.15. Does anyone want to whip up that PR? 🙏

@solimant
Copy link
Contributor

solimant commented Dec 7, 2023

@benjdlambert - thank you very much. Yes, of course, we're more than happy to open a PR. Could you just share a pointer on where to look? Does something like this suffice?
#21783

@Rugvip
Copy link
Member

Rugvip commented Dec 12, 2023

Closing as fixed

@Rugvip Rugvip closed this as completed Dec 12, 2023
@simonstamm
Copy link
Contributor

Hey there, I'm going to hijack this closed topic a bit because I found here what I was searching for. @nBerg mentioned in the code snippet This is unrelated, but for some reason this is needed in scaffolder, but not RJSF? and he's right. Without the extra something: properties: ... I get in the console:

could not merge subschemas in allOf:
 Error: Could not resolve values for path:"title". They are probably incompatible. Values: 

Is this intended or is there another solution that anyone knows of?

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 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants