8000 [VERY WIP] Experimenting with API frameworks by Mierdin · Pull Request #142 · toddproject/todd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Oct 7, 2021. It is now read-only.

[VERY WIP] Experimenting with API frameworks #142

Closed
wants to merge 4 commits into from
Closed
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
57 changes: 57 additions & 0 deletions design/design.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package design

import (
. "github.com/goadesign/goa/design"
. "github.com/goadesign/goa/design/apidsl"
)

// These are the existing ToDD API functions that need to be covered
// http.HandleFunc("/v1/agent", tapi.Agent)
// http.HandleFunc("/v1/groups", tapi.Groups)
// http.HandleFunc("/v1/object/list", tapi.ListObjects)
// http.HandleFunc("/v1/object/group", tapi.ListObjects)
// http.HandleFunc("/v1/object/testrun", tapi.ListObjects)
// http.HandleFunc("/v1/object/create", tapi.CreateObject)
// http.HandleFunc("/v1/object/delete", tapi.DeleteObject)
// http.HandleFunc("/v1/testrun/run", tapi.Run)
// http.HandleFunc("/v1/testdata", tapi.TestData)

// Using https://github.com/goadesign/goa-cellar/tree/master/design as an example
var _ = API("todd", func() {
Title("The ToDD API")
Description("The ToDD API")
Contact(func() {
Name("Matt Oswalt")
// Email("admin@goa.design")
URL("https://github.com/toddproject")
})
License(func() {
Name("Apache v2")
URL("https://github.com/toddproject/todd/blob/master/LICENSE")
})
Docs(func() {

// May want to also provide API docs?
Description("todd docs")
URL("https://todd.readthedocs.io")
})
Host("localhost:8081")
Scheme("http")
BasePath("/todd")

Origin("http://swagger.goa.design", func() {
Methods("GET", "POST", "PUT", "PATCH", "DELETE")
MaxAge(600)
Credentials()
})

ResponseTemplate(Created, func(pattern string) {
Description("Resource created")
Status(201)
Headers(func() {
Header("Location", String, "href to created resource", func() {
Pattern(pattern)
})
})
})
})
39 changes: 39 additions & 0 deletions design/media_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package design

import (
. "github.com/goadesign/goa/design"
. "github.com/goadesign/goa/design/apidsl"
)

// Object is the ToDD object resource media type.
var Object = MediaType("application/json", func() {

Description("A ToDD object (group, testrun, etc)")

Attributes(func() {

Attribute("label", String, func() {
Description("The label for the object")
Example("test-datacenter")
})

Attribute("type", String, func() {
Description("Type of object (group, testrun, etc)")
Enum("testrun", "group")
})

Attribute("spec", String, "Details of object", func() {
// TODO(mierdin): I _think_ this can just be a string, since we're doing our own
// parsing of this after it's marshaled into BaseObject
Example("{}")
})

Required("label", "type", "spec")
})

View("default", func() {
Attribute("label")
Attribute("type")
Attribute("spec")
})
})
62 changes: 62 additions & 0 deletions design/objects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package design

import (
. "github.com/goadesign/goa/design"
. "github.com/goadesign/goa/design/apidsl"
)

var _ = Resource("object", func() {

DefaultMedia(Object)
BasePath("/object")

Action("list", func() {
// TODO(mierdin): Provide option to filter by type
Routing(
GET(""),
)
Description("Retrieve all ToDD objects.")
Response(OK, CollectionOf(Object))
})

Action("get", func() {
Routing(
GET("/:label"),
)
Description("Retrieve object with given label")
Params(func() {
Param("label", String, "Object Label", func() {
Minimum(1)
})
})
Response(OK, Object)
Response(NotFound)
Response(BadRequest, ErrorMedia)
})

Action("create", func() {
Routing(
POST(""),
)
Description("Create new object")
Payload(func() {
Member("name")
Required("name")
// TODO(mierdin): Add label, type, and spec?
})
Response(Created)
Response(BadRequest, ErrorMedia)
})

Action("delete", func() {
Routing(
DELETE("/:label"),
)
Params(func() {
Param("label", String, "Object Label")
})
Response(NoContent)
Response(NotFound)
Response(BadRequest, ErrorMedia)
})
})
0