Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
support map types using additionalProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Ho committed Mar 5, 2021
1 parent 6b15afd commit 5319534
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 176 deletions.
9 changes: 6 additions & 3 deletions example/foo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (

type FooResponse struct {
ID string `json:"id"`
Bar string `json:"bar"`
Baz string `json:"baz"`
startDate time.Time `json:"startDate"`
StartDate time.Time `json:"startDate"`
Msg json.RawMessage `json:"msg"`
InnerFoos []InnerFoo `json:"foo"`
Environments map[string]Environment `json:"environments"`
}

type Environment struct {
Name string `json:"name"`
}

// @Title Get all foos
Expand Down
18 changes: 9 additions & 9 deletions oas.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ type SchemaObject struct {
FieldName string `json:"-"` // For goas
DisabledFieldNames map[string]struct{} `json:"-"` // For goas

Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Required []string `json:"required,omitempty"`
Properties *orderedmap.OrderedMap `json:"properties,omitempty"`
Description string `json:"description,omitempty"`
Items *SchemaObject `json:"items,omitempty"` // use ptr to prevent recursive error
Example interface{} `json:"example,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Required []string `json:"required,omitempty"`
Properties *orderedmap.OrderedMap `json:"properties,omitempty"`
AdditionalProperties *SchemaObject `json:"additionalProperties,omitempty"`
Description string `json:"description,omitempty"`
Items *SchemaObject `json:"items,omitempty"` // use ptr to prevent recursive error
Example interface{} `json:"example,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`

// Ref is used when SchemaObject is as a ReferenceObject
Ref string `json:"$ref,omitempty"`
Expand All @@ -167,7 +168,6 @@ type SchemaObject struct {
// OneOf
// AnyOf
// Not
// AdditionalProperties
// Description
// Default
// Nullable
Expand Down
5 changes: 2 additions & 3 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,15 +1057,14 @@ func (p *parser) parseSchemaObject(pkgPath, pkgName, typeName string) (*SchemaOb
itemTypeName := typeName[5:]
schema, ok := p.KnownIDSchema[genSchemeaObjectID(pkgName, itemTypeName)]
if ok {
schemaObject.Items = &SchemaObject{Ref: addSchemaRefLinkPrefix(schema.ID)}
schemaObject.AdditionalProperties = &SchemaObject{Ref: addSchemaRefLinkPrefix(schema.ID)}
return &schemaObject, nil
}
schemaProperty, err := p.parseSchemaObject(pkgPath, pkgName, itemTypeName)
if err != nil {
return nil, err
}
schemaObject.Properties = orderedmap.New()
schemaObject.Properties.Set("key", schemaProperty)
schemaObject.AdditionalProperties = schemaProperty
return &schemaObject, nil
} else if typeName == "time.Time" {
schemaObject.Type = "string"
Expand Down
Loading

0 comments on commit 5319534

Please sign in to comment.