diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 561b5ff..35c62a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,8 +14,8 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - stable: false - go-version: 1.16.0-rc1 + stable: true + go-version: 1.16 - name: Lint continue-on-error: true # TODO: Remove when 1.16 linting starts passing. run: | diff --git a/Makefile b/Makefile index 167872b..7ad5519 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ -GO ?= go1.16rc1 +GO ?= go1.16 export GO .PHONY: build -build: trucegen ## Build truce into bin folder +build: fmt ## Build truce into bin folder @mkdir -p bin @echo "Building Truce from source." @$(GO) build -o bin/truce ./cmd/truce/... .PHONY: install -install: trucegen ## Install truce globally +install: ## Install truce globally $(GO) install ./cmd/truce/... .PHONY: test @@ -17,16 +17,11 @@ test: build .PHONY: fmt fmt: deps ## Run go fmt -s and cue fmt all over the shop - @cue fmt truce.cue + @cue fmt ./cue/... @gofmt -s -w $(shell find . -name "*.go") -.PHONY: trucegen -trucegen: fmt ## Generate truce specification - @echo "Generating embedded truce.go definitions." - @$(GO) run internal/cmd/trucegen/main.go - require-buildtools: - @$(GO) version >/dev/null || (echo "Go 1.16beta1 is currently required. Try 'make install-go'." && exit 2) + @$(GO) version >/dev/null || (echo "${GO} is currently required. Try 'make install-go'." && exit 2) .PHONY: install-go install-go: ## Install latest beta version of Go (requires a stable version of Go). @@ -40,7 +35,7 @@ deps: require-buildtools ## Download dependencies @$(GO) mod tidy .PHONY: examplegen ## Re-generate example project -examplegen: cleanExample trucegen build ## generate example directory cue services +examplegen: cleanExample build ## generate example directory cue services @bin/truce gen example/service.cue # http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html diff --git a/cue.mod b/cue/cue.mod similarity index 100% rename from cue.mod rename to cue/cue.mod diff --git a/openapi.cue b/cue/openapi.cue similarity index 100% rename from openapi.cue rename to cue/openapi.cue diff --git a/truce.cue b/cue/truce.cue similarity index 100% rename from truce.cue rename to cue/truce.cue diff --git a/example/client.go b/example/client.go index 426eebf..705125a 100644 --- a/example/client.go +++ b/example/client.go @@ -32,319 +32,425 @@ func NewClient(host string) (*Client, error) { return &Client{client: http.DefaultClient, host: u}, nil } -func (_c *Client) GetPost(ctxt context.Context, id string) (Post, error) { - _u, _err := _c.host.Parse(fmt.Sprintf("/api/v1/posts/%v", id)) - if _err != nil { - return Post{}, _err +func (c *Client) DeletePost(ctxt context.Context, id string) error { + return c.deletePost(ctxt, id) +} + +func (c *Client) deletePost(ctxt context.Context, v0 string) error { + u, err := c.host.Parse(fmt.Sprintf("/api/v1/posts/%v", v0)) + if err != nil { + return err + } + + var ( + body io.Reader + resp *http.Response + ) + + req, err := http.NewRequest("DELETE", u.String(), body) + if err != nil { + return err + } + + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return err + } + + defer func() { + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() + }() + + if err = checkResponse(resp); err != nil { + return err + } + + return nil +} + +func (c *Client) DeleteUser(ctxt context.Context, id string) error { + return c.deleteUser(ctxt, id) +} + +func (c *Client) deleteUser(ctxt context.Context, v0 string) error { + u, err := c.host.Parse(fmt.Sprintf("/api/v1/users/%v", v0)) + if err != nil { + return err + } + + var ( + body io.Reader + resp *http.Response + ) + + req, err := http.NewRequest("DELETE", u.String(), body) + if err != nil { + return err + } + + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return err + } + + defer func() { + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() + }() + + if err = checkResponse(resp); err != nil { + return err + } + + return nil +} + +func (c *Client) GetPost(ctxt context.Context, id string) (Post, error) { + return c.getPost(ctxt, id) +} + +func (c *Client) getPost(ctxt context.Context, v0 string) (Post, error) { + u, err := c.host.Parse(fmt.Sprintf("/api/v1/posts/%v", v0)) + if err != nil { + return Post{}, err } var ( - _body io.Reader - _resp *http.Response + body io.Reader + resp *http.Response ) - _req, _err := http.NewRequest("GET", _u.String(), _body) - if _err != nil { - return Post{}, _err + req, err := http.NewRequest("GET", u.String(), body) + if err != nil { + return Post{}, err } - _resp, _err = _c.client.Do(_req.WithContext(ctxt)) - if _err != nil { - return Post{}, _err + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return Post{}, err } defer func() { - _, _ = io.Copy(ioutil.Discard, _resp.Body) - _ = _resp.Body.Close() + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() }() - if _err = _checkResponse(_resp); _err != nil { - return Post{}, _err + if err = checkResponse(resp); err != nil { + return Post{}, err } - var _rtn Post - _err = json.NewDecoder(_resp.Body).Decode(&_rtn) - return _rtn, _err + var rtn Post + err = json.NewDecoder(resp.Body).Decode(&rtn) + return rtn, err +} + +func (c *Client) GetPosts(ctxt context.Context, limit int64) ([]Post, error) { + return c.getPosts(ctxt, limit) } -func (_c *Client) GetPosts(ctxt context.Context, limit int64) ([]Post, error) { - _u, _err := _c.host.Parse("/api/v1/posts") - if _err != nil { - return nil, _err +func (c *Client) getPosts(ctxt context.Context, v0 int64) ([]Post, error) { + u, err := c.host.Parse("/api/v1/posts") + if err != nil { + return nil, err } - _query := _u.Query() - _query.Set("limit", fmt.Sprintf("%v", limit)) - _u.RawQuery = _query.Encode() + query := u.Query() + query.Set("limit", fmt.Sprintf("%v", v0)) + u.RawQuery = query.Encode() var ( - _body io.Reader - _resp *http.Response + body io.Reader + resp *http.Response ) - _req, _err := http.NewRequest("GET", _u.String(), _body) - if _err != nil { - return nil, _err + req, err := http.NewRequest("GET", u.String(), body) + if err != nil { + return nil, err } - _resp, _err = _c.client.Do(_req.WithContext(ctxt)) - if _err != nil { - return nil, _err + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return nil, err } defer func() { - _, _ = io.Copy(ioutil.Discard, _resp.Body) - _ = _resp.Body.Close() + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() }() - if _err = _checkResponse(_resp); _err != nil { - return nil, _err + if err = checkResponse(resp); err != nil { + return nil, err } - var _rtn []Post - _err = json.NewDecoder(_resp.Body).Decode(&_rtn) - return _rtn, _err + var rtn []Post + err = json.NewDecoder(resp.Body).Decode(&rtn) + return rtn, err } -func (_c *Client) GetUser(ctxt context.Context, id string) (User, error) { - _u, _err := _c.host.Parse(fmt.Sprintf("/api/v1/users/%v", id)) - if _err != nil { - return User{}, _err +func (c *Client) GetUser(ctxt context.Context, id string) (User, error) { + return c.getUser(ctxt, id) +} + +func (c *Client) getUser(ctxt context.Context, v0 string) (User, error) { + u, err := c.host.Parse(fmt.Sprintf("/api/v1/users/%v", v0)) + if err != nil { + return User{}, err } var ( - _body io.Reader - _resp *http.Response + body io.Reader + resp *http.Response ) - _req, _err := http.NewRequest("GET", _u.String(), _body) - if _err != nil { - return User{}, _err + req, err := http.NewRequest("GET", u.String(), body) + if err != nil { + return User{}, err } - _resp, _err = _c.client.Do(_req.WithContext(ctxt)) - if _err != nil { - return User{}, _err + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return User{}, err } defer func() { - _, _ = io.Copy(ioutil.Discard, _resp.Body) - _ = _resp.Body.Close() + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() }() - if _err = _checkResponse(_resp); _err != nil { - return User{}, _err + if err = checkResponse(resp); err != nil { + return User{}, err } - var _rtn User - _err = json.NewDecoder(_resp.Body).Decode(&_rtn) - return _rtn, _err + var rtn User + err = json.NewDecoder(resp.Body).Decode(&rtn) + return rtn, err +} + +func (c *Client) GetUsers(ctxt context.Context, limit int64) ([]User, error) { + return c.getUsers(ctxt, limit) } -func (_c *Client) GetUsers(ctxt context.Context, limit int64) ([]User, error) { - _u, _err := _c.host.Parse("/api/v1/users") - if _err != nil { - return nil, _err +func (c *Client) getUsers(ctxt context.Context, v0 int64) ([]User, error) { + u, err := c.host.Parse("/api/v1/users") + if err != nil { + return nil, err } - _query := _u.Query() - _query.Set("limit", fmt.Sprintf("%v", limit)) - _u.RawQuery = _query.Encode() + query := u.Query() + query.Set("limit", fmt.Sprintf("%v", v0)) + u.RawQuery = query.Encode() var ( - _body io.Reader - _resp *http.Response + body io.Reader + resp *http.Response ) - _req, _err := http.NewRequest("GET", _u.String(), _body) - if _err != nil { - return nil, _err + req, err := http.NewRequest("GET", u.String(), body) + if err != nil { + return nil, err } - _resp, _err = _c.client.Do(_req.WithContext(ctxt)) - if _err != nil { - return nil, _err + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return nil, err } defer func() { - _, _ = io.Copy(ioutil.Discard, _resp.Body) - _ = _resp.Body.Close() + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() }() - if _err = _checkResponse(_resp); _err != nil { - return nil, _err + if err = checkResponse(resp); err != nil { + return nil, err } - var _rtn []User - _err = json.NewDecoder(_resp.Body).Decode(&_rtn) - return _rtn, _err + var rtn []User + err = json.NewDecoder(resp.Body).Decode(&rtn) + return rtn, err +} + +func (c *Client) PatchPost(ctxt context.Context, id string, post PatchPostRequest) (Post, error) { + return c.patchPost(ctxt, id, post) } -func (_c *Client) PatchPost(ctxt context.Context, id string, post PatchPostRequest) (Post, error) { - _u, _err := _c.host.Parse(fmt.Sprintf("/api/v1/posts/%v", id)) - if _err != nil { - return Post{}, _err +func (c *Client) patchPost(ctxt context.Context, v0 string, v1 PatchPostRequest) (Post, error) { + u, err := c.host.Parse(fmt.Sprintf("/api/v1/posts/%v", v0)) + if err != nil { + return Post{}, err } var ( - _body io.Reader - _resp *http.Response + body io.Reader + resp *http.Response ) - _buf := &bytes.Buffer{} - _body = _buf - if _err = json.NewEncoder(_buf).Encode(post); _err != nil { - return Post{}, _err + buf := &bytes.Buffer{} + body = buf + if err = json.NewEncoder(buf).Encode(v1); err != nil { + return Post{}, err } - _req, _err := http.NewRequest("PATCH", _u.String(), _body) - if _err != nil { - return Post{}, _err + req, err := http.NewRequest("PATCH", u.String(), body) + if err != nil { + return Post{}, err } - _resp, _err = _c.client.Do(_req.WithContext(ctxt)) - if _err != nil { - return Post{}, _err + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return Post{}, err } defer func() { - _, _ = io.Copy(ioutil.Discard, _resp.Body) - _ = _resp.Body.Close() + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() }() - if _err = _checkResponse(_resp); _err != nil { - return Post{}, _err + if err = checkResponse(resp); err != nil { + return Post{}, err } - var _rtn Post - _err = json.NewDecoder(_resp.Body).Decode(&_rtn) - return _rtn, _err + var rtn Post + err = json.NewDecoder(resp.Body).Decode(&rtn) + return rtn, err +} + +func (c *Client) PatchUser(ctxt context.Context, id string, user PatchUserRequest) (User, error) { + return c.patchUser(ctxt, id, user) } -func (_c *Client) PatchUser(ctxt context.Context, id string, user PatchUserRequest) (User, error) { - _u, _err := _c.host.Parse(fmt.Sprintf("/api/v1/users/%v", id)) - if _err != nil { - return User{}, _err +func (c *Client) patchUser(ctxt context.Context, v0 string, v1 PatchUserRequest) (User, error) { + u, err := c.host.Parse(fmt.Sprintf("/api/v1/users/%v", v0)) + if err != nil { + return User{}, err } var ( - _body io.Reader - _resp *http.Response + body io.Reader + resp *http.Response ) - _buf := &bytes.Buffer{} - _body = _buf - if _err = json.NewEncoder(_buf).Encode(user); _err != nil { - return User{}, _err + buf := &bytes.Buffer{} + body = buf + if err = json.NewEncoder(buf).Encode(v1); err != nil { + return User{}, err } - _req, _err := http.NewRequest("PATCH", _u.String(), _body) - if _err != nil { - return User{}, _err + req, err := http.NewRequest("PATCH", u.String(), body) + if err != nil { + return User{}, err } - _resp, _err = _c.client.Do(_req.WithContext(ctxt)) - if _err != nil { - return User{}, _err + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return User{}, err } defer func() { - _, _ = io.Copy(ioutil.Discard, _resp.Body) - _ = _resp.Body.Close() + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() }() - if _err = _checkResponse(_resp); _err != nil { - return User{}, _err + if err = checkResponse(resp); err != nil { + return User{}, err } - var _rtn User - _err = json.NewDecoder(_resp.Body).Decode(&_rtn) - return _rtn, _err + var rtn User + err = json.NewDecoder(resp.Body).Decode(&rtn) + return rtn, err +} + +func (c *Client) PutPost(ctxt context.Context, post PutPostRequest) (Post, error) { + return c.putPost(ctxt, post) } -func (_c *Client) PutPost(ctxt context.Context, post PutPostRequest) (Post, error) { - _u, _err := _c.host.Parse("/api/v1/posts") - if _err != nil { - return Post{}, _err +func (c *Client) putPost(ctxt context.Context, v0 PutPostRequest) (Post, error) { + u, err := c.host.Parse("/api/v1/posts") + if err != nil { + return Post{}, err } var ( - _body io.Reader - _resp *http.Response + body io.Reader + resp *http.Response ) - _buf := &bytes.Buffer{} - _body = _buf - if _err = json.NewEncoder(_buf).Encode(post); _err != nil { - return Post{}, _err + buf := &bytes.Buffer{} + body = buf + if err = json.NewEncoder(buf).Encode(v0); err != nil { + return Post{}, err } - _req, _err := http.NewRequest("PUT", _u.String(), _body) - if _err != nil { - return Post{}, _err + req, err := http.NewRequest("PUT", u.String(), body) + if err != nil { + return Post{}, err } - _resp, _err = _c.client.Do(_req.WithContext(ctxt)) - if _err != nil { - return Post{}, _err + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return Post{}, err } defer func() { - _, _ = io.Copy(ioutil.Discard, _resp.Body) - _ = _resp.Body.Close() + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() }() - if _err = _checkResponse(_resp); _err != nil { - return Post{}, _err + if err = checkResponse(resp); err != nil { + return Post{}, err } - var _rtn Post - _err = json.NewDecoder(_resp.Body).Decode(&_rtn) - return _rtn, _err + var rtn Post + err = json.NewDecoder(resp.Body).Decode(&rtn) + return rtn, err } -func (_c *Client) PutUser(ctxt context.Context, user PutUserRequest) (User, error) { - _u, _err := _c.host.Parse("/api/v1/users") - if _err != nil { - return User{}, _err +func (c *Client) PutUser(ctxt context.Context, user PutUserRequest) (User, error) { + return c.putUser(ctxt, user) +} + +func (c *Client) putUser(ctxt context.Context, v0 PutUserRequest) (User, error) { + u, err := c.host.Parse("/api/v1/users") + if err != nil { + return User{}, err } var ( - _body io.Reader - _resp *http.Response + body io.Reader + resp *http.Response ) - _buf := &bytes.Buffer{} - _body = _buf - if _err = json.NewEncoder(_buf).Encode(user); _err != nil { - return User{}, _err + buf := &bytes.Buffer{} + body = buf + if err = json.NewEncoder(buf).Encode(v0); err != nil { + return User{}, err } - _req, _err := http.NewRequest("PUT", _u.String(), _body) - if _err != nil { - return User{}, _err + req, err := http.NewRequest("PUT", u.String(), body) + if err != nil { + return User{}, err } - _resp, _err = _c.client.Do(_req.WithContext(ctxt)) - if _err != nil { - return User{}, _err + resp, err = c.client.Do(req.WithContext(ctxt)) + if err != nil { + return User{}, err } defer func() { - _, _ = io.Copy(ioutil.Discard, _resp.Body) - _ = _resp.Body.Close() + _, _ = io.Copy(ioutil.Discard, resp.Body) + _ = resp.Body.Close() }() - if _err = _checkResponse(_resp); _err != nil { - return User{}, _err + if err = checkResponse(resp); err != nil { + return User{}, err } - var _rtn User - _err = json.NewDecoder(_resp.Body).Decode(&_rtn) - return _rtn, _err + var rtn User + err = json.NewDecoder(resp.Body).Decode(&rtn) + return rtn, err } -func _checkResponse(resp *http.Response) error { +func checkResponse(resp *http.Response) error { switch resp.StatusCode { case http.StatusOK: return nil diff --git a/example/server.go b/example/server.go index 367ebe9..3eef9cc 100644 --- a/example/server.go +++ b/example/server.go @@ -16,6 +16,8 @@ var _ = time.After var _ = strconv.Itoa type Service interface { + DeletePost(ctxt context.Context, id string) error + DeleteUser(ctxt context.Context, id string) error GetPost(ctxt context.Context, id string) (Post, error) GetPosts(ctxt context.Context, limit int64) ([]Post, error) GetUser(ctxt context.Context, id string) (User, error) @@ -37,6 +39,8 @@ func NewServer(srv Service) *Server { srv: srv, } + s.Router.Delete("/api/v1/posts/{id}", s.handleDeletePost) + s.Router.Delete("/api/v1/users/{id}", s.handleDeleteUser) s.Router.Get("/api/v1/posts/{id}", s.handleGetPost) s.Router.Get("/api/v1/posts", s.handleGetPosts) s.Router.Get("/api/v1/users/{id}", s.handleGetUser) @@ -49,9 +53,45 @@ func NewServer(srv Service) *Server { return s } +func (c *Server) handleDeletePost(w http.ResponseWriter, r *http.Request) { + + v0 := chi.URLParam(r, "id") + + r0, err := c.srv.DeletePost(r.Context(), v0) + if err != nil { + handleError(w, err) + return + } + + if err := json.NewEncoder(w).Encode(r0); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + + return +} + +func (c *Server) handleDeleteUser(w http.ResponseWriter, r *http.Request) { + + v0 := chi.URLParam(r, "id") + + r0, err := c.srv.DeleteUser(r.Context(), v0) + if err != nil { + handleError(w, err) + return + } + + if err := json.NewEncoder(w).Encode(r0); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + + return +} + func (c *Server) handleGetPost(w http.ResponseWriter, r *http.Request) { - id := chi.URLParam(r, "id") - r0, err := c.srv.GetPost(r.Context(), id) + + v0 := chi.URLParam(r, "id") + + r0, err := c.srv.GetPost(r.Context(), v0) if err != nil { handleError(w, err) return @@ -65,12 +105,14 @@ func (c *Server) handleGetPost(w http.ResponseWriter, r *http.Request) { } func (c *Server) handleGetPosts(w http.ResponseWriter, r *http.Request) { + q0 := r.URL.Query().Get("limit") - limit, err := strconv.ParseInt(q0, 10, 64) + v0, err := strconv.ParseInt(q0, 10, 64) if err != nil { return } - r0, err := c.srv.GetPosts(r.Context(), limit) + + r0, err := c.srv.GetPosts(r.Context(), v0) if err != nil { handleError(w, err) return @@ -84,8 +126,10 @@ func (c *Server) handleGetPosts(w http.ResponseWriter, r *http.Request) { } func (c *Server) handleGetUser(w http.ResponseWriter, r *http.Request) { - id := chi.URLParam(r, "id") - r0, err := c.srv.GetUser(r.Context(), id) + + v0 := chi.URLParam(r, "id") + + r0, err := c.srv.GetUser(r.Context(), v0) if err != nil { handleError(w, err) return @@ -99,12 +143,14 @@ func (c *Server) handleGetUser(w http.ResponseWriter, r *http.Request) { } func (c *Server) handleGetUsers(w http.ResponseWriter, r *http.Request) { + q0 := r.URL.Query().Get("limit") - limit, err := strconv.ParseInt(q0, 10, 64) + v0, err := strconv.ParseInt(q0, 10, 64) if err != nil { return } - r0, err := c.srv.GetUsers(r.Context(), limit) + + r0, err := c.srv.GetUsers(r.Context(), v0) if err != nil { handleError(w, err) return @@ -118,14 +164,16 @@ func (c *Server) handleGetUsers(w http.ResponseWriter, r *http.Request) { } func (c *Server) handlePatchPost(w http.ResponseWriter, r *http.Request) { - id := chi.URLParam(r, "id") - var post PatchPostRequest - if err := json.NewDecoder(r.Body).Decode(&post); err != nil { + + v0 := chi.URLParam(r, "id") + + var v1 PatchPostRequest + if err := json.NewDecoder(r.Body).Decode(&v1); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - r0, err := c.srv.PatchPost(r.Context(), id, post) + r0, err := c.srv.PatchPost(r.Context(), v0, v1) if err != nil { handleError(w, err) return @@ -139,14 +187,16 @@ func (c *Server) handlePatchPost(w http.ResponseWriter, r *http.Request) { } func (c *Server) handlePatchUser(w http.ResponseWriter, r *http.Request) { - id := chi.URLParam(r, "id") - var user PatchUserRequest - if err := json.NewDecoder(r.Body).Decode(&user); err != nil { + + v0 := chi.URLParam(r, "id") + + var v1 PatchUserRequest + if err := json.NewDecoder(r.Body).Decode(&v1); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - r0, err := c.srv.PatchUser(r.Context(), id, user) + r0, err := c.srv.PatchUser(r.Context(), v0, v1) if err != nil { handleError(w, err) return @@ -160,13 +210,14 @@ func (c *Server) handlePatchUser(w http.ResponseWriter, r *http.Request) { } func (c *Server) handlePutPost(w http.ResponseWriter, r *http.Request) { - var post PutPostRequest - if err := json.NewDecoder(r.Body).Decode(&post); err != nil { + + var v0 PutPostRequest + if err := json.NewDecoder(r.Body).Decode(&v0); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - r0, err := c.srv.PutPost(r.Context(), post) + r0, err := c.srv.PutPost(r.Context(), v0) if err != nil { handleError(w, err) return @@ -180,13 +231,14 @@ func (c *Server) handlePutPost(w http.ResponseWriter, r *http.Request) { } func (c *Server) handlePutUser(w http.ResponseWriter, r *http.Request) { - var user PutUserRequest - if err := json.NewDecoder(r.Body).Decode(&user); err != nil { + + var v0 PutUserRequest + if err := json.NewDecoder(r.Body).Decode(&v0); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - r0, err := c.srv.PutUser(r.Context(), user) + r0, err := c.srv.PutUser(r.Context(), v0) if err != nil { handleError(w, err) return diff --git a/example/swagger.json b/example/swagger.json index aa7ff7d..71aa37b 100644 --- a/example/swagger.json +++ b/example/swagger.json @@ -6,24 +6,18 @@ }, "components": { "schemas": { - "Post": { + "NotAuthorized": { "type": "object", "properties": { - "body": { - "type": "string", - "format": "base64" - }, - "title": { + "message": { "type": "string" - }, - "draft": { - "type": "boolean" - }, - "created": { - "type": "string", - "format": "date-time" - }, - "id": { + } + } + }, + "NotFound": { + "type": "object", + "properties": { + "message": { "type": "string" } } @@ -31,6 +25,9 @@ "User": { "type": "object", "properties": { + "id": { + "type": "string" + }, "name": { "type": "string" }, @@ -44,38 +41,60 @@ }, "labels": { "type": "object" - }, - "id": { - "type": "string" } } }, - "NotAuthorized": { + "PutUserRequest": { "type": "object", "properties": { - "message": { + "name": { "type": "string" + }, + "age": { + "type": "integer", + "format": "int64" + }, + "height": { + "type": "number", + "format": "float" + }, + "labels": { + "type": "object" } } }, - "NotFound": { + "PatchUserRequest": { "type": "object", "properties": { - "message": { + "name": { "type": "string" + }, + "age": { + "type": "integer", + "format": "int64" + }, + "height": { + "type": "number", + "format": "float" + }, + "labels": { + "type": "object" } } }, - "PutPostRequest": { + "Post": { "type": "object", "properties": { - "body": { - "type": "string", - "format": "base64" + "id": { + "type": "string" }, "title": { "type": "string" }, + "body": { + "type": "string", + "format": "base64" + }, "draft": { "type": "boolean" }, @@ -85,16 +104,16 @@ } } }, - "PatchPostRequest": { + "PutPostRequest": { "type": "object", "properties": { + "title": { + "type": "string" + }, "body": { "type": "string", "format": "base64" }, - "title": { - "type": "string" - }, "draft": { "type": "boolean" }, @@ -104,173 +123,156 @@ } } }, - "PutUserRequest": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "age": { - "type": "integer", - "format": "int64" - }, - "height": { - "type": "number", - "format": "float" - }, - "labels": { - "type": "object" - } - } - }, - "PatchUserRequest": { + "PatchPostRequest": { "type": "object", "properties": { - "name": { + "title": { "type": "string" }, - "age": { - "type": "integer", - "format": "int64" + "body": { + "type": "string", + "format": "base64" }, - "height": { - "type": "number", - "format": "float" + "draft": { + "type": "boolean" }, - "labels": { - "type": "object" + "created": { + "type": "string", + "format": "date-time" } } } } }, "paths": { - "/posts/{id}": { + "/users/{id}": { "get": { - "operationId": "GetPost", - "responses": { - "200": { - "description": "GetPost operation 200 response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Post" - } - } - } - } - }, + "operationId": "GetUser", "parameters": [ { "name": "id", - "schema": { - "type": "string" - }, "in": "path", "description": "id from path", - "required": true + "required": true, + "schema": { + "type": "string" + } } - ] - }, - "patch": { - "operationId": "PatchPost", + ], "responses": { "200": { - "description": "PatchPost operation 200 response", + "description": "GetUser operation 200 response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Post" + "$ref": "#/components/schemas/User" } } } } - }, + } + }, + "patch": { + "operationId": "PatchUser", "parameters": [ { "name": "id", - "schema": { - "type": "string" - }, "in": "path", "description": "id from path", - "required": true + "required": true, + "schema": { + "type": "string" + } } ], "requestBody": { - "description": "PatchPost operation request body", + "description": "PatchUser operation request body", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PatchPostRequest" + "$ref": "#/components/schemas/PatchUserRequest" } } } - } - } - }, - "/posts": { - "get": { - "operationId": "GetPosts", + }, "responses": { "200": { - "description": "GetPosts operation 200 response", + "description": "PatchUser operation 200 response", "content": { "application/json": { "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Post" - } + "$ref": "#/components/schemas/User" } } } } - }, + } + }, + "delete": { + "operationId": "DeleteUser", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "id from path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "DeleteUser operation 200 response" + } + } + } + }, + "/users": { + "get": { + "operationId": "GetUsers", "parameters": [ { "name": "limit", + "in": "query", + "description": "limit from query", "schema": { "type": "integer", "format": "int64" - }, - "in": "query", - "description": "limit from query" + } } - ] - }, - "put": { - "operationId": "PutPost", + ], "responses": { "200": { - "description": "PutPost operation 200 response", + "description": "GetUsers operation 200 response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Post" + "type": "array", + "items": { + "$ref": "#/components/schemas/User" + } } } } } - }, + } + }, + "put": { + "operationId": "PutUser", "requestBody": { - "description": "PutPost operation request body", + "description": "PutUser operation request body", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PutPostRequest" + "$ref": "#/components/schemas/PutUserRequest" } } } - } - } - }, - "/users/{id}": { - "get": { - "operationId": "GetUser", + }, "responses": { "200": { - "description": "GetUser operation 200 response", + "description": "PutUser operation 200 response", "content": { "application/json": { "schema": { @@ -279,106 +281,142 @@ } } } - }, + } + } + }, + "/posts/{id}": { + "get": { + "operationId": "GetPost", "parameters": [ { "name": "id", - "schema": { - "type": "string" - }, "in": "path", "description": "id from path", - "required": true + "required": true, + "schema": { + "type": "string" + } } - ] - }, - "patch": { - "operationId": "PatchUser", + ], "responses": { "200": { - "description": "PatchUser operation 200 response", + "description": "GetPost operation 200 response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/User" + "$ref": "#/components/schemas/Post" } } } } - }, + } + }, + "patch": { + "operationId": "PatchPost", "parameters": [ { "name": "id", - "schema": { - "type": "string" - }, "in": "path", "description": "id from path", - "required": true + "required": true, + "schema": { + "type": "string" + } } ], "requestBody": { - "description": "PatchUser operation request body", + "description": "PatchPost operation request body", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PatchUserRequest" + "$ref": "#/components/schemas/PatchPostRequest" } } } - } - } - }, - "/users": { - "get": { - "operationId": "GetUsers", + }, "responses": { "200": { - "description": "GetUsers operation 200 response", + "description": "PatchPost operation 200 response", "content": { "application/json": { "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/User" - } + "$ref": "#/components/schemas/Post" } } } } - }, + } + }, + "delete": { + "operationId": "DeletePost", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "id from path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "DeletePost operation 200 response" + } + } + } + }, + "/posts": { + "get": { + "operationId": "GetPosts", "parameters": [ { "name": "limit", + "in": "query", + "description": "limit from query", "schema": { "type": "integer", "format": "int64" - }, - "in": "query", - "description": "limit from query" + } } - ] - }, - "put": { - "operationId": "PutUser", + ], "responses": { "200": { - "description": "PutUser operation 200 response", + "description": "GetPosts operation 200 response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/User" + "type": "array", + "items": { + "$ref": "#/components/schemas/Post" + } } } } } - }, + } + }, + "put": { + "operationId": "PutPost", "requestBody": { - "description": "PutUser operation request body", + "description": "PutPost operation request body", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PutUserRequest" + "$ref": "#/components/schemas/PutPostRequest" + } + } + } + }, + "responses": { + "200": { + "description": "PutPost operation 200 response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Post" + } } } } diff --git a/go.mod b/go.mod index 455e56d..16c8b8b 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,14 @@ module github.com/TruceRPC/truce go 1.16 require ( - cuelang.org/go v0.2.2 + cuelang.org/go v0.3.0-beta.5 github.com/cockroachdb/apd/v2 v2.0.2 // indirect + github.com/emicklei/proto v1.9.0 // indirect github.com/pkg/errors v0.9.1 // indirect - golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect - golang.org/x/text v0.3.4 // indirect - golang.org/x/tools v0.1.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect + github.com/stretchr/testify v1.3.0 // indirect + golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d // indirect + golang.org/x/text v0.3.5 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect gotest.tools/v3 v3.0.3 ) diff --git a/go.sum b/go.sum index 75de48f..56dcde2 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cuelang.org/go v0.2.2 h1:i/wFo48WDibGHKQTRZ08nB8PqmGpVpQ2sRflZPj73nQ= -cuelang.org/go v0.2.2/go.mod h1:Dyjk8Y/B3CfFT1jQKJU0g5PpCeMiDe0yMOhk57oXwqo= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +cuelang.org/go v0.3.0-beta.5 h1:c+zS9MBCFzbuz+RI+3dp2PwfnS05aF3MqSEaAGFwzSk= +cuelang.org/go v0.3.0-beta.5/go.mod h1:Ikvs157igkGV5gFUdYSFa+lWp/CDteVhubPTXyvPRtA= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -23,12 +23,14 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/emicklei/proto v1.6.15 h1:XbpwxmuOPrdES97FrSfpyy67SSCV/wBIKXqgJzh6hNw= github.com/emicklei/proto v1.6.15/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= +github.com/emicklei/proto v1.9.0 h1:l0QiNT6Qs7Yj0Mb4X6dnWBQer4ebei2BFcgQLbGqUDc= +github.com/emicklei/proto v1.9.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -64,7 +66,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -93,7 +94,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/rogpeppe/go-internal v1.6.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.6.2-0.20200830194709-1115b6af0369 h1:wdCVGtPadWC/ZuuLC7Hv58VQ5UF7V98ewE71n5mJfrM= +github.com/rogpeppe/go-internal v1.6.2-0.20200830194709-1115b6af0369/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -105,35 +107,37 @@ github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHN github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20200513190911-00229845015e/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= +golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= +golang.org/x/exp v0.0.0-20210126221216-84987778548c/go.mod h1:I6l2HNBLBZEcrOoCpyKLdY2lHoRZ8lI4x60KMCQDft4= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -142,45 +146,39 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= -golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d h1:1aflnvSoWWLI2k/dMUAl5lvU1YO4Mb4hz0gh+1rjcxU= +golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc= -golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200612220849-54c614fe050c/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -200,8 +198,8 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= -gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/cmd/trucegen/main.go b/internal/cmd/trucegen/main.go deleted file mode 100644 index d275c69..0000000 --- a/internal/cmd/trucegen/main.go +++ /dev/null @@ -1,59 +0,0 @@ -package main - -import ( - "bytes" - "io" - "os" - - "cuelang.org/go/cue" - "cuelang.org/go/cue/load" - "cuelang.org/go/encoding/gocode" -) - -func main() { - cwd, err := os.Getwd() - if err != nil { - panic(err) - } - - inst := cue.Build(load.Instances([]string{"."}, &load.Config{ - Dir: cwd, - ModuleRoot: cwd, - Module: "github.com/TruceRPC/truce", - }))[0] - if err := inst.Err; err != nil { - panic(err) - } - - v, err := gocode.Generate(".", inst, &gocode.Config{ - RuntimeVar: "Runtime", - }) - if err != nil { - panic(err) - } - - // TODO(georgemac): put back ioutil.WriteFile once https://github.com/cuelang/cue/pull/664 is resolved. - fi, err := os.OpenFile("./truce.go", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) - if err != nil { - panic(err) - } - - defer fi.Close() - - buf := bytes.NewBuffer(v) - line, err := buf.ReadBytes('\n') - for ; err == nil; line, err = buf.ReadBytes('\n') { - if bytes.Contains(line, []byte("LookupField")) { - _, _ = fi.Write([]byte("\t//lint:ignore SA1019 until FieldByName is produced by cue gocode https://github.com/cuelang/cue/pull/664\n")) - } - - _, _ = fi.Write(line) - } - - if err != io.EOF { - panic(err) - } - - // write the final line - _, _ = fi.Write(line) -} diff --git a/internal/generate/openapi/testdata/service.cue b/internal/generate/openapi/testdata/service.cue index f933101..f1037c2 100644 --- a/internal/generate/openapi/testdata/service.cue +++ b/internal/generate/openapi/testdata/service.cue @@ -25,20 +25,7 @@ outputs: "example": "1": { openapi: { version: 3 - path: "example/swagger.json" - } - go: { - types: {path: "example/types.go", pkg: "example"} - server: { - path: "example/server.go" - type: "Server" - pkg: "example" - } - client: { - path: "example/client.go" - type: "Client" - pkg: "example" - } + path: "swagger.json" } } diff --git a/internal/generate/openapi/testdata/swagger.json.golden b/internal/generate/openapi/testdata/swagger.json.golden index e8338e8..6f90798 100644 --- a/internal/generate/openapi/testdata/swagger.json.golden +++ b/internal/generate/openapi/testdata/swagger.json.golden @@ -6,24 +6,18 @@ }, "components": { "schemas": { - "Post": { + "NotAuthorized": { "type": "object", "properties": { - "body": { - "type": "string", - "format": "base64" - }, - "title": { + "message": { "type": "string" - }, - "draft": { - "type": "boolean" - }, - "created": { - "type": "string", - "format": "date-time" - }, - "id": { + } + } + }, + "NotFound": { + "type": "object", + "properties": { + "message": { "type": "string" } } @@ -31,6 +25,9 @@ "User": { "type": "object", "properties": { + "id": { + "type": "string" + }, "name": { "type": "string" }, @@ -44,38 +41,60 @@ }, "labels": { "type": "object" - }, - "id": { - "type": "string" } } }, - "NotAuthorized": { + "PutUserRequest": { "type": "object", "properties": { - "message": { + "name": { "type": "string" + }, + "age": { + "type": "integer", + "format": "int64" + }, + "height": { + "type": "number", + "format": "float" + }, + "labels": { + "type": "object" } } }, - "NotFound": { + "PatchUserRequest": { "type": "object", "properties": { - "message": { + "name": { "type": "string" + }, + "age": { + "type": "integer", + "format": "int64" + }, + "height": { + "type": "number", + "format": "float" + }, + "labels": { + "type": "object" } } }, - "PutPostRequest": { + "Post": { "type": "object", "properties": { - "body": { - "type": "string", - "format": "base64" + "id": { + "type": "string" }, "title": { "type": "string" }, + "body": { + "type": "string", + "format": "base64" + }, "draft": { "type": "boolean" }, @@ -85,16 +104,16 @@ } } }, - "PatchPostRequest": { + "PutPostRequest": { "type": "object", "properties": { + "title": { + "type": "string" + }, "body": { "type": "string", "format": "base64" }, - "title": { - "type": "string" - }, "draft": { "type": "boolean" }, @@ -104,162 +123,126 @@ } } }, - "PutUserRequest": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "age": { - "type": "integer", - "format": "int64" - }, - "height": { - "type": "number", - "format": "float" - }, - "labels": { - "type": "object" - } - } - }, - "PatchUserRequest": { + "PatchPostRequest": { "type": "object", "properties": { - "name": { + "title": { "type": "string" }, - "age": { - "type": "integer", - "format": "int64" + "body": { + "type": "string", + "format": "base64" }, - "height": { - "type": "number", - "format": "float" + "draft": { + "type": "boolean" }, - "labels": { - "type": "object" + "created": { + "type": "string", + "format": "date-time" } } } } }, "paths": { - "/posts/{id}": { + "/users/{id}": { "get": { - "operationId": "GetPost", - "responses": { - "200": { - "description": "GetPost operation 200 response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Post" - } - } - } - } - }, + "operationId": "GetUser", "parameters": [ { "name": "id", - "schema": { - "type": "string" - }, "in": "path", "description": "id from path", - "required": true + "required": true, + "schema": { + "type": "string" + } } - ] - }, - "patch": { - "operationId": "PatchPost", + ], "responses": { "200": { - "description": "PatchPost operation 200 response", + "description": "GetUser operation 200 response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Post" + "$ref": "#/components/schemas/User" } } } } - }, + } + }, + "patch": { + "operationId": "PatchUser", "parameters": [ { "name": "id", - "schema": { - "type": "string" - }, "in": "path", "description": "id from path", - "required": true + "required": true, + "schema": { + "type": "string" + } } ], "requestBody": { - "description": "PatchPost operation request body", + "description": "PatchUser operation request body", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PatchPostRequest" + "$ref": "#/components/schemas/PatchUserRequest" } } } - } - } - }, - "/posts": { - "get": { - "operationId": "GetPosts", + }, "responses": { "200": { - "description": "GetPosts operation 200 response", + "description": "PatchUser operation 200 response", "content": { "application/json": { "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/Post" - } + "$ref": "#/components/schemas/User" } } } } } - }, - "put": { - "operationId": "PutPost", + } + }, + "/users": { + "get": { + "operationId": "GetUsers", "responses": { "200": { - "description": "PutPost operation 200 response", + "description": "GetUsers operation 200 response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/Post" + "type": "array", + "items": { + "$ref": "#/components/schemas/User" + } } } } } - }, + } + }, + "put": { + "operationId": "PutUser", "requestBody": { - "description": "PutPost operation request body", + "description": "PutUser operation request body", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PutPostRequest" + "$ref": "#/components/schemas/PutUserRequest" } } } - } - } - }, - "/users/{id}": { - "get": { - "operationId": "GetUser", + }, "responses": { "200": { - "description": "GetUser operation 200 response", + "description": "PutUser operation 200 response", "content": { "application/json": { "schema": { @@ -268,68 +251,85 @@ } } } - }, + } + } + }, + "/posts/{id}": { + "get": { + "operationId": "GetPost", "parameters": [ { "name": "id", - "schema": { - "type": "string" - }, "in": "path", "description": "id from path", - "required": true + "required": true, + "schema": { + "type": "string" + } } - ] - }, - "patch": { - "operationId": "PatchUser", + ], "responses": { "200": { - "description": "PatchUser operation 200 response", + "description": "GetPost operation 200 response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/User" + "$ref": "#/components/schemas/Post" } } } } - }, + } + }, + "patch": { + "operationId": "PatchPost", "parameters": [ { "name": "id", - "schema": { - "type": "string" - }, "in": "path", "description": "id from path", - "required": true + "required": true, + "schema": { + "type": "string" + } } ], "requestBody": { - "description": "PatchUser operation request body", + "description": "PatchPost operation request body", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PatchUserRequest" + "$ref": "#/components/schemas/PatchPostRequest" + } + } + } + }, + "responses": { + "200": { + "description": "PatchPost operation 200 response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Post" + } } } } } } }, - "/users": { + "/posts": { "get": { - "operationId": "GetUsers", + "operationId": "GetPosts", "responses": { "200": { - "description": "GetUsers operation 200 response", + "description": "GetPosts operation 200 response", "content": { "application/json": { "schema": { "type": "array", "items": { - "$ref": "#/components/schemas/User" + "$ref": "#/components/schemas/Post" } } } @@ -338,28 +338,28 @@ } }, "put": { - "operationId": "PutUser", + "operationId": "PutPost", + "requestBody": { + "description": "PutPost operation request body", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PutPostRequest" + } + } + } + }, "responses": { "200": { - "description": "PutUser operation 200 response", + "description": "PutPost operation 200 response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/User" + "$ref": "#/components/schemas/Post" } } } } - }, - "requestBody": { - "description": "PutUser operation request body", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/PutUserRequest" - } - } - } } } } diff --git a/spec.go b/spec.go index 9acbbf5..25ffdd6 100644 --- a/spec.go +++ b/spec.go @@ -4,8 +4,6 @@ import ( "cuelang.org/go/cue" ) -var Runtime = &cue.Runtime{} - type Specification struct { Outputs map[string]map[string]Output `cue:"outputs"` Specifications map[string]map[string]API `cue:"specifications"` @@ -17,7 +15,7 @@ func Compile(data []byte) (cue.Value, error) { return cue.Value{}, err } - filled, err := cuegenInstance.Fill(target.Value()) + filled, err := Instance.Fill(target.Value()) if err != nil { return cue.Value{}, err } diff --git a/truce.go b/truce.go index ebe620b..babe706 100644 --- a/truce.go +++ b/truce.go @@ -1,45 +1,38 @@ -// Code generated by gocode.Generate; DO NOT EDIT. - package truce import ( - "fmt" + _ "embed" "cuelang.org/go/cue" - "cuelang.org/go/encoding/gocode/gocodec" + "cuelang.org/go/cue/build" + _ "cuelang.org/go/pkg" +) + +var ( + //go:embed cue/truce.cue + truceSource []byte + //go:embed cue/openapi.cue + openAPISource []byte + + Runtime = &cue.Runtime{} + + Instance *cue.Instance ) -var cuegenCodec, cuegenInstance = func() (*gocodec.Codec, *cue.Instance) { - var r *cue.Runtime - r = Runtime - instances, err := r.Unmarshal(cuegenInstanceData) +func must(err error) { if err != nil { panic(err) } - if len(instances) != 1 { - panic("expected encoding of exactly one instance") - } - return gocodec.New(r, nil), instances[0] -}() - -// cuegenMake is called in the init phase to initialize CUE values for -// validation functions. -func cuegenMake(name string, x interface{}) cue.Value { - //lint:ignore SA1019 until FieldByName is produced by cue gocode https://github.com/cuelang/cue/pull/664 - f, err := cuegenInstance.LookupField(name) +} + +func init() { + instance := build.NewContext().NewInstance("cue", nil) + must(instance.AddFile("truce.cue", truceSource)) + must(instance.AddFile("openapi.cue", openAPISource)) + + var err error + Instance, err = Runtime.Build(instance) if err != nil { - panic(fmt.Errorf("could not find type %q in instance", name)) - } - v := f.Value - if x != nil { - w, err := cuegenCodec.ExtractType(x) - if err != nil { - panic(err) - } - v = v.Unify(w) + panic(err) } - return v } - -// Data size: 2040 bytes. -var cuegenInstanceData = []byte("\x01\x1f\x8b\b\x00\x00\x00\x00\x00\x00\xff\xbcY\xefn\u0738\x11_\xe5R\xa0\x12\xae\xfd\xde\x03\n\xd0\xdc \xd8u\u05b2\x1b\xf7\x0f*\xd4glm\xe7b\xe0\x1a/\x92\xed}\xa8\xac\x04\xf4.w\u035cD\xe9(\xca\x17'\xd9\x03\xda^\xaf}\xaa>T\x1f\xe0\\\fII\x94v\u05ce\x1b\xa3\xf9b\xeep\xe67?\xce\f\xc9\x11\xf3\xb3\xab\u007f\xdes\xee]\xfd\xab\xe3\\\xfd\xad\xd3\xf9\xdd\xd5_?q\x9cO\x19\xcf%\xe1\x13zH$\x01\xb9\xf3\x89s\xffy\x9aJ\xe7^\u01f9?\"\xf2\xdc\xf9\xb4\xe3\xfc\xe4\t\x8bi\xee\\\xfd\xd0\xe9t~y\xf5\x8f{\x8e\xf3\xf30\x9a\x14\u051f\xb1\xd8X\xfe\xd0q\xae\xbe\xeftzW\u007f\xff\xc4q~Z\u02ff\xef8\xf7\x9c\xfb\xcfHB\x01\xe8\xbe\x12z\x9dN\xe7\xc7\xcf\xfe\x03L\x1c\xc7\xf9\u015c\xc9\xf3\xe2\u031f\xa4\xc9\xf6X\x14\x13\xfa|t\xb0-a\xe08\x8e[\xf0\x84\x88\xfc\x9c\xc4\u038f\x9f\xfd;#\x93\xaf\u025c\"5\xeby,\xc9R!Q\xcfs\xb1\xa0s\xfa&\u00de\x8bs)\x18\x9f\xe7\xd8\xeb{\u07abn>9\xa7\t99{\x1d\xa0w\x9e\x1b\xea\xc9H\xfdp_\xc9\u02cc\x06\b!\xa4\xc5 b\xf9\x9fH\x0625\x89\xf6\xbeC\xf8eB\xb20\x8cz\xe1\xcb(\xeao\x86Q\xd4\xf37\xfb\x0f\xb0\xd6\x1e\nA.\x03t\x96\xa6\xb1\x16\x8c\x04K\x02T\t\xceH\xdev1KEBd`\x89\xd8\u030cs\u007f,X2\x12t\xc6\xde\xf4V\x88\xf0iO\xf1\xea\xe3\x01\xc2a\x84\xfb\x03\x847q\x1f\xed\xed!\u0338\xc4jY\xb5S\x90\xd19\x15XIK\xbf \xfd\xed\xafA\xb6\xb8+\u07f38%\x80\xd9\xf6\u03cb\xe4l\u027dR\xbeS\xf7\x10\xec%\xdf \xa4\x84\xb7\x9c\u07e9_\xc9\x12\x9aK\x92dK\xce5P\xcb\xf7\x94H\xba\x056wFb\xa3\xcc\xfb\u00c7w\x80\xa4\xc3x'PUA\xdc\t\x9a\x15\xe7\xbbY\u8964\xed\x94}\x14\xea\xda\x1a3\xa7\xc8\x1e(\xdb^\xab\x83cF\xe2\x9c\x1a\x919:\xa4(h\x83\xda\xearB\x18\xe6\x1b\x1bY{\xdbX\xef\xcd:\xd4\xc20\n\xa3\xc8\xdf|\x80\x9b\xde-\x95^\x18\x81N\u007f\xbf\x17nF\xfd\xfd\x90l\xbd-\rJ\x87\xea\xb84^\x12\x92\x8d\x88\x90y\x80\x90>\x8d\xfd'\x8cO\x87q\xfc\xa28K\x88\x9c\x9c\xf7\xd6\x1d\xa5\x03\xedu\x80v\xfb\x86\xccW$\xd6|*\xd4\xf0qt#+\xb7:\xd0!h\xe9\xd9k:Q\a\x8dK\xa6S&Y\xca\x015\u0368\x90\x8c\xe6\xfa\x0e(\x97a\x1c\x1a\x99\x01\xb2\x9d+\xf9\xa2\xb4\xd8X6y \xe8,@\xb8\xbb=I\x93,\xe5\x94\xcb|[\xdf>\xf9\xf6i\u03c6\xea\xe3\x1alQ\as\u00ce\xa6f\xa5\xd2f\x1chJ\x98\x80H\x030I\x93j\x19\xc6\xc2fT\xae\x02\xeaDK\x16\x95\xeaF[\xf7\x06\xfa\x80ax\x1b\x94\x8a~\tg\x93]&\xb3\xc4\x05Tt-\xab\x8a\xc5\x15\x93\xb2\xc0\xcd\xec\x92\xcfU\xf4?\x9c\xbd\x1d\xf5\x85\xb7\xf0\u048cr\x92\xb1]\x15\xc7Y*\x10\xc9\x18t+\x03\x18|EE\xceR\x9e#\xc6Q\x9e\xd1\t\x9b\xb1\t\x91J\x02\x8e\x8d\xba\xd1R\x16\x87t\x06\u02b6\xad\xa2\x88O{\x06\xb8\x8f\u02d4i\x99\u046b\u016e\xa1\x14 \xbc\xeb\xef\xf8\xbb&\xea\x8c\xcf\u04a0N-\x93\xb1*u\x83j\xc4\x17\x1a,\xb0\b42_\x87\xa7\x862q\xaa\x05j]\x90/\x1d\a\x18\xd5\xcb:\xa43\x1f$y\xad\x0e\v)\u056deXEkmE\xfd/[\u0686\xb5\xe7\x19\xa3\xf1T\xbbVC\xe3\xdb\xd0\xf0\x95,oX\x01\x81\xca\n\x18\xf4\xac\xc6\x0f=l\xea\x9a\xf5\x06-i\xd9\r\x96.\xd5\"\x1b\x1a\v\xfb\u05e2\xefk\x1co\xa5B=\xacF\xe5`\xd1HHF\xe4\xb9\x15\x03\xb5~n\x16\u03dbQ\x9f\x15|R\xd7^\xb5n\xae\xc8\n\xc2sh\x86s\xff\\\xca\xcc\a\xd8f*\xf0i}\x9f\xa5_\xa6\xdfR\xb1\xc64\xa1\xf2<\x9d\xf6[\x89\x84t\xa9\xca?\x9e\x06\x86a=\xf9*#\x82$TR\x91\a(Dj[\x88\xb9a\xaf\xbd\x101/\x12\xa8\xbbF\xd8\xd9\f\xad&Q\xa9\x87\x1a\xc8\xe7$\xa1\x11\x1c\x14\xbc\x88c\xe8\x02nc\xe7\xcfD\x9a\x98S\xe6\u007f6=K\xa7\x97\xb8Y4\xa0\xa1\xf6`m\xe0\xad(\xb4\x8f\xa8F\x83|\xfbZt\x19//B\x84n\xbfb\x1biJ\xf3\x89`\x99T\xe7\n\x9cY\xb5r\x1f\xa9\xf0\xac\xab\xc2k\x1c\xf4q\x83\xec\xed\xea@'\x05\xba*\xa8\xf3VR\\A\xbf)\x98\xa0\u04e0\xea\xa4VE\xcd\u07ac(\xb2j\x99\xa7\xfc(\xc9\xe4\xe5h\xa9\xa63(g\xab\xd6\x11\x9b\xa1\x98\xf2^\xd6G\x9f\xa3\x1d\xf4\x0ee\xa8\t\x05%\xb3|\xbe}\xd8\xd6\xf8\xff\ue37d\xd5\x05\xee^W\xb9\xebJ\xf7\xa6\xdam\x16o\xab\x94o:N]A\xf3,\xe5y\xfb\xe2\xc0\x8fwvp\x8bJ\xbbpuXt\xddV\xe7\x19z\xbc\xb3\x83J\xd0\xd5E)\xa8,\x04\xf73As\xcaek\xb9\x93\x94K\xca\xe5R\x140\u0272\xd8t\v\u06ef\xf3\x94\xb7\xd9\xdd\x14\xdd\xf5\xf1\xad\xef*\x9b\xder\x9c\u06d1^\xfa\xfdQ\x890\u017fb\xbf\x98\xed`!\xd8\xf7\xc3\n\x83k\xf1\xa1,\x97\x11a\x93\xd3\\\xfeqi\x87}`\u058d=REo\x9b\xaf\xc9\xe7\xaat*j\xb7\n\xda\xf5\xcd@\xbb5mv\x9c\xfa\x01\x8b\xef5\x9e\xb0\u008b\xfaww8:.\u02e8\xbc\x99\x90j\xff\xaa\xae\xf0\xc2\xea{\v\x99\x15\xf2f\xd4&\\\xfdfUv\xa9\xfb\x01\xea\x9ed\x94\x0fG\xc7'\n\xb2\xe1\x10\xed}\x87_\x86;[\xbf\x8f\x1e\xe9/\xb4y\xbao\xee\xa5\xee\x17ie\xb0\xf8p\u0795\x99\xa2\xa6:Q@\uc389\x98S\xe9\xb99\x15\x17T\x00\xab\xf1eF\xa7\xa5x\x123\xcae[\xbc\xf0\x9a\xdc\x15&\xdc)\u0593\x1dz\x8f6\xb1\xbf\x9d\u007fK\xe6s*|\x95{\xaf\xa6\xb6\v \x1a\u03b2\xb6L\xff\x90\xcbiZ\xc8\u03f1\xe7f_\u03c3\x06\xac\xa2\x8f\x15B\u036aZX\x03\xe6\x85Z\x17\xf6\xdcn\xcd}8:V\xcaU\xd4\xca\xecT\xec\x9a\xe1W\xeeL\x8a\xad\x94+\xe7\xcd\f\xf02\xe0n\xd5u\xae\xb0{b\xe6\xd6\xd9\xd67\u043e\xb6\x86{\br\xf0t<\x1e\x99t\xc2PM\x1a\xcep\xdb\xfa\xbeo\x9cxn\xa6\x1e^\x82jiT\x88T\x94d&\x16\x19\x00:\x82\u0252M.\x89,\xf2\x83tJ\x034\xb1\n\xa8dm\x85N\x85i\xb8\xf5\x97($[o\xe1\xafzO\xb8\x96~\x89\xa2\x16Z]\xad\x9a|\xf7\t|DD\x9e\xab\x8f\xe6\x00m\x82\xb5\xb9?\xaa7\x9f\x05z\x0f[G\xbfK(\x8b\xb2\x10nf\xa6?\xabT,\xb0*\x8f\\\x8aB}a\xe9\u03e3U\u0242\x895\x992yP\xe1S\xa6v\xec\x14\x85_m\xfd&R\x85\xf4\xee\xf1\xa2f\x80\xec3\x01B\v>\xda\xec\xc9\xd6\xdbU\xecS\xd1\xeb\x928\xee\xa3\xf7\xa0\xa6\x1f\x86\xc2\xcdh\x1fV\v&\x8f\u00a8\xf9\x1bk\u0357\xa5\xd0\x06-\xa7\u0523\u05b2\xc2>\xd6[\u074a\xb5\u07aceJ\xce\xd24\x868\ua3b1[e\xc3\xcet\xe3p(\xcbQ\u007f-\x05\b\u007fq4\x06\x16xt\xf2\xc2\f\xfel\xfe\x0e\xc7\aO\xd5\xe8d4>>y\xf6B\x8d\x0f\x8f\xbe<\x1a\x1f\xa9\xe1\u04e3\xe1\xa1\x1a\x1c\x9c<{vt\xa0\xad\xc6\u03c7\aG\xb8QYK\x19\x1d\x9a\xb9\xf5I\xcd\x04K\x98d\x17\xb0\xebC\xfd\xbe;\xd0/\u0183\xfa\x8dv`\x1eD\a\xd5;\xe3\xa0\xfab\x1f\u060f\xaf\x91\xd7\xcdc6\x010dZ\xe27\xd0\xc6Zn\xd0;\x84\xc3\xe8\xb4\xf7\xa6\x8fU/\xdc\xcdR\xc6\xed\x1ez\x95\xc1\xa6\xa5O\u2e3c\x1f,\xa5G\xc8x\x86Q\t\xe9U\x01\xb0*\xae\xcc\vt\xb5\x81\xe9i=\xd8i\xeb4\xd4\x17\x84\xe7^\x10Q\xff\x8f\xccu\xfa\xdf\x14T\\^kP\x9f\xc2$.j\x80\x85\xd7\xe9\xfc7\x00\x00\xff\xff\x19F\x88\x83\x82\x1b\x00\x00")