Exemple #1
0
func petAPIRouterBuilder(spec *spec.Document, api *untyped.API) *defaultRouteBuilder {
	builder := newDefaultRouteBuilder(spec, newRoutableUntypedAPI(spec, api, new(Context)))
	builder.AddRoute("GET", "/pets", spec.AllPaths()["/pets"].Get)
	builder.AddRoute("POST", "/pets", spec.AllPaths()["/pets"].Post)
	builder.AddRoute("DELETE", "/pets/{id}", spec.AllPaths()["/pets/{id}"].Delete)
	builder.AddRoute("GET", "/pets/{id}", spec.AllPaths()["/pets/{id}"].Get)

	return builder
}
Exemple #2
0
func AddSwaggerRoutes(doc *spec.Document) {
	for path, pathItem := range doc.AllPaths() {
		path = doc.BasePath() + deCurly(path)

		// TODO may be something usable here?
		// if extension, ok := pathItem.Extensions.GetString("x-revel-controller"); ok { }

		if pathItem.Head != nil {
			if action, ok := pathItem.Head.Extensions.GetString(X_REVEL_CONTROLLER_ACTION); ok {
				_fail(addRoute(action, "HEAD", path))
			}
		}

		if pathItem.Get != nil {
			if action, ok := pathItem.Get.Extensions.GetString(X_REVEL_CONTROLLER_ACTION); ok {
				_fail(addRoute(action, "GET", path))
			}
		}

		if pathItem.Post != nil {
			if action, ok := pathItem.Post.Extensions.GetString(X_REVEL_CONTROLLER_ACTION); ok {
				_fail(addRoute(action, "POST", path))
			}
		}

		if pathItem.Put != nil {
			if action, ok := pathItem.Put.Extensions.GetString(X_REVEL_CONTROLLER_ACTION); ok {
				_fail(addRoute(action, "PUT", path))
			}
		}

		if pathItem.Delete != nil {
			if action, ok := pathItem.Delete.Extensions.GetString(X_REVEL_CONTROLLER_ACTION); ok {
				_fail(addRoute(action, "DELETE", path))
			}
		}

		if pathItem.Patch != nil {
			if action, ok := pathItem.Patch.Extensions.GetString(X_REVEL_CONTROLLER_ACTION); ok {
				_fail(addRoute(action, "PATCH", path))
			}
		}

		if pathItem.Options != nil {
			if action, ok := pathItem.Options.Extensions.GetString("x-revel-controller-action"); ok {
				_fail(addRoute(action, "OPTIONS", path))
			}
		}
	}
}