Added generic test

This commit is contained in:
Shreyas Goenka 2023-01-18 18:09:18 +01:00
parent 35c3793579
commit d00cee4680
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 115 additions and 23 deletions

View File

@ -819,21 +819,29 @@ func TestPointerInStructSchema(t *testing.T) {
assert.Equal(t, expectedSchema, string(jsonSchema)) assert.Equal(t, expectedSchema, string(jsonSchema))
} }
// TODO: last test to do once all the todos are done func TestGenericSchema(t *testing.T) {
func TestObjectSchema(t *testing.T) {
type Person struct { type Person struct {
Name string `json:"name"` Name string `json:"name"`
Age int `json:"age,omitempty"` Age int `json:"age,omitempty"`
} }
type Plot struct { type Plot struct {
Stakes []string `json:"stakes"` Stakes []string `json:"stakes"`
Deaths []Person `json:"deaths"`
Murders map[string]Person `json:"murders"`
}
type Wedding struct {
Hidden string `json:","`
Groom Person `json:"groom"`
Bride Person `json:"bride"`
Plots []Plot `json:"plots"`
} }
type Story struct { type Story struct {
Hero Person `json:"hero"` Hero *Person `json:"hero"`
Villian Person `json:"villian"` Villian Person `json:"villian,omitempty"`
Plot Plot `json:"plot"` Weddings []Wedding `json:"weddings"`
} }
elem := Story{} elem := Story{}
@ -863,21 +871,6 @@ func TestObjectSchema(t *testing.T) {
"name" "name"
] ]
}, },
"plot": {
"type": "object",
"properties": {
"stakes": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false,
"required": [
"stakes"
]
},
"villian": { "villian": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -892,13 +885,112 @@ func TestObjectSchema(t *testing.T) {
"required": [ "required": [
"name" "name"
] ]
},
"weddings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"bride": {
"type": "object",
"properties": {
"age": {
"type": "number"
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
},
"groom": {
"type": "object",
"properties": {
"age": {
"type": "number"
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
},
"plots": {
"type": "array",
"items": {
"type": "object",
"properties": {
"deaths": {
"type": "array",
"items": {
"type": "object",
"properties": {
"age": {
"type": "number"
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
}
},
"murders": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"age": {
"type": "number"
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
}
},
"stakes": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false,
"required": [
"stakes",
"deaths",
"murders"
]
}
}
},
"additionalProperties": false,
"required": [
"groom",
"bride",
"plots"
]
}
} }
}, },
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": [
"hero", "hero",
"villian", "weddings"
"plot"
] ]
}` }`