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

Dereference option schemas before giving it as props to anyOf and oneOf #2270

Closed
wants to merge 6 commits into from

Conversation

NixBiks
Copy link
Contributor

@NixBiks NixBiks commented Mar 10, 2021

Reasons for making this change

Fixes #2016 and #1819

If this is related to existing tickets, include links to them as well.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests
    • I've updated docs if needed
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@@ -132,7 +132,10 @@ class AnyOfField extends Component {
}

const enumOptions = options.map((option, index) => ({
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to instead just set option = retrieveSchema(option, registry.rootSchema) earlier in this function, so that everything related to the option is already dereferenced (this might fix other bugs with oneOf / refs)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I guess I'll update the samples as well then since this will ignore any title that is a sibling to a $ref.

Actually; if you look the reference sample. There you have a reference to the same schema but with different titles. That wouldn't be possible if we changed like above. We could implement your suggestion but still look for title in the $ref schema.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved the logic to SchemaField instead, so props.options are now dereferenced. That also fixes #1819

@NixBiks
Copy link
Contributor Author

NixBiks commented Mar 11, 2021

@epicfaace I've now updated the options so they are all dereferenced from the beginning.

I have an issue running npm start though - it succeeded once yesterday (out of many tries) but today it doesn't work again. Is there some race condition? Do you know what could be the issue?

@rjsf/playground: Entrypoint main = main.js main.fd9ed9f11cef66249b22.hot-update.js main.js.map main.fd9ed9f11cef66249b22.hot-update.js.map
@rjsf/playground: [../antd/dist/es/index.js] 162 bytes {main} [built] [failed] [1 error]
@rjsf/playground: [../bootstrap-4/dist/index.js] 166 bytes {main} [built] [failed] [1 error]
@rjsf/playground: [../core/dist/es/index.js] 162 bytes {main} [built] [failed] [1 error]
@rjsf/playground: [../fluent-ui/dist/index.js] 164 bytes {main} [built] [failed] [1 error]
@rjsf/playground: [../material-ui/dist/index.js] 166 bytes {main} [built] [failed] [1 error]
@rjsf/playground:     + 1927 hidden modules
@rjsf/playground: ERROR in ../antd/dist/es/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/antd/dist/es/index.js'
@rjsf/playground:  @ ./src/index.js 5:0-48 76:11-20
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: ERROR in ../bootstrap-4/dist/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/bootstrap-4/dist/index.js'
@rjsf/playground:  @ ./src/index.js 6:0-61 88:11-26
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: ERROR in ../core/dist/es/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/core/dist/es/index.js'
@rjsf/playground:  @ ./src/app.js 19:0-45 361:29-33 385:29-33 545:23-32 630:21-30 704:29-33
@rjsf/playground:  @ ./src/index.js
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: ERROR in ../fluent-ui/dist/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/fluent-ui/dist/index.js'
@rjsf/playground:  @ ./src/index.js 3:0-57 84:11-24
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: ERROR in ../material-ui/dist/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/material-ui/dist/index.js'
@rjsf/playground:  @ ./src/index.js 2:0-54 72:11-19
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: Child html-webpack-plugin for "index.html":
@rjsf/playground:                                    Asset      Size  Chunks             Chunk Names
@rjsf/playground:     54a49ead881005d0f02e.hot-update.json  44 bytes          [emitted]  
@rjsf/playground:      + 1 hidden asset
@rjsf/playground:     Entrypoint undefined = index.html
@rjsf/playground:        4 modules
@rjsf/playground: Child vs/editor/editor:
@rjsf/playground:      2 assets
@rjsf/playground:     Entrypoint main = editor.worker.js editor.worker.js.map
@rjsf/playground:        37 modules
@rjsf/playground: Child vs/language/json/jsonWorker:
@rjsf/playground:      2 assets
@rjsf/playground:     Entrypoint main = json.worker.js json.worker.js.map
@rjsf/playground:        62 modules
@rjsf/playground: ℹ 「wdm」: Failed to compile.

Those no such file errors puzzles me - the files are indeed there (I can even navigate to them by pressing those links)

@NixBiks NixBiks changed the title fix: title from refs schema before fallback value Dereference option schemas before giving it as props to anyOf and oneOf Mar 12, 2021
@epicfaace
Copy link
Member

epicfaace commented Mar 14, 2021

@epicfaace I've now updated the options so they are all dereferenced from the beginning.

I have an issue running npm start though - it succeeded once yesterday (out of many tries) but today it doesn't work again. Is there some race condition? Do you know what could be the issue?

@rjsf/playground: Entrypoint main = main.js main.fd9ed9f11cef66249b22.hot-update.js main.js.map main.fd9ed9f11cef66249b22.hot-update.js.map
@rjsf/playground: [../antd/dist/es/index.js] 162 bytes {main} [built] [failed] [1 error]
@rjsf/playground: [../bootstrap-4/dist/index.js] 166 bytes {main} [built] [failed] [1 error]
@rjsf/playground: [../core/dist/es/index.js] 162 bytes {main} [built] [failed] [1 error]
@rjsf/playground: [../fluent-ui/dist/index.js] 164 bytes {main} [built] [failed] [1 error]
@rjsf/playground: [../material-ui/dist/index.js] 166 bytes {main} [built] [failed] [1 error]
@rjsf/playground:     + 1927 hidden modules
@rjsf/playground: ERROR in ../antd/dist/es/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/antd/dist/es/index.js'
@rjsf/playground:  @ ./src/index.js 5:0-48 76:11-20
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: ERROR in ../bootstrap-4/dist/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/bootstrap-4/dist/index.js'
@rjsf/playground:  @ ./src/index.js 6:0-61 88:11-26
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: ERROR in ../core/dist/es/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/core/dist/es/index.js'
@rjsf/playground:  @ ./src/app.js 19:0-45 361:29-33 385:29-33 545:23-32 630:21-30 704:29-33
@rjsf/playground:  @ ./src/index.js
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: ERROR in ../fluent-ui/dist/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/fluent-ui/dist/index.js'
@rjsf/playground:  @ ./src/index.js 3:0-57 84:11-24
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: ERROR in ../material-ui/dist/index.js
@rjsf/playground: Module build failed: Error: ENOENT: no such file or directory, open '/home/nixd/Projects/react-jsonschema-form/packages/material-ui/dist/index.js'
@rjsf/playground:  @ ./src/index.js 2:0-54 72:11-19
@rjsf/playground:  @ multi ./src/index
@rjsf/playground: Child html-webpack-plugin for "index.html":
@rjsf/playground:                                    Asset      Size  Chunks             Chunk Names
@rjsf/playground:     54a49ead881005d0f02e.hot-update.json  44 bytes          [emitted]  
@rjsf/playground:      + 1 hidden asset
@rjsf/playground:     Entrypoint undefined = index.html
@rjsf/playground:        4 modules
@rjsf/playground: Child vs/editor/editor:
@rjsf/playground:      2 assets
@rjsf/playground:     Entrypoint main = editor.worker.js editor.worker.js.map
@rjsf/playground:        37 modules
@rjsf/playground: Child vs/language/json/jsonWorker:
@rjsf/playground:      2 assets
@rjsf/playground:     Entrypoint main = json.worker.js json.worker.js.map
@rjsf/playground:        62 modules
@rjsf/playground: ℹ 「wdm」: Failed to compile.

Those no such file errors puzzles me - the files are indeed there (I can even navigate to them by pressing those links)

Thanks. Yeah, it might be a race condition. Try running npm run build before npm start and then hopefully the issue will be fixed. You could also edit a file in the playground folder, which should probably reload the code and get the right files.

@epicfaace epicfaace closed this Mar 14, 2021
@epicfaace epicfaace reopened this Mar 14, 2021
@NixBiks
Copy link
Contributor Author

NixBiks commented Mar 15, 2021

I'll close this in favour of #2272

@NixBiks NixBiks closed this Mar 15, 2021
epicfaace added a commit that referenced this pull request Apr 13, 2021
… contain references (#2272)

* fix: title from refs schema before fallback value

* Added test for #2270

* After review

* Add formData when dereferencing

* Moved logic to SchemaField, so props.options are already dereferenced

* Removed wrong comment

* Fix: refs should be included when determining matching option
based on formData

* Integrated tests from PR #2245

* Added a new test

* Updated tests after review

* Update isValid to take rootSchema

* * use global ajv in isValid
* simplify withIdRefPrefix
* add comments
* improve error handling

* Added test and fixed withIdRefPrefix for arrays

* * Cleaned up
* Fixed bug with $ref being a property
* added tests for withIdRefPrefix

* * Clean up
* Check for # in ref
* update tests

* Added upgrade note

* Change title of test in validate_test

Co-authored-by: Ashwin Ramaswami <[email protected]>

* Change title of test in validate_test

Co-authored-by: Ashwin Ramaswami <[email protected]>

* Added test with ref within properties

Co-authored-by: Ashwin Ramaswami <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Titles in refs are not incorporated when constructing allOf/oneOf/anyOf dropdowns
2 participants