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

RefResolver export function for resolving references #419

Closed

Conversation

kave
Copy link

@kave kave commented Jun 4, 2018

I had a use-case to take a schema with references and create a ref-resovled version.

I figured this maybe useful for other users to have the ability to export a reference resolved version of a schema.

Additions

  • RefResolver export function
  • unittests to cover use case

Testcase Example

Before

{
  "$id": "tree",
  "type": "object",
  "$schema": "http://json-schema.org/draft-06/schema#",
  "properties": {
    "name": {
      "type": "string"
    },
    "fruits": {
      "type": "object",
      "properties": {
        "apples": {
          "$ref": "apples"
        },
        "oranges": {
          "$ref": "oranges"
        }
      }
    }
  }
}

after

{
  "$id": "tree",
  "type": "object",
  "$schema": "http://json-schema.org/draft-06/schema#",
  "properties": {
    "name": {
      "type": "string"
    },
    "fruits": {
      "type": "object",
      "properties": {
        "apples": {
          "$id": "apples",
          "type": "object",
          "$schema": "http://json-schema.org/draft-06/schema#",
          "properties": {
            "name": {
              "type": "string"
            },
            "quantity": {
              "type": "integer"
            },
            "types": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "oranges": {
          "$id": "oranges",
          "type": "object",
          "$schema": "http://json-schema.org/draft-06/schema#",
          "properties": {
            "name": {
              "type": "string"
            },
            "quantity": {
              "type": "integer"
            },
            "types": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}

@kave
Copy link
Author

kave commented Jun 4, 2018

@Julian hey not entirely sure why some of these Draft6 tests are failing only added a new function and test. the test i wrote for this passes so was curious if you could help me debug?

@Julian
Copy link
Member

Julian commented Jun 4, 2018 via email

@maddanio
Copy link

How would this behave, or expected to behave, with recursive references? I guess it can only give up, right?

@gazpachoking
Copy link
Contributor

How would this behave, or expected to behave, with recursive references? I guess it can only give up, right?

I'm not fully sure the consequences, but python is fine with recursive data structures, so I don't think that should be a problem.

@maddanio
Copy link

Hmm, true, guess one would have to be quite careful though not to try and perform any kind of tree-like traversal though :)

@Julian
Copy link
Member

Julian commented Aug 13, 2019

So, sorry for letting this sit around for so long, but I think this should really live externally to jsonschema as a small library on top.

(It even might want to have a CLI that takes a file with refs and resolves them).

But yeah as-is, other than that there's the known bug that jsonschema has with location-independent references, I don't think there's a good enough reason to require that this lives in the library itself.

Happy to hear further thoughts, but for now going to close. Of course much appreciated, and apologies again that I couldn't make my mind up sooner.

@Julian Julian closed this Aug 13, 2019
Julian added a commit that referenced this pull request Aug 13, 2020
86f52b87 Fix a clear copy-paste error in the case names for tests from #394.
ec18a7d0 Merge pull request #360 from notEthan/duplicate_uris
cd9a4b9d change schemas with duplicate URIs http://localhost:1234/folder/
43e190e0 Merge pull request #394 from rjmill/rjmill/bools-and-1s-and-0s-inside-objects-and-arrays
85f0d459 Merge pull request #419 from ChALkeR/chalker/format-uri
54436216 Merge pull request #420 from ChALkeR/chalker/format/ip6
ad47b726 Add long valid and invalid ipv6
b2ab70ec More optional ipv6 tests
37189ae6 Test that uri format scheme is validated for allowed chars
2106ed17 backport uniqueItems cases to draft3
49fc2a95 backport const test cases to draft6
79fe60c0 more tests for true != 1 and false != 0 inside objects/arrays

git-subtree-dir: json
git-subtree-split: 86f52b87e3d572b8f808dd074a6b95c3695ba992
@chbrandt chbrandt mentioned this pull request Oct 6, 2022
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.

4 participants