Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-goenka committed Aug 20, 2024
1 parent 7db32fc commit b899285
Showing 1 changed file with 0 additions and 135 deletions.
135 changes: 0 additions & 135 deletions bundle/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,141 +388,6 @@ func TestSliceOfStructSchema(t *testing.T) {
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) {
tracker := newTracker()
dummyType := reflect.TypeOf(struct{}{})
Expand Down

0 comments on commit b899285

Please sign in to comment.