From 139e10cd3fc5b86de559b4a99690fd9d54b82206 Mon Sep 17 00:00:00 2001 From: Daniel Bell Date: Thu, 18 Jul 2024 14:51:10 -0500 Subject: [PATCH] alignment, reverted spec-kw generation --- .../yetanalytics/lrs/pedestal/openapi.cljc | 109 +++++++++--------- .../com/yetanalytics/lrs/pedestal/routes.cljc | 33 ++++-- 2 files changed, 77 insertions(+), 65 deletions(-) diff --git a/src/main/com/yetanalytics/lrs/pedestal/openapi.cljc b/src/main/com/yetanalytics/lrs/pedestal/openapi.cljc index b154e8f..8bad512 100644 --- a/src/main/com/yetanalytics/lrs/pedestal/openapi.cljc +++ b/src/main/com/yetanalytics/lrs/pedestal/openapi.cljc @@ -25,7 +25,7 @@ :type {} :moreinfo {} :extensions {}}}}} - :Agent ;maybe important + :Agent {:allOf [{:type :object :properties {:name :t#string :objectType :t#string}} @@ -41,14 +41,14 @@ :r#IFI]}]} :Actor {:oneOf [:r#Group :r#Agent]} - + :Error (gs/o {:error :t#string}) :IFI {:oneOf [(gs/o {:mbox :r#MailToIRI}) (gs/o {:mbox_sha1sum :t#string}) (gs/o {:openid :r#URI}) (gs/o {:account :r#Account})]} - + :IRI {:type :string :format :iri} :IRL :t#string :MailToIRI {:type :string :format :email} @@ -89,28 +89,27 @@ :operationId :get-activity-profile :description "Fetches the specified Profile document in the context of the specified Activity. The semantics of the request are driven by the \"profileId\" parameter. If it is included, the GET method will act upon a single defined document identified by \"profileId\". Otherwise, GET will return the available ids."} - :xapi.activities.profile.PUT.request/params {:params {:activityId :r#IRI :profileId :t#string} :requestBody (g/request :t#object) :responses {204 (g/response "No content")} :operationId :put-activity-profile :description "Stores or changes the specified Profile document in the context of the specified Activity."} - + :xapi.activities.profile.POST.request/params {:params {:activityId :r#IRI :profileId :t#string} - :requestBody(g/request :t#object) + :requestBody (g/request :t#object) :responses {204 (g/response "No content")} :operationId :post-activity-profile :description "Stores or changes the specified Profile document in the context of the specified Activity."} - + :xapi.activities.profile.DELETE.request/params {:params {:activityId :r#IRI :profileId :t#string} :responses {204 (g/response "No content")} :operationId :delete-activity-profile :description "Deletes the specified Profile document in the context of the specified Activity."} - + :xapi.activities.state.GET.request/params {:params {:activityId :r#IRI :agent :r#Agent @@ -129,7 +128,7 @@ :?#registration :r#UUID :stateId :t#string} :requestBody (g/request :t#object) - :responses {204 (g/response "No content" )} + :responses {204 (g/response "No content")} :operationId :put-state :description "Stores or changes the document specified by the given stateId that exists in the context of the specified Activity, Agent, and registration (if specified)."} :xapi.activities.state.POST.request/params @@ -138,7 +137,7 @@ :?#registration :r#UUID :stateId :t#string} :requestBody (g/request :t#object) - :responses {204 (g/response "No content" )} + :responses {204 (g/response "No content")} :operationId :post-state :description "Stores or changes the document specified by the given stateId that exists in the context of the specified Activity, Agent, and registration (if specified)."} :xapi.activities.state.DELETE.request/params @@ -146,7 +145,7 @@ :agent :r#Agent :?#registration :r#UUID :?#stateId :t#string} - :responses {204 (g/response "No content" )} + :responses {204 (g/response "No content")} :operationId :delete-state :description "Deletes all documents associated with the specified Activity, Agent, and registration (if specified), or just the document specified by stateId"} :xapi.agents.profile.GET.request/params @@ -178,56 +177,54 @@ :operationId :delete-agents-profile :description "Deletes the specified Profile document in the context of the specified Agent."})) +(def annotations + {:health {:operationId :health + :responses {200 (gc/response "Empty body---a 200 indicates server is alive")} + :description "Simple heartbeat"} + :about {:operationId :get-about + :description "About info" + :responses + {200 (gc/response "Object containing body text and optional etag" + (gc/o {:body :t#string + :#?etag :t#string}))}} + :statements-get {:params {:?#statementId :t#string + :?#voidedStatementId :t#string + :?#agent :r#Actor + :?#verb :r#IRI + :?#activity :r#IRI + :?#registration :r#UUID + :?#related_activities :t#boolean + :?#related_agents :t#boolean + :?#since :r#Timestamp + :?#limit :t#integer + :?#format :t#string + :?#attachments :t#boolean + :?#ascending :t#boolean} + :responses {200 (gc/response "Requested Statement or Results" + {:oneOf [:r#Statement + :r#StatementResult]})} + :operationId :get-statement + :description "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#21-statement-resource"} -(def annotations - {:health {:operationId :health - :responses {200 (gc/response "Empty body---a 200 indicates server is alive")} - :description "Simple heartbeat"} - :about {:operationId :get-about - :description "About info" - :responses - {200 (gc/response "Object containing body text and optional etag" - (gc/o {:body :t#string - :#?etag :t#string}))}} - :statements-get {:params {:?#statementId :t#string - :?#voidedStatementId :t#string - :?#agent :r#Actor - :?#verb :r#IRI - :?#activity :r#IRI - :?#registration :r#UUID - :?#related_activities :t#boolean - :?#related_agents :t#boolean - :?#since :r#Timestamp - :?#limit :t#integer - :?#format :t#string - :?#attachments :t#boolean - :?#ascending :t#boolean} - - :responses {200 (gc/response "Requested Statement or Results" - {:oneOf [:r#Statement - :r#StatementResult]})} - :operationId :get-statement - :description "https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Communication.md#21-statement-resource"} - - :statements-put {:params {:statementId :t#string} - :requestBody (gc/request :r#Statement) - :responses {204 (gc/response "No content")} - :operationId :put-statement - :description ""} + :statements-put {:params {:statementId :t#string} + :requestBody (gc/request :r#Statement) + :responses {204 (gc/response "No content")} + :operationId :put-statement + :description ""} :statements-post {:requestBody (gc/request {:oneOf [(gc/a :r#statementId) :r#statementId]}) - :responses {200 (gc/response "Array of Statement id(s) (UUID) in the same order as the corresponding stored Statements." - (gc/a :r#statementId))} + :responses {200 (gc/response "Array of Statement id(s) (UUID) in the same order as the corresponding stored Statements." + (gc/a :r#statementId))} :operationId :post-statement :description "Stores a Statement, or a set of Statements."} - :agents-post {:params {:agent :r#Agent} - :responses {200 (gc/response "Return a special, Person Object for a specified Agent. The Person Object is very similar to an Agent Object, but instead of each attribute having a single value, each attribute has an array value, and it is legal to include multiple identifying properties." - :r#Person)} - :operationId :get-agent - :description "Gets a specified agent"} - :activities-post {:params {:activityId :r#IRI} - :responses {200 (gc/response "The requested Activity object" - :r#Activity)} + :agents-post {:params {:agent :r#Agent} + :responses {200 (gc/response "Return a special, Person Object for a specified Agent. The Person Object is very similar to an Agent Object, but instead of each attribute having a single value, each attribute has an array value, and it is legal to include multiple identifying properties." + :r#Person)} + :operationId :get-agent + :description "Gets a specified agent"} + :activities-post {:params {:activityId :r#IRI} + :responses {200 (gc/response "The requested Activity object" + :r#Activity)} :operationId :get-activity :description "Gets the Activity with the specified activityId"}}) diff --git a/src/main/com/yetanalytics/lrs/pedestal/routes.cljc b/src/main/com/yetanalytics/lrs/pedestal/routes.cljc index a243817..6e5bf79 100644 --- a/src/main/com/yetanalytics/lrs/pedestal/routes.cljc +++ b/src/main/com/yetanalytics/lrs/pedestal/routes.cljc @@ -43,16 +43,31 @@ method method-not-allowed :route-name (keyword route-name-ns (name method))] - (let [method-kw (case method - :head :get - method) - method-str (-> method-kw name clojure.string/upper-case) - token-vec ["xapi" resource doc-type method-str "request/params"] - spec-kw (-> (clojure.string/join \. token-vec) - keyword) + (let [spec-kw + (case resource-tuple + ["activities" "state"] + (case method + :put :xapi.activities.state.PUT.request/params + :post :xapi.activities.state.POST.request/params + :get :xapi.activities.state.GET.request/params + :head :xapi.activities.state.GET.request/params + :delete :xapi.activities.state.DELETE.request/params) + ["activities" "profile"] + (case method + :put :xapi.activities.profile.PUT.request/params + :post :xapi.activities.profile.POST.request/params + :get :xapi.activities.profile.GET.request/params + :head :xapi.activities.profile.GET.request/params + :delete :xapi.activities.profile.DELETE.request/params) + ["agents" "profile"] + (case method + :put :xapi.agents.profile.PUT.request/params + :post :xapi.agents.profile.POST.request/params + :get :xapi.agents.profile.GET.request/params + :head :xapi.agents.profile.GET.request/params + :delete :xapi.agents.profile.DELETE.request/params)) doc-params-interceptor - (xapi-i/params-interceptor spec-kw) - + (xapi-i/params-interceptor spec-kw) params-interceptors (cond-> [doc-params-interceptor] ;; Scan files if scanner is present on PUT/POST