remove generic schema test

This commit is contained in:
Shreyas Goenka 2024-08-22 17:42:19 +02:00
parent 39efb705de
commit 790731f981
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 1 additions and 228 deletions

View File

@ -12,234 +12,7 @@ import (
// TODO: Add a test that checks the primitive overrides for reference regexs work.
// Basically that the custom override for bundle regex works.
func TestGenericSchema(t *testing.T) {
type Person struct {
Name string `json:"name"`
Age int `json:"age,omitempty"`
}
type Plot struct {
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 {
Hero *Person `json:"hero"`
Villian Person `json:"villian,omitempty"`
Weddings []Wedding `json:"weddings"`
}
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": {
"hero": {
"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]+\\])*)\\}"
}
]
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
},
"villian": {
"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]+\\])*)\\}"
}
]
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
},
"weddings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"bride": {
"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]+\\])*)\\}"
}
]
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
},
"groom": {
"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]+\\])*)\\}"
}
]
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
},
"plots": {
"type": "array",
"items": {
"type": "object",
"properties": {
"deaths": {
"type": "array",
"items": {
"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]+\\])*)\\}"
}
]
},
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
}
},
"murders": {
"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]+\\])*)\\}"
}
]
},
"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,
"required": [
"hero",
"weddings"
]
}`
t.Log("[DEBUG] actual: ", string(jsonSchema))
t.Log("[DEBUG] expected: ", expected)
assert.Equal(t, expected, string(jsonSchema))
}
// TODO: Add a bundle of end to end tests, that both fail and pass the schema validation.
func TestDocIngestionForObject(t *testing.T) {
docs := &Docs{