From fea7dabbd4241496a38acb34ff746a38e39fa0f7 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Mon, 15 Feb 2021 21:35:09 +0100 Subject: [PATCH] Describe submission API in Swagger --- Handler/ShowChallenge.hs | 66 ++++++++++++++++++++++++++++++++++++++++ Handler/Swagger.hs | 1 + 2 files changed, 67 insertions(+) diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index 2444acc..f0b51b8 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -406,6 +406,72 @@ getChallengeSubmissionR challengeName = do (formWidget, formEnctype) <- generateFormPost $ submissionForm (Just defaultUrl) (defaultBranch scheme) (repoGitAnnexRemote repo) challengeLayout True challenge $ challengeSubmissionWidget formWidget formEnctype challenge + +declareChallengeSubmissionSwagger :: Declare (Definitions Schema) Swagger +declareChallengeSubmissionSwagger = do + -- param schemas + let challengeNameSchema = toParamSchema (Proxy :: Proxy String) + let stringSchema = toParamSchema (Proxy :: Proxy String) + + challengeSubmissionResponse <- declareResponse (Proxy :: Proxy Int) + + return $ mempty + & paths .~ + fromList [ ("/api/challenge-submission/{challengeName}", + mempty & DS.post ?~ (mempty + & parameters .~ [ Inline $ mempty + & name .~ "challengeName" + & required ?~ True + & schema .~ ParamOther (mempty + & in_ .~ ParamPath + & paramSchema .~ challengeNameSchema), + Inline $ mempty + & name .~ "f1" + & description .~ Just "submission description" + & required ?~ False + & schema .~ ParamOther (mempty + & in_ .~ ParamFormData + & paramSchema .~ stringSchema), + Inline $ mempty + & name .~ "f2" + & description .~ Just "submission tags" + & required ?~ False + & schema .~ ParamOther (mempty + & in_ .~ ParamFormData + & paramSchema .~ stringSchema), + Inline $ mempty + & name .~ "f3" + & description .~ Just "repo URL" + & required ?~ True + & schema .~ ParamOther (mempty + & in_ .~ ParamFormData + & paramSchema .~ stringSchema), + Inline $ mempty + & name .~ "f4" + & description .~ Just "repo branch" + & required ?~ True + & schema .~ ParamOther (mempty + & in_ .~ ParamFormData + & paramSchema .~ stringSchema), + + Inline $ mempty + & name .~ "f5" + & description .~ Just "git-annex remote specification" + & required ?~ False + & schema .~ ParamOther (mempty + & in_ .~ ParamFormData + & paramSchema .~ stringSchema)] + & produces ?~ MimeList ["application/json"] + & description ?~ "Initiates a submission based on a given repo URL/branch. Returns an asynchrous job ID." + & at 200 ?~ Inline challengeSubmissionResponse)) + ] + +challengeSubmissionApi :: Swagger +challengeSubmissionApi = spec & definitions .~ defs + where + (defs, spec) = runDeclare declareChallengeSubmissionSwagger mempty + + postChallengeSubmissionJsonR :: Text -> Handler Value postChallengeSubmissionJsonR challengeName = do Entity userId _ <- requireAuthPossiblyByToken diff --git a/Handler/Swagger.hs b/Handler/Swagger.hs index f45e8ed..5f20f1d 100644 --- a/Handler/Swagger.hs +++ b/Handler/Swagger.hs @@ -20,6 +20,7 @@ apiDescription = generalApi <> mySubmissionsApi <> challengeReadmeInMarkdownApi <> queryApi + <> challengeSubmissionApi generalApi :: Swagger generalApi = (mempty :: Swagger)