mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +08:00
fix array schmea generation incorrect (#4801)
This commit is contained in:
@@ -144,6 +144,8 @@ type (
|
|||||||
MapMapNumber map[string]map[string]float64 `json:"mapMapNumber"`
|
MapMapNumber map[string]map[string]float64 `json:"mapMapNumber"`
|
||||||
MapMapBoolean map[string]map[string]bool `json:"mapMapBoolean"`
|
MapMapBoolean map[string]map[string]bool `json:"mapMapBoolean"`
|
||||||
MapMapString map[string]map[string]string `json:"mapMapString"`
|
MapMapString map[string]map[string]string `json:"mapMapString"`
|
||||||
|
MapMapObject map[string]map[string]ComplexJsonLevel1 `json:"mapMapObject"`
|
||||||
|
MapMapPointerObject map[string]map[string]*ComplexJsonLevel1 `json:"mapMapPointerObject"`
|
||||||
// Object
|
// Object
|
||||||
Object ComplexJsonLevel1 `json:"object"`
|
Object ComplexJsonLevel1 `json:"object"`
|
||||||
PointerObject *ComplexJsonLevel1 `json:"pointerObject"`
|
PointerObject *ComplexJsonLevel1 `json:"pointerObject"`
|
||||||
@@ -194,6 +196,8 @@ type (
|
|||||||
MapMapNumber map[string]map[string]float64 `json:"mapMapNumber"`
|
MapMapNumber map[string]map[string]float64 `json:"mapMapNumber"`
|
||||||
MapMapBoolean map[string]map[string]bool `json:"mapMapBoolean"`
|
MapMapBoolean map[string]map[string]bool `json:"mapMapBoolean"`
|
||||||
MapMapString map[string]map[string]string `json:"mapMapString"`
|
MapMapString map[string]map[string]string `json:"mapMapString"`
|
||||||
|
MapMapObject map[string]map[string]ComplexJsonLevel1 `json:"mapMapObject"`
|
||||||
|
MapMapPointerObject map[string]map[string]*ComplexJsonLevel1 `json:"mapMapPointerObject"`
|
||||||
// Object
|
// Object
|
||||||
Object ComplexJsonLevel1 `json:"object"`
|
Object ComplexJsonLevel1 `json:"object"`
|
||||||
PointerObject *ComplexJsonLevel1 `json:"pointerObject"`
|
PointerObject *ComplexJsonLevel1 `json:"pointerObject"`
|
||||||
|
|||||||
@@ -137,8 +137,7 @@ func parametersFromType(method string, tp apiSpec.Type) []spec.Parameter {
|
|||||||
if required {
|
if required {
|
||||||
requiredFields = append(requiredFields, jsonTag.Name)
|
requiredFields = append(requiredFields, jsonTag.Name)
|
||||||
}
|
}
|
||||||
p, r := propertiesFromType(member.Type)
|
var schema = spec.Schema{
|
||||||
properties[jsonTag.Name] = spec.Schema{
|
|
||||||
SwaggerSchemaProps: spec.SwaggerSchemaProps{
|
SwaggerSchemaProps: spec.SwaggerSchemaProps{
|
||||||
Example: exampleValueFromOptions(jsonTag.Options, member.Type),
|
Example: exampleValueFromOptions(jsonTag.Options, member.Type),
|
||||||
},
|
},
|
||||||
@@ -150,13 +149,19 @@ func parametersFromType(method string, tp apiSpec.Type) []spec.Parameter {
|
|||||||
ExclusiveMaximum: exclusiveMaximum,
|
ExclusiveMaximum: exclusiveMaximum,
|
||||||
Minimum: minimum,
|
Minimum: minimum,
|
||||||
ExclusiveMinimum: exclusiveMinimum,
|
ExclusiveMinimum: exclusiveMinimum,
|
||||||
Enum: enumsValueFromOptions(jsonTag.Options),
|
Enum: enumsValueFromOptions(jsonTag.Options),
|
||||||
Items: itemsFromGoType(member.Type),
|
|
||||||
Properties: p,
|
|
||||||
Required: r,
|
|
||||||
AdditionalProperties: mapFromGoType(member.Type),
|
AdditionalProperties: mapFromGoType(member.Type),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
switch sampleTypeFromGoType(member.Type) {
|
||||||
|
case swaggerTypeArray:
|
||||||
|
schema.Items=itemsFromGoType(member.Type)
|
||||||
|
case swaggerTypeObject:
|
||||||
|
p, r := propertiesFromType(member.Type)
|
||||||
|
schema.Properties = p
|
||||||
|
schema.Required = r
|
||||||
|
}
|
||||||
|
properties[jsonTag.Name] = schema
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if len(properties) > 0 {
|
if len(properties) > 0 {
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ func propertiesFromType(tp apiSpec.Type) (spec.SchemaProperties, []string) {
|
|||||||
if required {
|
if required {
|
||||||
requiredFields = append(requiredFields, jsonTagString)
|
requiredFields = append(requiredFields, jsonTagString)
|
||||||
}
|
}
|
||||||
p, r := propertiesFromType(member.Type)
|
var schema = spec.Schema{
|
||||||
properties[jsonTagString] = spec.Schema{
|
|
||||||
SwaggerSchemaProps: spec.SwaggerSchemaProps{
|
SwaggerSchemaProps: spec.SwaggerSchemaProps{
|
||||||
Example: example,
|
Example: example,
|
||||||
},
|
},
|
||||||
@@ -50,12 +49,19 @@ func propertiesFromType(tp apiSpec.Type) (spec.SchemaProperties, []string) {
|
|||||||
Minimum: minimum,
|
Minimum: minimum,
|
||||||
ExclusiveMinimum: exclusiveMinimum,
|
ExclusiveMinimum: exclusiveMinimum,
|
||||||
Enum: enum,
|
Enum: enum,
|
||||||
Items: itemsFromGoType(member.Type),
|
|
||||||
Properties: p,
|
|
||||||
Required: r,
|
|
||||||
AdditionalProperties: mapFromGoType(member.Type),
|
AdditionalProperties: mapFromGoType(member.Type),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
switch sampleTypeFromGoType(member.Type) {
|
||||||
|
case swaggerTypeArray:
|
||||||
|
schema.Items=itemsFromGoType(member.Type)
|
||||||
|
case swaggerTypeObject:
|
||||||
|
p, r := propertiesFromType(member.Type)
|
||||||
|
schema.Properties = p
|
||||||
|
schema.Required = r
|
||||||
|
}
|
||||||
|
|
||||||
|
properties[jsonTagString] = schema
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func itemsFromGoType(tp apiSpec.Type) *spec.SchemaOrArray {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return itemFromGoType(array)
|
return itemFromGoType(array.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapFromGoType(tp apiSpec.Type) *spec.SchemaOrBool {
|
func mapFromGoType(tp apiSpec.Type) *spec.SchemaOrBool {
|
||||||
@@ -75,18 +75,23 @@ func mapFromGoType(tp apiSpec.Type) *spec.SchemaOrBool {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
p, r := propertiesFromType(mapType.Value)
|
var schema = &spec.Schema{
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Type: typeFromGoType(mapType.Value),
|
||||||
|
AdditionalProperties: mapFromGoType(mapType.Value),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
switch sampleTypeFromGoType(mapType.Value) {
|
||||||
|
case swaggerTypeArray:
|
||||||
|
schema.Items = itemsFromGoType(mapType.Value)
|
||||||
|
case swaggerTypeObject:
|
||||||
|
p, r := propertiesFromType(mapType.Value)
|
||||||
|
schema.Properties = p
|
||||||
|
schema.Required = r
|
||||||
|
}
|
||||||
return &spec.SchemaOrBool{
|
return &spec.SchemaOrBool{
|
||||||
Allows: true,
|
Allows: true,
|
||||||
Schema: &spec.Schema{
|
Schema: schema,
|
||||||
SchemaProps: spec.SchemaProps{
|
|
||||||
Type: typeFromGoType(mapType.Value),
|
|
||||||
Items: itemsFromGoType(mapType.Value),
|
|
||||||
Properties: p,
|
|
||||||
Required: r,
|
|
||||||
AdditionalProperties: mapFromGoType(mapType.Value),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,41 +106,8 @@ func itemFromGoType(tp apiSpec.Type) *spec.SchemaOrArray {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case apiSpec.DefineStruct:
|
case apiSpec.DefineStruct, apiSpec.NestedStruct:
|
||||||
var (
|
properties, requiredFields := propertiesFromType(itemType)
|
||||||
properties = map[string]spec.Schema{}
|
|
||||||
requiredFields []string
|
|
||||||
)
|
|
||||||
rangeMemberAndDo(itemType, func(tag *apiSpec.Tags, required bool, member apiSpec.Member) {
|
|
||||||
jsonTag, _ := tag.Get(tagJson)
|
|
||||||
if jsonTag == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
minimum, maximum, exclusiveMinimum, exclusiveMaximum := rangeValueFromOptions(jsonTag.Options)
|
|
||||||
if required {
|
|
||||||
requiredFields = append(requiredFields, jsonTag.Name)
|
|
||||||
}
|
|
||||||
p, r := propertiesFromType(member.Type)
|
|
||||||
properties[jsonTag.Name] = spec.Schema{
|
|
||||||
SwaggerSchemaProps: spec.SwaggerSchemaProps{
|
|
||||||
Example: exampleValueFromOptions(jsonTag.Options, member.Type),
|
|
||||||
},
|
|
||||||
SchemaProps: spec.SchemaProps{
|
|
||||||
Description: formatComment(member.Comment),
|
|
||||||
Type: typeFromGoType(member.Type),
|
|
||||||
Default: defValueFromOptions(jsonTag.Options, member.Type),
|
|
||||||
Maximum: maximum,
|
|
||||||
ExclusiveMaximum: exclusiveMaximum,
|
|
||||||
Minimum: minimum,
|
|
||||||
ExclusiveMinimum: exclusiveMinimum,
|
|
||||||
Enum: enumsValueFromOptions(jsonTag.Options),
|
|
||||||
Items: itemsFromGoType(member.Type),
|
|
||||||
Properties: p,
|
|
||||||
Required: r,
|
|
||||||
AdditionalProperties: mapFromGoType(member.Type),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return &spec.SchemaOrArray{
|
return &spec.SchemaOrArray{
|
||||||
Schema: &spec.Schema{
|
Schema: &spec.Schema{
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
@@ -148,16 +120,13 @@ func itemFromGoType(tp apiSpec.Type) *spec.SchemaOrArray {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
case apiSpec.PointerType:
|
case apiSpec.PointerType:
|
||||||
return itemsFromGoType(itemType.Type)
|
return itemFromGoType(itemType.Type)
|
||||||
case apiSpec.ArrayType:
|
case apiSpec.ArrayType:
|
||||||
p, r := propertiesFromType(itemType.Value)
|
|
||||||
return &spec.SchemaOrArray{
|
return &spec.SchemaOrArray{
|
||||||
Schema: &spec.Schema{
|
Schema: &spec.Schema{
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Type: typeFromGoType(itemType.Value),
|
Type: typeFromGoType(itemType),
|
||||||
Items: itemsFromGoType(itemType.Value),
|
Items: itemsFromGoType(itemType),
|
||||||
Properties: p,
|
|
||||||
Required: r,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user