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

Improve reference resolving #1829

Merged
merged 7 commits into from
May 6, 2022

Conversation

AlexandraBuzila
Copy link
Member

@AlexandraBuzila AlexandraBuzila commented Nov 4, 2021

  • resolve items subschema refs for renderers and testers
  • make rootSchema a required parameter in resolveSchema, as it is needed
    while resolving
  • add rootSchema as an optional parameter to Testers, so we can
    correclty resolve subschemas in testers
  • use resolved schemas in MaterialOneOfRenderer when computing default
    value
  • enable and update tests
  • remove 'Resolve Remote Schema' example as it's unsupported

@coveralls
Copy link

coveralls commented Nov 4, 2021

Coverage Status

Coverage remained the same at 84.29% when pulling 6a32016 on AlexandraBuzila:ref-resolving-fixes into d04e851 on eclipsesource:master.

@AlexandraBuzila
Copy link
Member Author

Open points that should be integrated in the PR:

  • we are currently resolving the refs for the items property directly in the resolveSchema method (and thus modifying the schema). This should be removed from the method and directly happen in the testers and renderers.
  • the rootSchema property in the resolveSchema method should be mandatory
  • check that all examples are working

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

Already works much better than before. Please see my detailed comments for further improvements. Please also test against the schema and uischema from:

packages/core/src/testers/testers.ts Outdated Show resolved Hide resolved
packages/core/src/util/resolvers.ts Outdated Show resolved Hide resolved
@AlexandraBuzila
Copy link
Member Author

Please also test against the schema and uischema from:

Both examples work. #1491 is covered by the oneOf-recursive example.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

Looks good! Added some comments and questions.

packages/core/src/testers/testers.ts Outdated Show resolved Hide resolved
packages/core/src/testers/testers.ts Outdated Show resolved Hide resolved
packages/core/src/util/renderer.ts Show resolved Hide resolved
Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

Thanks for the update! I have some more comments and questions

packages/core/src/testers/testers.ts Outdated Show resolved Hide resolved
packages/core/src/testers/testers.ts Outdated Show resolved Hide resolved
packages/core/src/testers/testers.ts Outdated Show resolved Hide resolved
packages/core/src/testers/testers.ts Outdated Show resolved Hide resolved
packages/core/src/testers/testers.ts Outdated Show resolved Hide resolved
packages/core/src/util/renderer.ts Outdated Show resolved Hide resolved
packages/core/src/util/resolvers.ts Outdated Show resolved Hide resolved
packages/core/src/util/resolvers.ts Outdated Show resolved Hide resolved
@AlexandraBuzila
Copy link
Member Author

Thank you for for the review, Stefan! I updated the code and integrated your comments.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

Looks good ;) Found one more small detail.

@@ -47,15 +47,17 @@ import { deriveTypes, hasType, resolveSchema } from '../util';
export const NOT_APPLICABLE = -1;
/**
* A tester is a function that receives an UI schema and a JSON schema and returns a boolean.
* Optionally, a root JSON schema can be provided, which can be used for resolving refs in the schema.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Optionally, a root JSON schema can be provided, which can be used for resolving refs in the schema.
* The rootSchema is handed over as context. Can be used to resolve references.

Comment on lines 438 to 441
const resolvedSchema = resolveSchema(schema, schemaPath, rootSchema ?? schema);
if (resolvedSchema?.items && (resolvedSchema.items as any).$ref){
resolvedSchema.items = resolveSchema(resolvedSchema, 'items', rootSchema ?? schema);
}
Copy link
Member

Choose a reason for hiding this comment

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

Here we are modifying the returned schema and therefore the overall schema stored in the JSON Forms store. Instead of building up a resolved schema we could adapt the checking logic to being able to follow refs.

AlexandraBuzila and others added 4 commits May 6, 2022 14:33
- resolve items subschema refs for renderers and testers
- make rootSchema a required parameter in resolveSchema, as it is needed
while resolving
- add rootSchema as an optional parameter to Testers and predicates used
by Testers, so we can correclty resolve subschemas
- use resolved schemas in MaterialOneOfRenderer when computing default
value
- enable and update tests
- remove 'Resolve Remote Schema' example as it's unsupported
- make rootSchema parameter required in testers
- update tests
- use rootSchema where applicable when resolving
Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

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

Great work! That's a great improvement to JSON Forms!

@sdirix sdirix merged commit c5e6703 into eclipsesource:master May 6, 2022
@sdirix sdirix changed the title Fix ref resolving for oneOf schemas Improve reference resolving May 6, 2022
@sdirix sdirix linked an issue May 6, 2022 that may be closed by this pull request
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.

Remove external ref resolving
3 participants