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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Kommentaar can be configured with a configuration file; see
Running Tests
-------------

`GO111MODULE=off ./bin/test ./...`
`GO111MODULE=off go test ./...`

Motivation and rationale
------------------------
Expand Down
18 changes: 17 additions & 1 deletion docparse/docparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,23 @@ func TestGetReference(t *testing.T) {
}},

{"UnknownObject", "could not find", nil},
{"net/http.Header", "not a struct", nil},
{"net/http.Header", "", &Reference{
Name: "Header",
Package: "net/http",
Lookup: "http.Header",
Info: "A Header represents the key-value pairs in an HTTP header.\n\n" +
"The keys should be in canonical form, as returned by\n" +
"[CanonicalHeaderKey].",
Context: "req",
Schema: &Schema{
Title: "Header",
Description: "A Header represents the key-value pairs in an HTTP header.\n\n" +
"The keys should be in canonical form, as returned by\n" +
"[CanonicalHeaderKey].",
Type: "object",
Properties: map[string]*Schema{},
},
}},
}

for _, tt := range tests {
Expand Down
2 changes: 2 additions & 0 deletions docparse/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ func GetReference(prog *Program, context string, isEmbed bool, lookup, filePath
arLookup = fmt.Sprintf("[%v:%v]", wrapper, arLookup)
}
return GetReference(prog, context, isEmbed, arLookup, filePath)
case *ast.MapType:
st = &ast.StructType{Fields: &ast.FieldList{}}
default:
return nil, ErrNotStruct{ts, fmt.Sprintf(
"%v is not a struct or interface but a %T", name, ts.Type)}
Expand Down
8 changes: 7 additions & 1 deletion docparse/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ start:
}
if isPrimitive(vtyp.Name) {
// we are done, no need for a lookup of a custom type
p.AdditionalProperties = &Schema{Type: JSONSchemaType(vtyp.Name)}
if vtyp.Name != "any" {
p.AdditionalProperties = &Schema{Type: JSONSchemaType(vtyp.Name)}
}
return &p, nil
}

Expand Down Expand Up @@ -705,6 +707,10 @@ arrayStart:
pkg = importPath
}

case *ast.MapType:
p.Items = &Schema{Type: "object"}
return nil

default:
return fmt.Errorf("fieldToSchema: unknown array type: %T", typ)
}
Expand Down
1 change: 1 addition & 0 deletions testdata/openapi2/src/struct-map/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "struct-map/otherpkg"

type resp struct {
Basic map[string]interface{} `json:"basic"` // Basic comment.
Basic2 map[string]any `json:"basic2"` // Basic2 comment.
Custom myMap `json:"custom"` // Custom comment.
Struct aStruct `json:"aStruct"` // Struct comment.
OtherStruct otherpkg.OtherStruct `json:"otherStruct"` // OtherStruct comment.
Expand Down
3 changes: 3 additions & 0 deletions testdata/openapi2/src/struct-map/want.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ definitions:
basic:
description: Basic comment.
type: object
basic2:
description: Basic2 comment.
type: object
custom:
description: Custom comment.
type: object
Expand Down
4 changes: 4 additions & 0 deletions testdata/openapi2/src/struct-slice/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type resp struct {
Basic []string `json:"basic"` // Basic comment.
Custom mySlice `json:"custom"` // Custom comment.
Double anotherSlice `json:"another"` // Double comment.
OneMore oneMoreSlice `json:"oneMore"` // OneMore comment.
StructRef customFieldValues `json:"structRef"` // structRefComment.
Deal deal `json:"deal"`
}
Expand All @@ -14,6 +15,9 @@ type mySlice []string
// anotherSlice comment.
type anotherSlice mySlice

// oneMoreSlice comment.
type oneMoreSlice []map[string]any

type customFieldValues []*customFieldValue

type customFieldValue struct {
Expand Down
5 changes: 5 additions & 0 deletions testdata/openapi2/src/struct-slice/want.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ definitions:
type: string
deal:
$ref: '#/definitions/struct-slice.deal'
oneMore:
description: OneMore comment.
type: array
items:
type: object
structRef:
description: structRefComment.
type: array
Expand Down
Loading