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

Support mixed formats in referenced schema definitions #232

Closed
nantipov opened this issue Feb 14, 2025 · 8 comments · Fixed by #233
Closed

Support mixed formats in referenced schema definitions #232

nantipov opened this issue Feb 14, 2025 · 8 comments · Fixed by #233

Comments

@nantipov
Copy link

nantipov commented Feb 14, 2025

Would it possible to add support of a mixed formats in schemas definitions?
Or is there already existing capability?

For example, a schema defined in json points via $ref to a schema defined in yaml.

For now in such a use-case I get error: Failed to parse the JSON document at line 1 and column 1.

example schema

{
  "type": "object",
  "properties": {
    "name": {
      "$ref": "http://example.com/schemas/name.yaml"
    }
  }
}

dependant schema http://example.com/schemas/name.yaml

name:
  type: string

Thank you.

Remark
This might seen as a short followup on the topic of yaml and OpenAPI (#80)

@jviotti
Copy link
Member

jviotti commented Feb 14, 2025

Hey @nantipov , thanks for reporting. It should indeed work. Let me dig into it today. We might indeed be missing something on the logic to read JSON / YAML.

jviotti added a commit that referenced this issue Feb 14, 2025
Fixes: #232
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
Copy link
Member

jviotti commented Feb 14, 2025

@nantipov I'm struggling to reproduce. Are you using --http or resolving the YAML dependency with --resolve? Can you show me a complete example? This is what I'm trying:

schema.json:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$ref": "http://example.com/schema.yaml"
}

schema.yaml:

$id: http://example.com/schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
type: string

instance.json:

"foo"

And then this works fine:

jsonschema validate schema.json --resolve schema.yaml instance.json

@jviotti
Copy link
Member

jviotti commented Feb 14, 2025

Ah, it's the HTTP resolver indeed. I have a test and a fix. I'll release a new version in a bit

jviotti added a commit that referenced this issue Feb 14, 2025
Fixes: #232
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@nantipov
Copy link
Author

Hello @jviotti thanks for a quick follow up on this and checking all the things around.
And sorry for the late reply.

Well, yes, it was in combination of --resolve and --http. I cannot show the complete example at the moment. Maybe I can make some of simplified version of it a bit later.

But it seems you have already found the culprit in the HTTP resolver.

Thanks a lot.

Looking forward for helping with testing the updated version.

jviotti added a commit that referenced this issue Feb 14, 2025
Fixes: #232
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Feb 14, 2025
Fixes: #232
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Feb 14, 2025
Fixes: #232
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Feb 14, 2025
Fixes: #232
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Feb 14, 2025
Fixes: #232
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
Copy link
Member

jviotti commented Feb 14, 2025

@nantipov Awesome! I'm releasing v6.0.1 in a bit. I'll let you know so you can give it a shot and confirm the fix

@jviotti
Copy link
Member

jviotti commented Feb 14, 2025

Done @nantipov ! See https://github.com/sourcemeta/jsonschema/releases/tag/v6.0.1. Also uploaded to NPM and Homebrew. Please re-open if you still hit the issue!

@nantipov
Copy link
Author

Hi @jviotti ,

thanks a lot for such a quick fix.
I very appreciate it.

Looks great.

@jviotti
Copy link
Member

jviotti commented Feb 17, 2025

Any time! And if you have any suggestions for the tool, please let me know!

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 a pull request may close this issue.

2 participants