diff --git a/docparser/datatest/user.go b/docparser/datatest/user.go index a10b762..3bf6735 100644 --- a/docparser/datatest/user.go +++ b/docparser/datatest/user.go @@ -12,6 +12,7 @@ import ( // GetUser returns a user corresponding to specified id // @openapi:path // /pets: +// // get: // description: "Returns all pets from the system that the user has access to" // operationId: GetUser @@ -63,6 +64,7 @@ func GetUser() {} // PostFoo returns a user corresponding to specified id // @openapi:path // /pets: +// // post: // description: "Returns all pets from the system that the user has access to" // requestBody: @@ -114,6 +116,7 @@ type Pet struct { StrData map[string]string `json:"strData"` Children map[string]Pet `json:"children"` IntData map[string]int `json:"IntData"` + PtrStringMapAlias *MapStringString `json:"PtrStringMapAlias"` ByteData []byte `json:"ByteData"` JSONData json.RawMessage `json:"json_data"` CustomString otherpackage.CustomString `json:"custom_string"` diff --git a/docparser/model.go b/docparser/model.go index 64d7c55..4350862 100644 --- a/docparser/model.go +++ b/docparser/model.go @@ -383,7 +383,9 @@ func (spec *openAPI) replaceSchemaNameToCustom(s *schema) { if !ok { return } - refSplit[3] = meta.CustomName() + if meta.CustomName() != "" { + refSplit[3] = meta.CustomName() + } } s.Ref = strings.Join(refSplit, "/") } @@ -416,34 +418,20 @@ func (spec *openAPI) composeSpecSchemas() { } } -func (spec *openAPI) parseMaps(mp *ast.MapType) (*schema, []error) { +func (spec *openAPI) parseMaps(f *ast.File, mp *ast.MapType) (*schema, []error) { errors := make([]error, 0) - // only map[string] - if i, ok := mp.Key.(*ast.Ident); ok { - t, _, err := parseIdentProperty(i) - if err != nil { - errors = append(errors, BuildError{ - Err: err, - Message: "could not parse ident property from map", - }) - } - - if t != "string" { - return nil, errors - } + p, err := parseNamedType(f, mp, nil) + if err != nil { + logrus.WithError(err).Error("Can't parse the type of field in map") + errors = append(errors, BuildError{ + Err: err, + Message: "can't parse the type of field in map", + }) } - e := newEntity() - e.Type = "object" - e.AdditionalProperties = &schema{} - - // map[string]interface{} - if _, ok := mp.Value.(*ast.InterfaceType); ok { - return &e, errors - } + return p, errors - return nil, errors } func (spec *openAPI) parseStructs(f *ast.File, tpe *ast.StructType) (interface{}, []error) { @@ -575,7 +563,7 @@ func (spec *openAPI) parseSchemas(f *ast.File) (errors []error) { switch n := ts.Type.(type) { case *ast.MapType: var errs []error - entity, errs = spec.parseMaps(n) + entity, errs = spec.parseMaps(f, n) if len(errs) != 0 { errors = append(errors, errs...) }