-
Notifications
You must be signed in to change notification settings - Fork 95
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
Add support for subschemas #99
base: main
Are you sure you want to change the base?
Conversation
1c44284
to
4684bc6
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #99 +/- ##
==========================================
- Coverage 76.58% 75.25% -1.33%
==========================================
Files 24 25 +1
Lines 1892 2138 +246
==========================================
+ Hits 1449 1609 +160
- Misses 354 425 +71
- Partials 89 104 +15 ☔ View full report in Codecov by Sentry. |
4684bc6
to
43dd923
Compare
046ba39
to
7bc36c4
Compare
18e8e38
to
827b886
Compare
- fix: add guard against loading non-json files when reading references in schemas - feat: introduce basic allOf support - fix: handle struct slices prop merging for allOf types - feat: introduce basic anyOf support, fix default value issue. - fix: make anyOf properties of primitive types dump interface instead of first type - fix: reduce duplicate types - fix: furhter reduce duplicate types - chore: refactor cmp Opts utility - fix: add graceful handling of some edge cases in code generation - empty enum type name - missing unmarshal methods for map types - "Plain" type naming collisions - schema.Type new properties potential (de)serialization - chore: rename test files after rebase - chore: cleanup go deps - chore: fix go linting issues - chore: integrate new formatter changes after rebase - fix: set consistent var names in unmarshallers, introduce support for both yaml and json in validators - chore: remove dead code - fix: use '>' instead of '>=' to perform max length validation. - chore: remove 'two' constant - chore: disable gomnd linter
cb3f1ad
to
66cf143
Compare
@@ -373,7 +415,7 @@ func (g *schemaGenerator) generateType( | |||
return codegen.EmptyInterfaceType{}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for maintaining this great tool!
I have been trying to use it for a schema with anyOf
and I have a comment on this PR.
When using anyOf
, the type
may not be set, and only be defined in the items which are part of the anyOf
itself - see for instance https://json-schema.org/understanding-json-schema/reference/combining#anyOf.
Specifically, I tried running go-jsonschema
from the lastest release as well as from this PR for this schema, and in both cases, I hit the EmptyInterfaceType
.
type EmbeddedlinksarrayJson []interface{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! will look into it :)
It breaks with this testcase: {
"$schema": "http://json-schema.org/draft-07/schema#",
"$defs": {
"foo": {
"type": "object",
"properties": {
"foo": {
"type": "string"
}
},
"required": [
"foo"
]
}
},
"id": "https://example.com/objectAllOf",
"type": "object",
"properties": {
"flags": {
"anyOf": [
{
"type": "string"
},
{
"type": "boolean"
}
]
},
"configurations": {
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"properties": {
"bar": {
"type": "number"
}
},
"required": [
"bar"
]
},
{
"type": "object",
"properties": {
"baz": {
"type": "boolean"
}
}
},
{
"$ref": "#/$defs/foo"
}
]
}
}
}
}
|
@joepjoosten thanks for providing it! I will look at it as soon as I can. |
Any updates on the status of this PR? The fixes in this branch would be helpful to a project I am working on as well. Thanks |
Hi @omissis any updates on when you think this is ready for use? I am using allOf and anyOf quite extensively in one of my project and I would really like to use this tooling. Is there anything I might do to help get it ready? |
Seems to break when there is an {
"$schema": "http://json-schema.org/draft-07/schema#",
"id": "https://example.com/objectAllOf",
"type": "object",
"allOf": [
{
"type": "object",
"properties": {
"foo": {
"type": "string"
}
},
"required": ["foo"]
},
{
"type": "object",
"properties": {
"bar": {
"type": "number"
}
},
"required": ["bar"]
},
{
"type": "object",
"properties": {
"configurations": {
"type": "array",
"items": {}
}
}
}
]
}
|
…n string validator
A quick update for all those who are waiting: I have just finished bringing this one up to date with all the things I have merged on main, and fixed all the broken tests code that I could find. This puts me in a position where I can look at all the feedback above and try to fix the issues. This is now the top priority for this repo to merge, and save for very small and trivial fixes and improvements, I will not merge anything else until this is done. Thank you for your patience. |
Thank you, @omissis! If you are looking for more inspiration for testing, it might be worth looking into what other json schema tools use in their repos:
If I find time in the coming weeks, I could also take a look to see if there are any interesting test cases we could add. |
This PR introduces support for anyOf and allOf subschemas.