This commit is contained in:
Shreyas Goenka 2024-08-20 19:10:50 +02:00
parent 7db32fc211
commit b89928513e
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 0 additions and 135 deletions

View File

@ -388,141 +388,6 @@ func TestSliceOfStructSchema(t *testing.T) {
assert.Equal(t, expected, string(jsonSchema)) assert.Equal(t, expected, string(jsonSchema))
} }
func TestEmbeddedStructSchema(t *testing.T) {
type Location struct {
Country string `json:"country"`
State string `json:"state,omitempty"`
}
type Person struct {
Name string `json:"name"`
Age int `json:"age,omitempty"`
Home Location `json:"home"`
}
type Plot struct {
Events map[string]Person `json:"events"`
}
type Story struct {
Plot Plot `json:"plot"`
*Person
Location
}
elem := Story{}
schema, err := New(reflect.TypeOf(elem), nil)
assert.NoError(t, err)
jsonSchema, err := json.MarshalIndent(schema, " ", " ")
assert.NoError(t, err)
expected :=
`{
"type": "object",
"properties": {
"age": {
"anyOf": [
{
"type": "number"
},
{
"type": "string",
"pattern": "\\$\\{([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}"
}
]
},
"country": {
"type": "string"
},
"home": {
"type": "object",
"properties": {
"country": {
"type": "string"
},
"state": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"country"
]
},
"name": {
"type": "string"
},
"plot": {
"type": "object",
"properties": {
"events": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"age": {
"anyOf": [
{
"type": "number"
},
{
"type": "string",
"pattern": "\\$\\{([a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)*(\\[[0-9]+\\])*)\\}"
}
]
},
"home": {
"type": "object",
"properties": {
"country": {
"type": "string"
},
"state": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"country"
]
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name",
"home"
]
}
}
},
"additionalProperties": false,
"required": [
"events"
]
},
"state": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"plot",
"name",
"home",
"country"
]
}`
t.Log("[DEBUG] actual: ", string(jsonSchema))
t.Log("[DEBUG] expected: ", expected)
assert.Equal(t, expected, string(jsonSchema))
}
func TestErrorWithTrace(t *testing.T) { func TestErrorWithTrace(t *testing.T) {
tracker := newTracker() tracker := newTracker()
dummyType := reflect.TypeOf(struct{}{}) dummyType := reflect.TypeOf(struct{}{})