Skip to content

Commit

Permalink
Merge pull request #147 from tdakkota/feat/fallback-to-raw
Browse files Browse the repository at this point in the history
feat(gen): fallback to jx.Raw if schema is inaccurate
  • Loading branch information
ernado authored Feb 2, 2022
2 parents 062685d + b9d2572 commit 76ab023
Show file tree
Hide file tree
Showing 39 changed files with 32,304 additions and 6,244 deletions.
148 changes: 118 additions & 30 deletions _testdata/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,11 @@
"style": "form",
"schema": {
"type": "object",
"required": ["min", "max", "filter"],
"required": [
"min",
"max",
"filter"
],
"properties": {
"min": {
"type": "integer"
Expand All @@ -511,7 +515,11 @@
"style": "deepObject",
"schema": {
"type": "object",
"required": ["min", "max", "filter"],
"required": [
"min",
"max",
"filter"
],
"properties": {
"min": {
"type": "integer"
Expand All @@ -533,7 +541,12 @@
"application/json": {
"schema": {
"type": "object",
"required": ["style", "min", "max", "filter"],
"required": [
"style",
"min",
"max",
"filter"
],
"properties": {
"style": {
"type": "string"
Expand Down Expand Up @@ -885,6 +898,9 @@
"testMapWithProps": {
"$ref": "#/components/schemas/MapWithProperties"
},
"testAny": {
"$ref": "#/components/schemas/AnyTest"
},
"testDate": {
"type": "string",
"format": "date"
Expand Down Expand Up @@ -942,38 +958,78 @@
"oneOf": [
{
"type": "object",
"required": ["common-1", "common-2", "unique-1"],
"required": [
"common-1",
"common-2",
"unique-1"
],
"properties": {
"common-1": {"type": "string"},
"common-2": {"type": "integer"},
"unique-1": {"type": "string"}
"common-1": {
"type": "string"
},
"common-2": {
"type": "integer"
},
"unique-1": {
"type": "string"
}
}
},
{
"type": "object",
"required": ["common-1", "common-2", "unique-2"],
"required": [
"common-1",
"common-2",
"unique-2"
],
"properties": {
"common-1": {"type": "string"},
"common-2": {"type": "integer"},
"unique-2": {"type": "string"}
"common-1": {
"type": "string"
},
"common-2": {
"type": "integer"
},
"unique-2": {
"type": "string"
}
}
},
{
"type": "object",
"required": ["common-1", "common-2", "unique-3"],
"required": [
"common-1",
"common-2",
"unique-3"
],
"properties": {
"common-1": {"type": "string"},
"common-2": {"type": "integer"},
"common-3": {"type": "integer"},
"unique-3": {"type": "string"}
"common-1": {
"type": "string"
},
"common-2": {
"type": "integer"
},
"common-3": {
"type": "integer"
},
"unique-3": {
"type": "string"
}
}
},
{
"type": "object",
"required": ["common-1", "common-2", "unique-4"],
"required": [
"common-1",
"common-2",
"unique-4"
],
"properties": {
"common-3": {"type": "integer"},
"unique-4": {"type": "string"}
"common-3": {
"type": "integer"
},
"unique-4": {
"type": "string"
}
}
}
]
Expand All @@ -982,39 +1038,71 @@
"oneOf": [
{
"type": "object",
"required": ["a", "c"],
"required": [
"a",
"c"
],
"properties": {
"a": {"type": "string"},
"b": {"type": "integer"},
"c": {"type": "string"}
"a": {
"type": "string"
},
"b": {
"type": "integer"
},
"c": {
"type": "string"
}
}
},
{
"type": "object",
"required": ["a", "c"],
"required": [
"a",
"c"
],
"properties": {
"a": {"type": "string"},
"b": {"type": "integer"},
"c": {"type": "string"},
"d": {"type": "integer"}
"a": {
"type": "string"
},
"b": {
"type": "integer"
},
"c": {
"type": "string"
},
"d": {
"type": "integer"
}
}
}
]
},
"OneOfBugs" : {
"OneOfBugs": {
"type": "object",
"required": [
"issue143",
"additional-fields"
],
"properties": {
"issue143":{
"issue143": {
"$ref": "#/components/schemas/Issue143"
},
"additional-fields": {
"$ref": "#/components/schemas/OneVariantHasNoUniqueFields"
}
}
},
"AnyTest": {
"type": "object",
"properties": {
"empty": {},
"any_map": {
"additionalProperties": true
},
"any_array": {
"type": "array"
}
}
}
},
"parameters": {
Expand Down
7 changes: 5 additions & 2 deletions cmd/ogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func main() {
verbose = flag.Bool("v", false, "verbose")
generateTests = flag.Bool("generate-tests", false, "Generate tests based on schema examples")
skipTestsRegex = flag.String("skip-tests", "", "Skip tests matched by regex")
inferTypes = flag.Bool("infer-types", false, "Infer schema types, if type is not defined explicitly")

debugIgnoreNotImplemented = flag.String("debug.ignoreNotImplemented", "", "Ignore methods having functionality which is not implemented (all, oneOf, anyOf, allOf, nullable types, complex parameter types)")
debugNoerr = flag.Bool("debug.noerr", false, "Ignore all errors")
Expand Down Expand Up @@ -93,10 +94,12 @@ func main() {
}

opts := gen.Options{
SpecificMethodPath: *specificMethod,
IgnoreNotImplemented: strings.Split(*debugIgnoreNotImplemented, ","),
VerboseRoute: *verbose,
GenerateExampleTests: *generateTests,
SkipTestRegex: nil,
InferSchemaType: *inferTypes,
SpecificMethodPath: *specificMethod,
IgnoreNotImplemented: strings.Split(*debugIgnoreNotImplemented, ","),
}
if expr := *skipTestsRegex; expr != "" {
r, err := regexp.Compile(expr)
Expand Down
Loading

0 comments on commit 76ab023

Please sign in to comment.