Skip to content

Commit 90227a9

Browse files
authored
Revert "Fix enums placement (#124)"
This reverts commit 5662f8c.
1 parent 5662f8c commit 90227a9

File tree

2 files changed

+3
-52
lines changed

2 files changed

+3
-52
lines changed

reflect.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,35 +1379,17 @@ func reflectEnum(schema *Schema, fieldTag reflect.StructTag, fieldVal interface{
13791379
enum.loadFromField(fieldTag, fieldVal)
13801380

13811381
if len(enum.items) > 0 {
1382-
target := searchDeepestSchema(schema)
1383-
target.Enum = enum.items
1384-
1382+
schema.Enum = enum.items
13851383
if len(enum.names) > 0 {
1386-
if target.ExtraProperties == nil {
1387-
target.ExtraProperties = make(map[string]interface{}, 1)
1384+
if schema.ExtraProperties == nil {
1385+
schema.ExtraProperties = make(map[string]interface{}, 1)
13881386
}
13891387

13901388
schema.ExtraProperties[XEnumNames] = enum.names
13911389
}
13921390
}
13931391
}
13941392

1395-
func searchDeepestSchema(in *Schema) *Schema {
1396-
if in.Items == nil {
1397-
return in
1398-
}
1399-
1400-
if in.Items.SchemaOrBool == nil {
1401-
return in
1402-
}
1403-
1404-
if in.Items.SchemaOrBool.TypeObject == nil {
1405-
return in
1406-
}
1407-
1408-
return searchDeepestSchema(in.Items.SchemaOrBool.TypeObject)
1409-
}
1410-
14111393
// enum can be use for sending enum data that need validate.
14121394
type enum struct {
14131395
items []interface{}

reflect_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,34 +2655,3 @@ func TestReflector_Reflect_byteSlice(t *testing.T) {
26552655
"type":"object"
26562656
}`, s)
26572657
}
2658-
2659-
func TestReflector_Reflect_EnumsPlacement(t *testing.T) {
2660-
r := jsonschema.Reflector{}
2661-
2662-
type Check struct {
2663-
A int `json:"a" enum:"1"`
2664-
B []string `json:"b" enum:"check-string"`
2665-
C []withValNamedEnum `json:"c"`
2666-
D [][][]string `json:"d" enum:"d"`
2667-
F map[string]string `json:"f" enum:"f"`
2668-
G map[int]map[string][]int `json:"g" enum:"1"`
2669-
}
2670-
2671-
got, err := r.Reflect(Check{})
2672-
require.NoError(t, err)
2673-
2674-
assertjson.EqMarshal(t, `{
2675-
"definitions": {
2676-
"JsonschemaGoTestWithValNamedEnum": {"enum": [""],"type": "string","x-enum-names": ["n:"]}
2677-
},
2678-
"properties":{
2679-
"a":{"enum":["1"],"type":"integer"},
2680-
"b":{"items":{"enum":["check-string"],"type":"string"},"type":["array","null"]},
2681-
"c":{"items":{"$ref":"#/definitions/JsonschemaGoTestWithValNamedEnum"},"type":["array","null"]},
2682-
"d":{"items":{"items":{"items":{"enum":["d"],"type":"string"},"type":"array"},"type":"array"},"type":["array","null"]},
2683-
"f":{"additionalProperties":{"type":"string"},"enum":["f"],"type":["object","null"]},
2684-
"g":{"additionalProperties":{"additionalProperties":{"items":{"type":"integer"},"type":"array"},"type":"object"},"enum":["1"],"type":["object","null"]}
2685-
},
2686-
"type":"object"
2687-
}`, got)
2688-
}

0 commit comments

Comments
 (0)