1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-03 16:25:09 +00:00

more collection action code

This commit is contained in:
Craig Jellick
2018-01-20 01:08:31 -07:00
parent d170661103
commit 990db51407
3 changed files with 21 additions and 0 deletions

View File

@@ -64,6 +64,10 @@ func (j *JSONResponseWriter) writeMapSlice(builder *builder.Builder, apiContext
} }
} }
if apiContext.Schema.CollectionFormatter != nil {
apiContext.Schema.CollectionFormatter(apiContext, collection)
}
return collection return collection
} }

View File

@@ -120,5 +120,17 @@ func (s *Store) traverseAndAdd(apiContext *types.APIContext, schema *types.Schem
} }
} }
for _, action := range schema.CollectionActions {
for _, t := range []string{action.Output, action.Input} {
if t == "" {
continue
}
if refSchema, ok := schemaMap[t]; ok && !included[t] {
schemas = s.addSchema(apiContext, refSchema, schemaMap, schemas, included)
}
}
}
return schemas return schemas
} }

View File

@@ -262,3 +262,8 @@ func parseResponseURLBase(requestURL string, r *http.Request) (string, error) {
func (u *urlBuilder) Action(action string, resource *types.RawResource) string { func (u *urlBuilder) Action(action string, resource *types.RawResource) string {
return u.constructBasicURL(resource.Schema.Version, resource.Schema.PluralName, resource.ID) + "?action=" + url.QueryEscape(action) return u.constructBasicURL(resource.Schema.Version, resource.Schema.PluralName, resource.ID) + "?action=" + url.QueryEscape(action)
} }
func (u *urlBuilder) CollectionAction(schema *types.Schema, versionOverride *types.APIVersion, action string) string {
collectionURL := u.Collection(schema, versionOverride)
return collectionURL + "?action=" + url.QueryEscape(action)
}