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

$ref in subschemas #1286

Open
ph-poppe opened this issue Sep 21, 2023 · 1 comment
Open

$ref in subschemas #1286

ph-poppe opened this issue Sep 21, 2023 · 1 comment
Assignees
Labels
Area: Bridge Affects some of the bridge packages Bridge: JSON Schema Affects the uniforms-bridge-json-schema package Type: Question Questions and other discussions

Comments

@ph-poppe
Copy link

Before you open an issue, please check if a similar one already exists or has been closed before. Detailed information about the process of contributing can be found in CONTRIBUTING.md.

Let us know what is happening. Do provide us with:

  • Affected versions of the core, bridge, and theme packages you are aware of.
    • Include other versions as well, if you think it may help (React, browser, etc.).
  • Steps to reproduce. If possible, include a reproduction using our playground or CodeSandbox template.
  • Possible workarounds, if you've found any.

versions:
"uniforms": "^4.0.0-alpha.5",
"uniforms-bridge-json-schema": "^4.0.0-alpha.5",
"ajv": "^8.0.0",

run on chrome, React v 16.14

I have 2 schemas that are combined in a final one:

subschema1:

// note: instanceOf is handled by ajv
{
  $id: "/schemas/dateDef",
  oneOf: [{ type: "string", format: "date-time" }, { instanceof: "Date" }]
};

subschema 2:

{
  $id: "schemas/schema2",
  $schema: "http://json-schema.org/draft-07/schema#",
  type: "object",
  properties: {
    receivedDate: {
      $ref: "#/definitions/dateDef"
    },
    dueDate: {
      $ref: "#/definitions/dateDef"
    }
  },
  definitions:{
    dateDef:...
  }
}

final schema:

{
  type: "object",
  properties: {
     test: {$ref: "#/definitions/subSchema2"}
  },
  definitions: {
   subSchema2:...
 }
}

When this is loaded into the jonschemabridge, I hit the problem that dateDef is not resolved. In the jsonschemabridge he is looking for the dateDef definition in the parent schema, not in the subschema (subSchema2) and hence throwing an error. Is there a way for the bridge to look up the definition in the subschema?

current workaround:

  • adding the definition of the subSchema1 in the final schema as well.

thanks for the support!

@kestarumper kestarumper added Area: Bridge Affects some of the bridge packages Bridge: JSON Schema Affects the uniforms-bridge-json-schema package Type: Question Questions and other discussions labels Feb 26, 2024
@zendranm
Copy link
Member

No solution yet but, it seems the problem is the recursive nature of the resolveRefIfNeeded function used in the getField method. In the initial iteration, in the resolveRef function, the reference is correctly resolved against the schema. But if the next reference points to a nested schema, the reduce still tries to resolve that against the first level of the schema, instead of the nested schema.

Using the example provided in the issue description, the reference #/definitions/subSchema2 is correctly resolved against the final schema as schema.definitions['subSchema2'].

However, the reference #/definitions/dateDef is resolved as schema.definitions['dateDef'] whereas it should be schema.definitions['subSchema2'].definitions['dateDef'].

The proposed workaround should add the nested schema to the parent, but in my case ajv throws an error "Error: reference resolves to more than one schema".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Bridge Affects some of the bridge packages Bridge: JSON Schema Affects the uniforms-bridge-json-schema package Type: Question Questions and other discussions
Projects
Status: In progress
Development

No branches or pull requests

3 participants