这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ func schemaFromType(r Registry, t reflect.Type) *Schema {
s.ContentEncoding = "base64"
} else {
s.Type = TypeArray
s.Nullable = true
s.Items = r.Schema(t.Elem(), true, t.Name()+"Item")

if t.Kind() == reflect.Array {
Expand Down
22 changes: 11 additions & 11 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ func TestSchema(t *testing.T) {
{
name: "array",
input: [2]int{1, 2},
expected: `{"type": "array", "items": {"type": "integer", "format": "int64"}, "minItems": 2, "maxItems": 2}`,
expected: `{"type": ["array", "null"], "items": {"type": "integer", "format": "int64"}, "minItems": 2, "maxItems": 2}`,
},
{
name: "slice",
input: []int{1, 2, 3},
expected: `{"type": "array", "items": {"type": "integer", "format": "int64"}}`,
expected: `{"type": ["array", "null"], "items": {"type": "integer", "format": "int64"}}`,
},
{
name: "map",
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestSchema(t *testing.T) {
"type": "object",
"properties": {
"value": {
"type": "array",
"type": ["array", "null"],
"minItems": 1,
"maxItems": 10,
"uniqueItems": true,
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestSchema(t *testing.T) {
"type": "object",
"properties": {
"value": {
"type": "array",
"type": ["array", "null"],
"items": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -433,7 +433,7 @@ func TestSchema(t *testing.T) {
"type": "object",
"properties": {
"value": {
"type": "array",
"type": ["array", "null"],
"items": {
"type": "string"
},
Expand All @@ -453,7 +453,7 @@ func TestSchema(t *testing.T) {
"type": "object",
"properties": {
"value": {
"type": "array",
"type": ["array", "null"],
"items": {
"type": "integer",
"format": "int64"
Expand Down Expand Up @@ -744,7 +744,7 @@ func TestSchema(t *testing.T) {
},
"maxItems":1,
"minItems":1,
"type":"array"
"type":["array", "null"]
},
"byRef":{
"$ref":"#/components/schemas/RecursiveChildKey"
Expand All @@ -762,7 +762,7 @@ func TestSchema(t *testing.T) {
"items":{
"$ref":"#/components/schemas/RecursiveChildLoop"
},
"type":"array"}
"type":["array", "null"]}
},
"required":["slice","array","map","byValue", "byRef"],
"type":"object"
Expand Down Expand Up @@ -884,7 +884,7 @@ func TestSchema(t *testing.T) {
"additionalProperties":false,
"properties":{
"values":{
"type":"array",
"type":["array", "null"],
"items":{
"type":"string",
"minLength":1,
Expand Down Expand Up @@ -1041,7 +1041,7 @@ func TestSchema(t *testing.T) {
},
"maxItems":4,
"minItems":4,
"type":"array"
"type":["array", "null"]
}
},
"required":["value"],
Expand All @@ -1064,7 +1064,7 @@ func TestSchema(t *testing.T) {
},
"maxItems":4,
"minItems":4,
"type":"array"
"type":["array", "null"]
}
},
"required":["value"],
Expand Down