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

Allow references that don't start with #/definitions/ #1506

Merged
merged 22 commits into from
Feb 25, 2020
Merged

Allow references that don't start with #/definitions/ #1506

merged 22 commits into from
Feb 25, 2020

Conversation

epicfaace
Copy link
Member

@epicfaace epicfaace commented Nov 9, 2019

status

Ready for review. This PR introduces a few breaking changes:

  • We no longer support "recursive references to deep schema definitions" as mentioned before because that is not supported by the JSON pointer spec.
  • A new key, rootSchema, has been added to the registry. registry.definitions is still available, though, to ease compatibility.

original considerations

A few considerations:

  • We currently support definitions of the form #/definitions/. However, JSON Pointer standard says that absolute definition URLs should start with something like /definitions/ -- the former is only the "URI Fragment Identifier" representation of the JSON Pointer. However, Swagger does it the former way (starting with #). Not sure which one is best for us to go with? In the future, we might also want to support relative JSON Pointers, which is a consideration too.
  • This PR uses the jsonpointer library to resolve references. However, this changes the behavior for what I call "recursive references to deep schema definitions":

Consider the following schema:

{
      definitions: {
          testdef: {
            $ref: "#/definitions/testdefref",
          },
          testdefref: {
            type: "object",
            properties: {
              bar: { type: "string" },
            },
          },
        },
        type: "object",
        properties: {
          foo: { $ref: "#/definitions/testdef/properties/bar" },
        },
      }

In the previous behavior (added in #556), $ref: "#/definitions/testdef/properties/bar" would actually resolve to type: "string". However, using the jsonpointer library, it says that this definition does not even exist.

Perhaps I misunderstood the JSON Pointer spec when implementing #556 - maybe it's not supposed to resolve "recursive references to deep schema definitions". Is that the case, and if so, should we go by the standard or keep with our current implementation? (backwards compatibility isn't a huge issue as this will go into v2.0.0)

any thoughts @domharrington @erunion or others?

@erunion
Copy link
Collaborator

erunion commented Nov 10, 2019

Perhaps I misunderstood the JSON Pointer spec when implementing #556 - maybe it's not supposed to resolve "recursive references to deep schema definitions". Is that the case, and if so, should we go by the standard or keep with our current implementation? (backwards compatibility isn't a huge issue as this will go into v2.0.0)

That's tricky. The spec spec doesn't clarify $ref as being recursive in the way that you've got it, but there's also $recursiveRef which is for that, and RJSF doesn't support $recursiveRef right now.

I don't really want to get into putting stuff behind options, but maybe this should be? Create a new allowRecursiveRefs option, and if the pointer isn't found with jsonpointer, and this new option is enabled, fallback to the existing recursive code and document the expectation that this option is not compatible with OAS/Swagger schemas.

@epicfaace
Copy link
Member Author

  • We currently support definitions of the form #/definitions/. However, JSON Pointer standard says that absolute definition URLs should start with something like /definitions/ -- the former is only the "URI Fragment Identifier" representation of the JSON Pointer. However, Swagger does it the former way (starting with #). Not sure which one is best for us to go with? In the future, we might also want to support relative JSON Pointers, which is a consideration too.

Looking at the spec, it seems like JSON schema does require that $ref's are URI references (i.e. the version starting with #). So I'll change this PR accordingly.

@epicfaace epicfaace requested a review from edi9999 December 7, 2019 19:14
@epicfaace
Copy link
Member Author

@edi9999 this PR should be ready for review -- could you please take a look?

@edi9999
Copy link
Collaborator

edi9999 commented Dec 22, 2019

sorry, i don't have time right now, only after January 10th

@epicfaace
Copy link
Member Author

@edi9999 ?

@epicfaace
Copy link
Member Author

@edi9999 can you take a look at this PR?

Copy link
Collaborator

@edi9999 edi9999 left a comment

Choose a reason for hiding this comment

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

I'm not sure to be able to read this with a lot of things to say, but it looks good to me

@epicfaace epicfaace merged commit 64b8921 into master Feb 25, 2020
@epicfaace epicfaace deleted the refs branch February 25, 2020 23:06
erunion added a commit to readmeio/react-jsonschema-form that referenced this pull request Feb 27, 2020
* update package lock

* v2.0.0-alpha.2

* Overridable DescriptionField in BooleanField (rjsf-team#1594)

* Overridable description field in BooleanField

* Adds test for BooleanField's overridable DescriptionField

* doc: JSON schema version supported versions (rjsf-team#1603)

For rjsf-team#1307 (comment)

* Don't crash when schema property is a non-object - show an error instead (rjsf-team#1582)

* don't throw TypeError: Cannot use 'in' operator to search for

* Update Form_test.js

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

* Set up CI with Azure Pipelines (rjsf-team#1605)

* Set up CI with Azure Pipelines

[skip ci]

* Update azure-pipelines.yml for Azure Pipelines

* Add npm test to azure pipelines

* Delete .travis.yml

* Combine all themes into a single playground (rjsf-team#1539)

* move playground to new folder

* move playground to packages and standardize playground structure

* don't rely on bootstrap in playground

* fix styling, move share button to top right

* remove footer things

* more fixes

* encode theme in playground hash

* fix: don't switch to default theme when changing tabs

* correct package name is @rjsf/playground

* fix prod config for playground

* fix more configs

* use webpack-dev-server

* render form in a Frame

* add dependencies

* use DemoFrame component to properly fix material-ui styles

* use old bootstrap look and feel for the playground itself

* fix dist

* move netlify toml

* update netlify

* empty commit

* remove npm prepare to speed up travis runs

* fix webpack dist config for playground

* fix import

* disable minicssextractplugin to try to fix netlify

* fix netlify path

* no need to build playground / gh-pages for core package

* add HtmlWebpackPlugin

* Allow references that don't start with #/definitions/ (rjsf-team#1506)

* pass entire rootSchema to findSchemaDefinition, not just definitions

* use jsonpointer to handle non-"#/definitions" definitions

* revert package-lock

* make sure json pointers are URI fragment encoded

* replace "definitions" with "rootSchema"  variable

* Fix getMatchingOption logic

* fix tests

* remove console log

* Fix tests

* prettier

* Remove support for recursive references to deep schema definitions

* update docs for registry and definitions

* add `definitions` back to registry

* Fix mui form tests

* Add a general registry test

* update proptypes of registry

* fix eslint issues

* fix formatting

* Fix local playground for core package (rjsf-team#1607)

* remove scss file from playground

* fix dev playground on @rjsf/core

* fix playground version

* update package-lock

* fix playground "npm start"

* chore: move docs to separate folder (rjsf-team#1604)

* test: adding a github workflow for running tests

Co-authored-by: Ashwin Ramaswami <[email protected]>
Co-authored-by: Erik Lothe <[email protected]>
Co-authored-by: ACoolmanBigHealth <[email protected]>
Co-authored-by: Evgeniy Tatarkin <[email protected]>
Co-authored-by: Chancellor Clark <[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.

3 participants