Codebase list golang-github-alecthomas-jsonschema / d29031c
Handle byte slices as type alias David Halls authored 3 years ago Alec Thomas committed 3 years ago
10 changed file(s) with 70 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
9797 "binaryEncoding": "base64"
9898 }
9999 },
100 "photo2": {
101 "type": "string",
102 "media": {
103 "binaryEncoding": "base64"
104 }
105 },
100106 "feeling": {
101107 "oneOf": [
102108 {
9797 "binaryEncoding": "base64"
9898 }
9999 },
100 "photo2": {
101 "type": "string",
102 "media": {
103 "binaryEncoding": "base64"
104 }
105 },
100106 "feeling": {
101107 "oneOf": [
102108 {
8282 "binaryEncoding": "base64"
8383 }
8484 },
85 "photo2": {
86 "type": "string",
87 "media": {
88 "binaryEncoding": "base64"
89 }
90 },
8591 "feeling": {
8692 "oneOf": [
8793 {
9797 "binaryEncoding": "base64"
9898 }
9999 },
100 "photo2": {
101 "type": "string",
102 "media": {
103 "binaryEncoding": "base64"
104 }
105 },
100106 "feeling": {
101107 "oneOf": [
102108 {
9090 "binaryEncoding": "base64"
9191 }
9292 },
93 "photo2": {
94 "type": "string",
95 "media": {
96 "binaryEncoding": "base64"
97 }
98 },
9399 "feeling": {
94100 "oneOf": [
95101 {
8989 "binaryEncoding": "base64"
9090 }
9191 },
92 "photo2": {
93 "type": "string",
94 "media": {
95 "binaryEncoding": "base64"
96 }
97 },
9298 "feeling": {
9399 "oneOf": [
94100 {
250256 "binaryEncoding": "base64"
251257 }
252258 },
259 "photo2": {
260 "type": "string",
261 "media": {
262 "binaryEncoding": "base64"
263 }
264 },
253265 "feeling": {
254266 "oneOf": [
255267 {
8989 "binaryEncoding": "base64"
9090 }
9191 },
92 "photo2": {
93 "type": "string",
94 "media": {
95 "binaryEncoding": "base64"
96 }
97 },
9298 "feeling": {
9399 "oneOf": [
94100 {
250256 "binaryEncoding": "base64"
251257 }
252258 },
259 "photo2": {
260 "type": "string",
261 "media": {
262 "binaryEncoding": "base64"
263 }
264 },
253265 "feeling": {
254266 "oneOf": [
255267 {
1818 "SomeUntaggedBaseProperty",
1919 "id",
2020 "name",
21 "photo"
21 "photo",
22 "photo2"
2223 ],
2324 "properties": {
2425 "some_base_property": {
8990 "binaryEncoding": "base64"
9091 }
9192 },
93 "photo2": {
94 "type": "string",
95 "media": {
96 "binaryEncoding": "base64"
97 }
98 },
9299 "feeling": {
93100 "oneOf": [
94101 {
238238 returnType.MinItems = t.Len()
239239 returnType.MaxItems = returnType.MinItems
240240 }
241 switch t {
242 case byteSliceType:
241 if t.Kind() == reflect.Slice && t.Elem() == byteSliceType.Elem() {
243242 returnType.Type = "string"
244243 returnType.Media = &Type{BinaryEncoding: "base64"}
245244 return returnType
246 default:
247 returnType.Type = "array"
248 returnType.Items = r.reflectTypeToSchema(definitions, t.Elem())
249 return returnType
250 }
245 }
246 returnType.Type = "array"
247 returnType.Items = r.reflectTypeToSchema(definitions, t.Elem())
248 return returnType
251249
252250 case reflect.Interface:
253251 return &Type{
6868
6969 // Tests for RFC draft-wright-json-schema-hyperschema-00, section 4
7070 Photo []byte `json:"photo,omitempty" jsonschema:"required"`
71 Photo2 Bytes `json:"photo2,omitempty" jsonschema:"required"`
7172
7273 // Tests for jsonpb enum support
7374 Feeling ProtoEnum `json:"feeling,omitempty"`
103104 Child3 interface{} `json:"child3" jsonschema:"oneof_required=group2,oneof_type=string;array"`
104105 Child4 string `json:"child4" jsonschema:"oneof_required=group1"`
105106 }
107
108 type Bytes []byte
106109
107110 func TestSchemaGeneration(t *testing.T) {
108111 tests := []struct {