diff --git a/BUILD.bazel b/BUILD.bazel index 0df402e..a2f72ab 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,4 +1,3 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") load("@bazel_gazelle//:def.bzl", "gazelle") # gazelle:resolve go github.com/RMI/pacta/openapi/pacta //openapi:pacta_generated @@ -16,10 +15,3 @@ gazelle( ], command = "update-repos", ) - -go_library( - name = "pacta", - srcs = ["pacta.go"], - importpath = "github.com/RMI/pacta", - visibility = ["//visibility:public"], -) diff --git a/cmd/server/main.go b/cmd/server/main.go index e0cb6a8..bb2248c 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -13,7 +13,7 @@ import ( "github.com/RMI/pacta/cmd/server/pactasrv" "github.com/RMI/pacta/db/sqldb" "github.com/RMI/pacta/keyutil" - "github.com/RMI/pacta/openapi/pacta" + oapipacta "github.com/RMI/pacta/openapi/pacta" "github.com/Silicon-Ally/zaphttplog" "github.com/go-chi/chi/v5" "github.com/go-chi/httprate" @@ -107,7 +107,7 @@ func run(args []string) error { return fmt.Errorf("failed to init sqldb: %w", err) } - pactaSwagger, err := pacta.GetSwagger() + pactaSwagger, err := oapipacta.GetSwagger() if err != nil { return fmt.Errorf("failed to load PACTA swagger spec: %w", err) } @@ -116,12 +116,12 @@ func run(args []string) error { // that server names match. We don't know how this thing will be run. pactaSwagger.Servers = nil - // Create an instance of our handler which satisfies the generated interface - pactaSrv := &pactasrv.Server{ + // Create an instance of our handler which satisfies each generated interface + srv := &pactasrv.Server{ DB: db, } - pactaStrictHandler := pacta.NewStrictHandlerWithOptions(pactaSrv, nil /* middleware */, pacta.StrictHTTPServerOptions{ + pactaStrictHandler := oapipacta.NewStrictHandlerWithOptions(srv, nil /* middleware */, oapipacta.StrictHTTPServerOptions{ RequestErrorHandlerFunc: requestErrorHandlerFuncForService(logger, "pacta"), ResponseErrorHandlerFunc: responseErrorHandlerFuncForService(logger, "pacta"), }) @@ -129,7 +129,7 @@ func run(args []string) error { r := chi.NewRouter() // We now register our PACTA above as the handler for the interface - pacta.HandlerWithOptions(pactaStrictHandler, pacta.ChiServerOptions{ + oapipacta.HandlerWithOptions(pactaStrictHandler, oapipacta.ChiServerOptions{ BaseRouter: r.With( // The order of these is important. We run RequestID and RealIP first to // populate relevant metadata for logging, and we run recovery immediately after diff --git a/cmd/server/pactasrv/BUILD.bazel b/cmd/server/pactasrv/BUILD.bazel index aa09f3d..13c3ea2 100644 --- a/cmd/server/pactasrv/BUILD.bazel +++ b/cmd/server/pactasrv/BUILD.bazel @@ -1,8 +1,12 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "pactasrv", - srcs = ["pactasrv.go"], + srcs = [ + "pacta_version.go", + "pactasrv.go", + "user.go", + ], importpath = "github.com/RMI/pacta/cmd/server/pactasrv", visibility = ["//visibility:public"], deps = [ @@ -11,15 +15,3 @@ go_library( "//pacta", ], ) - -go_test( - name = "pactasrv_test", - srcs = ["pactasrv_test.go"], - embed = [":pactasrv"], - deps = [ - "//openapi:pacta_generated", - "@com_github_go_chi_jwtauth_v5//:jwtauth", - "@com_github_google_go_cmp//cmp", - "@com_github_lestrrat_go_jwx_v2//jwt", - ], -) diff --git a/cmd/server/pactasrv/pacta_version.go b/cmd/server/pactasrv/pacta_version.go new file mode 100644 index 0000000..608ecf0 --- /dev/null +++ b/cmd/server/pactasrv/pacta_version.go @@ -0,0 +1,38 @@ +package pactasrv + +import ( + "context" + "fmt" + + api "github.com/RMI/pacta/openapi/pacta" +) + +// Returns a version of the PACTA model by ID +// (GET /pacta-version/{id}) +func (s *Server) FindPactaVersionById(ctx context.Context, request api.FindPactaVersionByIdRequestObject) (api.FindPactaVersionByIdResponseObject, error) { + return nil, fmt.Errorf("not implemented") +} + +// Returns all versions of the PACTA model +// (GET /pacta-versions) +func (s *Server) ListPactaVersions(ctx context.Context, request api.ListPactaVersionsRequestObject) (api.ListPactaVersionsResponseObject, error) { + return nil, fmt.Errorf("not implemented") +} + +// Creates a PACTA version +// (POST /pacta-versions) +func (s *Server) CreatePactaVersion(ctx context.Context, request api.CreatePactaVersionRequestObject) (api.CreatePactaVersionResponseObject, error) { + return nil, fmt.Errorf("not implemented") +} + +// Updates a PACTA version +// (PATCH /pacta-version/{id}) +func (s *Server) UpdatePactaVersion(ctx context.Context, request api.UpdatePactaVersionRequestObject) (api.UpdatePactaVersionResponseObject, error) { + return nil, fmt.Errorf("not implemented") +} + +// Deletes a pacta version by ID +// (DELETE /pacta-version/{id}) +func (s *Server) DeletePactaVersion(ctx context.Context, request api.DeletePactaVersionRequestObject) (api.DeletePactaVersionResponseObject, error) { + return nil, fmt.Errorf("not implemented") +} diff --git a/cmd/server/pactasrv/pactasrv.go b/cmd/server/pactasrv/pactasrv.go index e9cd231..94b8092 100644 --- a/cmd/server/pactasrv/pactasrv.go +++ b/cmd/server/pactasrv/pactasrv.go @@ -1,16 +1,10 @@ -// Package pactasrv currently just implements the Petstore API interface, the -// bog standard OpenAPI example. It implements pactaapi.StrictServerInterface, -// which is auto-generated from the OpenAPI 3 spec. package pactasrv import ( "context" - "fmt" - "net/http" "github.com/RMI/pacta/db" - pactaapi "github.com/RMI/pacta/openapi/pacta" "github.com/RMI/pacta/pacta" ) @@ -66,92 +60,5 @@ type DB interface { } type Server struct { - DB DB - pets []pactaapi.Pet - idx int -} - -// Returns all pets -// (GET /pets) -func (s *Server) FindPets(ctx context.Context, req pactaapi.FindPetsRequestObject) (pactaapi.FindPetsResponseObject, error) { - out := []pactaapi.Pet{} - for _, p := range s.pets { - if matchesTag(req.Params.Tags, p.Tag) { - out = append(out, p) - } - } - if req.Params.Limit != nil && *req.Params.Limit > 0 && int(*req.Params.Limit) < len(out) { - out = out[:*req.Params.Limit] - } - - return pactaapi.FindPets200JSONResponse(out), nil -} - -func matchesTag(tags *[]string, tag *string) bool { - if tags == nil || tag == nil || len(*tags) == 0 { - return true - } - for _, t := range *tags { - if t == *tag { - return true - } - } - return false -} - -// Creates a new pet -// (POST /pets) -func (s *Server) AddPet(ctx context.Context, req pactaapi.AddPetRequestObject) (pactaapi.AddPetResponseObject, error) { - s.idx += 1 - id := int64(s.idx) - s.pets = append(s.pets, pactaapi.Pet{ - Id: id, - Name: req.Body.Name, - Tag: req.Body.Tag, - }) - return pactaapi.AddPet200JSONResponse{ - Id: id, - Name: req.Body.Name, - Tag: req.Body.Tag, - }, nil -} - -// Deletes a pet by ID -// (DELETE /pets/{id}) -func (s *Server) DeletePet(ctx context.Context, req pactaapi.DeletePetRequestObject) (pactaapi.DeletePetResponseObject, error) { - for i, p := range s.pets { - if p.Id == req.Id { - s.pets = append(s.pets[:i], s.pets[i+1:]...) - return pactaapi.DeletePet204Response{}, nil - } - } - return pactaapi.DeletePetdefaultJSONResponse{ - Body: pactaapi.Error{ - Code: 1, - Message: fmt.Sprintf("no pet with id %d", req.Id), - }, - StatusCode: http.StatusNotFound, - }, nil -} - -// Returns a pet by ID -// (GET /pets/{id}) -func (s *Server) FindPetByID(ctx context.Context, req pactaapi.FindPetByIDRequestObject) (pactaapi.FindPetByIDResponseObject, error) { - for _, p := range s.pets { - if p.Id == req.Id { - return pactaapi.FindPetByID200JSONResponse{ - Id: p.Id, - Name: p.Name, - Tag: p.Tag, - }, nil - } - } - - return pactaapi.FindPetByIDdefaultJSONResponse{ - Body: pactaapi.Error{ - Code: 2, - Message: fmt.Sprintf("no pet with id %d", req.Id), - }, - StatusCode: http.StatusNotFound, - }, nil + DB DB } diff --git a/cmd/server/pactasrv/pactasrv_test.go b/cmd/server/pactasrv/pactasrv_test.go deleted file mode 100644 index 24dd644..0000000 --- a/cmd/server/pactasrv/pactasrv_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package pactasrv - -import ( - "context" - "testing" - - "github.com/RMI/pacta/openapi/pacta" - "github.com/go-chi/jwtauth/v5" - "github.com/google/go-cmp/cmp" - "github.com/lestrrat-go/jwx/v2/jwt" -) - -func TestPets(t *testing.T) { - srv := &Server{} - - ctx := context.Background() - tkn := jwt.New() - tkn.Set("sub", "user123") - ctx = jwtauth.NewContext(ctx, tkn, nil) - - { - got, err := srv.FindPets(ctx, pacta.FindPetsRequestObject{ - Params: pacta.FindPetsParams{}, - }) - if err != nil { - t.Fatalf("srv.CreateRun: %v", err) - } - - want := pacta.FindPets200JSONResponse{} - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("unexpected create run response (-want +got)\n%s", diff) - } - } - - { - got, err := srv.AddPet(ctx, pacta.AddPetRequestObject{ - Body: &pacta.NewPet{ - Name: "Scruffles", - Tag: ptr("good boy"), - }, - }) - if err != nil { - t.Fatalf("srv.CreateRun: %v", err) - } - - want := pacta.AddPet200JSONResponse{ - Id: 1, - Name: "Scruffles", - Tag: ptr("good boy"), - } - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("unexpected create run response (-want +got)\n%s", diff) - } - } - - { - got, err := srv.FindPets(ctx, pacta.FindPetsRequestObject{ - Params: pacta.FindPetsParams{}, - }) - if err != nil { - t.Fatalf("srv.CreateRun: %v", err) - } - - want := pacta.FindPets200JSONResponse{ - pacta.Pet{ - Id: 1, - Name: "Scruffles", - Tag: ptr("good boy"), - }, - } - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("unexpected create run response (-want +got)\n%s", diff) - } - } -} - -func ptr[T any](in T) *T { - return &in -} diff --git a/cmd/server/pactasrv/user.go b/cmd/server/pactasrv/user.go new file mode 100644 index 0000000..74f8589 --- /dev/null +++ b/cmd/server/pactasrv/user.go @@ -0,0 +1,26 @@ +package pactasrv + +import ( + "context" + "fmt" + + api "github.com/RMI/pacta/openapi/pacta" +) + +// Returns a user by ID +// (GET /user/{id}) +func (s *Server) FindUserById(ctx context.Context, request api.FindUserByIdRequestObject) (api.FindUserByIdResponseObject, error) { + return nil, fmt.Errorf("not implemented") +} + +// Updates user properties +// (PATCH /user/{id}) +func (s *Server) UpdateUser(ctx context.Context, request api.UpdateUserRequestObject) (api.UpdateUserResponseObject, error) { + return nil, fmt.Errorf("not implemented") +} + +// Deletes a user by ID +// (DELETE /user/{id}) +func (s *Server) DeleteUser(ctx context.Context, request api.DeleteUserRequestObject) (api.DeleteUserResponseObject, error) { + return nil, fmt.Errorf("not implemented") +} diff --git a/frontend/openapi/generated/pacta/index.ts b/frontend/openapi/generated/pacta/index.ts index 7f940b7..9044c99 100644 --- a/frontend/openapi/generated/pacta/index.ts +++ b/frontend/openapi/generated/pacta/index.ts @@ -10,8 +10,12 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise'; export { OpenAPI } from './core/OpenAPI'; export type { OpenAPIConfig } from './core/OpenAPI'; +export type { EmptySuccess } from './models/EmptySuccess'; export type { Error } from './models/Error'; -export type { NewPet } from './models/NewPet'; -export type { Pet } from './models/Pet'; +export { Language } from './models/Language'; +export type { PactaVersion } from './models/PactaVersion'; +export type { PactaVersionChanges } from './models/PactaVersionChanges'; +export { User } from './models/User'; +export { UserChanges } from './models/UserChanges'; export { DefaultService } from './services/DefaultService'; diff --git a/frontend/openapi/generated/pacta/models/Pet.ts b/frontend/openapi/generated/pacta/models/EmptySuccess.ts similarity index 66% rename from frontend/openapi/generated/pacta/models/Pet.ts rename to frontend/openapi/generated/pacta/models/EmptySuccess.ts index a04949d..86ef93c 100644 --- a/frontend/openapi/generated/pacta/models/Pet.ts +++ b/frontend/openapi/generated/pacta/models/EmptySuccess.ts @@ -3,7 +3,4 @@ /* tslint:disable */ /* eslint-disable */ -import type { NewPet } from './NewPet'; - -export type Pet = NewPet; - +export type EmptySuccess = Record; diff --git a/frontend/openapi/generated/pacta/models/Language.ts b/frontend/openapi/generated/pacta/models/Language.ts new file mode 100644 index 0000000..f4462bc --- /dev/null +++ b/frontend/openapi/generated/pacta/models/Language.ts @@ -0,0 +1,11 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export enum Language { + EN = 'en', + FR = 'fr', + ES = 'es', + DE = 'de', +} diff --git a/frontend/openapi/generated/pacta/models/NewPet.ts b/frontend/openapi/generated/pacta/models/NewPet.ts deleted file mode 100644 index e07294c..0000000 --- a/frontend/openapi/generated/pacta/models/NewPet.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* generated using openapi-typescript-codegen -- do no edit */ -/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ - -export type NewPet = { - /** - * Name of the pet - */ - name: string; - /** - * Type of the pet - */ - tag?: string; -}; - diff --git a/frontend/openapi/generated/pacta/models/PactaVersion.ts b/frontend/openapi/generated/pacta/models/PactaVersion.ts new file mode 100644 index 0000000..8f1b996 --- /dev/null +++ b/frontend/openapi/generated/pacta/models/PactaVersion.ts @@ -0,0 +1,32 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type PactaVersion = { + /** + * Unique id of the pacta version - system assigned + */ + id: string; + /** + * the human meaningful name of the version of the PACTA model + */ + name: string; + /** + * Additional information about the version of the PACTA model + */ + description: string; + /** + * The hash (typically SHA256) that uniquely identifies this version of the PACTA model. + */ + digest: string; + /** + * The time at which this version of the PACTA model was created + */ + createdAt: string; + /** + * Whether this version of the PACTA model is the default version + */ + isDefault: boolean; +}; + diff --git a/frontend/openapi/generated/pacta/models/PactaVersionChanges.ts b/frontend/openapi/generated/pacta/models/PactaVersionChanges.ts new file mode 100644 index 0000000..2e04be2 --- /dev/null +++ b/frontend/openapi/generated/pacta/models/PactaVersionChanges.ts @@ -0,0 +1,24 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type PactaVersionChanges = { + /** + * the human meaningful name of the version of the PACTA model + */ + name?: string; + /** + * Additional information about the version of the PACTA model + */ + description?: string; + /** + * The hash (typically SHA256) that uniquely identifies this version of the PACTA model. + */ + digest?: string; + /** + * Whether this version of the PACTA model is the default version + */ + isDefault?: boolean; +}; + diff --git a/frontend/openapi/generated/pacta/models/User.ts b/frontend/openapi/generated/pacta/models/User.ts new file mode 100644 index 0000000..3502883 --- /dev/null +++ b/frontend/openapi/generated/pacta/models/User.ts @@ -0,0 +1,51 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type User = { + /** + * Unique id of the user + */ + id: string; + /** + * User's email address as entered + */ + enteredEmail: string; + /** + * Stanard formatting of the email address of the user + */ + canonicalEmail?: string; + /** + * Whether the user is an administrator of the PACTA platform + */ + admin: boolean; + /** + * Whether the user is an administrator of the PACTA platform + */ + superAdmin: boolean; + /** + * Name of the user + */ + name: string; + /** + * The user's preferred language, if present + */ + preferredLanguage: User.preferredLanguage; +}; + +export namespace User { + + /** + * The user's preferred language, if present + */ + export enum preferredLanguage { + EN = 'en', + FR = 'fr', + ES = 'es', + DE = 'de', + } + + +} + diff --git a/frontend/openapi/generated/pacta/models/UserChanges.ts b/frontend/openapi/generated/pacta/models/UserChanges.ts new file mode 100644 index 0000000..bef2650 --- /dev/null +++ b/frontend/openapi/generated/pacta/models/UserChanges.ts @@ -0,0 +1,39 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type UserChanges = { + /** + * The new name of the user + */ + name?: string; + /** + * The user's new preferred language + */ + preferredLanguage?: UserChanges.preferredLanguage; + /** + * Whether the given user is an admin + */ + admin?: boolean; + /** + * Whether the given user is a super admin + */ + superAdmin?: boolean; +}; + +export namespace UserChanges { + + /** + * The user's new preferred language + */ + export enum preferredLanguage { + EN = 'en', + FR = 'fr', + ES = 'es', + DE = 'de', + } + + +} + diff --git a/frontend/openapi/generated/pacta/services/DefaultService.ts b/frontend/openapi/generated/pacta/services/DefaultService.ts index 68271da..d6bb063 100644 --- a/frontend/openapi/generated/pacta/services/DefaultService.ts +++ b/frontend/openapi/generated/pacta/services/DefaultService.ts @@ -2,9 +2,12 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { EmptySuccess } from '../models/EmptySuccess'; import type { Error } from '../models/Error'; -import type { NewPet } from '../models/NewPet'; -import type { Pet } from '../models/Pet'; +import type { PactaVersion } from '../models/PactaVersion'; +import type { PactaVersionChanges } from '../models/PactaVersionChanges'; +import type { User } from '../models/User'; +import type { UserChanges } from '../models/UserChanges'; import type { CancelablePromise } from '../core/CancelablePromise'; import type { BaseHttpRequest } from '../core/BaseHttpRequest'; @@ -14,87 +17,182 @@ export class DefaultService { constructor(public readonly httpRequest: BaseHttpRequest) {} /** - * Returns all pets - * Returns all pets from the system that the user has access to - * Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. - * - * Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. - * - * @param tags tags to filter by - * @param limit maximum number of results to return - * @returns Pet pet response + * Returns a version of the PACTA model by ID + * @param id ID of pacta version to fetch + * @returns PactaVersion pacta response * @returns Error unexpected error * @throws ApiError */ - public findPets( - tags?: Array, - limit?: number, - ): CancelablePromise | Error> { + public findPactaVersionById( + id: string, + ): CancelablePromise { return this.httpRequest.request({ method: 'GET', - url: '/pets', + url: '/pacta-version/{id}', + path: { + 'id': id, + }, + }); + } + + /** + * Updates a PACTA version + * Updates a PACTA version's settable properties + * @param id ID of PACTA version to update + * @param body PACTA Version object properties to update + * @returns EmptySuccess pacta version updated successfully + * @returns Error unexpected error + * @throws ApiError + */ + public updatePactaVersion( + id: string, + body: PactaVersionChanges, + ): CancelablePromise { + return this.httpRequest.request({ + method: 'PATCH', + url: '/pacta-version/{id}', + path: { + 'id': id, + }, query: { - 'tags': tags, - 'limit': limit, + 'body': body, + }, + errors: { + 403: `caller does not have access or PACTA version does not exist`, + }, + }); + } + + /** + * Deletes a pacta version by ID + * deletes a single pacta version based on the ID supplied + * @param id ID of pacta version to delete + * @returns EmptySuccess pacta version deleted successfully + * @returns Error unexpected error + * @throws ApiError + */ + public deletePactaVersion( + id: string, + ): CancelablePromise { + return this.httpRequest.request({ + method: 'DELETE', + url: '/pacta-version/{id}', + path: { + 'id': id, + }, + errors: { + 403: `caller does not have access or pacta version does not exist`, }, }); } /** - * Creates a new pet - * Creates a new pet in the store. Duplicates are allowed - * @param requestBody Pet to add to the store - * @returns Pet pet response + * Returns all versions of the PACTA model + * @returns PactaVersion pacta versions * @returns Error unexpected error * @throws ApiError */ - public addPet( - requestBody: NewPet, - ): CancelablePromise { + public listPactaVersions(): CancelablePromise | Error> { + return this.httpRequest.request({ + method: 'GET', + url: '/pacta-versions', + }); + } + + /** + * Creates a PACTA version + * Creates a PACTA version + * @param body PACTA Version object properties to update + * @returns EmptySuccess pacta version created successfully + * @returns Error unexpected error + * @throws ApiError + */ + public createPactaVersion( + body: PactaVersion, + ): CancelablePromise { return this.httpRequest.request({ method: 'POST', - url: '/pets', - body: requestBody, - mediaType: 'application/json', + url: '/pacta-versions', + query: { + 'body': body, + }, + errors: { + 403: `caller does not have access to create PACTA versions`, + }, }); } /** - * Returns a pet by ID - * Returns a pet based on a single ID - * @param id ID of pet to fetch - * @returns Pet pet response + * Returns a user by ID + * Returns a user based on a single ID + * @param id ID of user to fetch + * @returns User user response * @returns Error unexpected error * @throws ApiError */ - public findPetById( - id: number, - ): CancelablePromise { + public findUserById( + id: string, + ): CancelablePromise { return this.httpRequest.request({ method: 'GET', - url: '/pets/{id}', + url: '/user/{id}', + path: { + 'id': id, + }, + errors: { + 403: `caller does not have access or user does not exist`, + }, + }); + } + + /** + * Updates user properties + * Updates a user's settable properties + * @param id ID of user to update + * @param body User object properties to update + * @returns User the new user object + * @returns Error unexpected error + * @throws ApiError + */ + public updateUser( + id: string, + body: UserChanges, + ): CancelablePromise { + return this.httpRequest.request({ + method: 'PATCH', + url: '/user/{id}', path: { 'id': id, }, + query: { + 'body': body, + }, + errors: { + 403: `caller does not have access or user does not exist`, + }, }); } /** - * Deletes a pet by ID - * deletes a single pet based on the ID supplied - * @param id ID of pet to delete + * Deletes a user by ID + * deletes a single user based on the ID supplied + * @param id ID of user to delete + * @returns EmptySuccess user deleted * @returns Error unexpected error * @throws ApiError */ - public deletePet( - id: number, - ): CancelablePromise { + public deleteUser( + id: string, + ): CancelablePromise { return this.httpRequest.request({ method: 'DELETE', - url: '/pets/{id}', + url: '/user/{id}', path: { 'id': id, }, + errors: { + 403: `caller does not have access or user does not exist`, + }, }); } diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue index 824c8a3..1cbc9f1 100644 --- a/frontend/pages/index.vue +++ b/frontend/pages/index.vue @@ -1,19 +1,19 @@ diff --git a/openapi/pacta.yaml b/openapi/pacta.yaml index dd7a5c7..6dce59c 100644 --- a/openapi/pacta.yaml +++ b/openapi/pacta.yaml @@ -4,8 +4,6 @@ info: title: RMI PACTA description: | API for interacting with RMI's Paris Agreement Capital Transition Assessment (PACTA) infrastructure - - Note: This is currently just the Swagger Petstore example until we start building out actual API endpoints. termsOfService: TODO contact: name: Silicon Ally @@ -16,42 +14,122 @@ info: url: https://mit-license.org/ servers: - url: TODO +definitions: + Language: + type: string + enum: &LANGUAGES + - en + - fr + - es + - de paths: - /pets: + /pacta-version/{id}: get: - summary: Returns all pets - description: | - Returns all pets from the system that the user has access to - Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. - - Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. - operationId: findPets + summary: Returns a version of the PACTA model by ID + operationId: findPactaVersionById parameters: - - name: tags - in: query - description: tags to filter by - required: false - style: form + - name: id + in: path + description: ID of pacta version to fetch + required: true schema: - type: array - items: - type: string - - name: limit + type: string + responses: + '200': + description: pacta response + content: + application/json: + schema: + $ref: '#/components/schemas/PactaVersion' + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + patch: + summary: Updates a PACTA version + description: Updates a PACTA version's settable properties + operationId: updatePactaVersion + parameters: + - name: id + in: path + description: ID of PACTA version to update + required: true + schema: + type: string + - name: body in: query - description: maximum number of results to return - required: false + description: PACTA Version object properties to update + required: true + schema: + $ref: '#/components/schemas/PactaVersionChanges' + responses: + '200': + description: pacta version updated successfully + content: + application/json: + schema: + $ref: '#/components/schemas/EmptySuccess' + + '403': + description: caller does not have access or PACTA version does not exist + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + delete: + summary: Deletes a pacta version by ID + description: deletes a single pacta version based on the ID supplied + operationId: deletePactaVersion + parameters: + - name: id + in: path + description: ID of pacta version to delete + required: true schema: - type: integer - format: int32 + type: string responses: '200': - description: pet response + description: pacta version deleted successfully + content: + application/json: + schema: + $ref: '#/components/schemas/EmptySuccess' + '403': + description: caller does not have access or pacta version does not exist + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + /pacta-versions: + get: + summary: Returns all versions of the PACTA model + operationId: listPactaVersions + responses: + '200': + description: pacta versions content: application/json: schema: type: array items: - $ref: '#/components/schemas/Pet' + $ref: '#/components/schemas/PactaVersion' default: description: unexpected error content: @@ -59,101 +137,242 @@ paths: schema: $ref: '#/components/schemas/Error' post: - summary: Creates a new pet - description: Creates a new pet in the store. Duplicates are allowed - operationId: addPet - requestBody: - description: Pet to add to the store - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/NewPet' + summary: Creates a PACTA version + description: Creates a PACTA version + operationId: createPactaVersion + parameters: + - name: body + in: query + description: PACTA Version object properties to update + required: true + schema: + $ref: '#/components/schemas/PactaVersion' responses: '200': - description: pet response + description: pacta version created successfully content: application/json: schema: - $ref: '#/components/schemas/Pet' + $ref: '#/components/schemas/EmptySuccess' + '403': + description: caller does not have access to create PACTA versions + content: + application/json: + schema: + $ref: '#/components/schemas/Error' default: description: unexpected error content: application/json: schema: $ref: '#/components/schemas/Error' - /pets/{id}: + + /user/{id}: get: - summary: Returns a pet by ID - description: Returns a pet based on a single ID - operationId: findPetByID + summary: Returns a user by ID + description: Returns a user based on a single ID + operationId: findUserById parameters: - name: id in: path - description: ID of pet to fetch + description: ID of user to fetch required: true schema: - type: integer - format: int64 + type: string responses: '200': - description: pet response + description: user response content: application/json: schema: - $ref: '#/components/schemas/Pet' + $ref: '#/components/schemas/User' + '403': + description: caller does not have access or user does not exist + content: + application/json: + schema: + $ref: '#/components/schemas/Error' default: description: unexpected error content: application/json: schema: $ref: '#/components/schemas/Error' + patch: + summary: Updates user properties + description: Updates a user's settable properties + operationId: updateUser + parameters: + - name: id + in: path + description: ID of user to update + required: true + schema: + type: string + - name: body + in: query + description: User object properties to update + required: true + schema: + $ref: '#/components/schemas/UserChanges' + responses: + '200': + description: the new user object + content: + application/json: + schema: + $ref: '#/components/schemas/User' + + '403': + description: caller does not have access or user does not exist + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + + default: + description: unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + delete: - summary: Deletes a pet by ID - description: deletes a single pet based on the ID supplied - operationId: deletePet + summary: Deletes a user by ID + description: deletes a single user based on the ID supplied + operationId: deleteUser parameters: - name: id in: path - description: ID of pet to delete + description: ID of user to delete required: true schema: - type: integer - format: int64 + type: string responses: - '204': - description: pet deleted + '200': + description: user deleted + content: + application/json: + schema: + $ref: '#/components/schemas/EmptySuccess' + '403': + description: caller does not have access or user does not exist + content: + application/json: + schema: + $ref: '#/components/schemas/Error' default: description: unexpected error content: application/json: schema: $ref: '#/components/schemas/Error' + components: schemas: - Pet: + Language: + type: string + enum: *LANGUAGES + + PactaVersion: + type: object + required: + - id + - name + - description + - digest + - createdAt + - isDefault + properties: + id: + type: string + description: Unique id of the pacta version - system assigned + name: + type: string + description: the human meaningful name of the version of the PACTA model + description: + type: string + description: Additional information about the version of the PACTA model + digest: + type: string + description: The hash (typically SHA256) that uniquely identifies this version of the PACTA model. + createdAt: + type: string + format: date-time + description: The time at which this version of the PACTA model was created + isDefault: + type: boolean + description: Whether this version of the PACTA model is the default version + + PactaVersionChanges: type: object - allOf: - - $ref: '#/components/schemas/NewPet' - - required: - - id - properties: - id: - type: integer - format: int64 - description: Unique id of the pet + properties: + name: + type: string + description: the human meaningful name of the version of the PACTA model + description: + type: string + description: Additional information about the version of the PACTA model + digest: + type: string + description: The hash (typically SHA256) that uniquely identifies this version of the PACTA model. + isDefault: + type: boolean + description: Whether this version of the PACTA model is the default version - NewPet: + User: type: object required: + - id + - enteredEmail + - requiredEmail + - admin + - superAdmin - name + - preferredLanguage + properties: + id: + type: string + description: Unique id of the user + enteredEmail: + type: string + description: User's email address as entered + canonicalEmail: + type: string + description: Stanard formatting of the email address of the user + admin: + type: boolean + description: Whether the user is an administrator of the PACTA platform + superAdmin: + type: boolean + description: Whether the user is an administrator of the PACTA platform + name: + type: string + description: Name of the user + preferredLanguage: + description: The user's preferred language, if present + type: string + enum: *LANGUAGES + + UserChanges: + type: object properties: name: type: string - description: Name of the pet - tag: + description: The new name of the user + preferredLanguage: + description: The user's new preferred language type: string - description: Type of the pet + enum: *LANGUAGES + admin: + type: boolean + description: Whether the given user is an admin + superAdmin: + type: boolean + description: Whether the given user is a super admin + + EmptySuccess: + type: object Error: type: object diff --git a/pacta.go b/pacta.go deleted file mode 100644 index a1c1e53..0000000 --- a/pacta.go +++ /dev/null @@ -1,24 +0,0 @@ -// Package pacta contains domain types for the PACTA ecosystem -package pacta - -import "time" - -type Provider string - -const ( - EmailAndPass Provider = "EMAIL_AND_PASS" - Facebook Provider = "FACEBOOK" - Google Provider = "GOOGLE" -) - -type UserID string - -// This is just an example struct -type User struct { - ID UserID - Name string - Email string - CreatedAt time.Time - AuthnProviderType Provider - AuthnProviderID UserID -}