Describe submission API in Swagger

This commit is contained in:
Filip Gralinski 2021-02-15 21:35:09 +01:00
parent 6686e9f845
commit fea7dabbd4
2 changed files with 67 additions and 0 deletions

View File

@ -406,6 +406,72 @@ getChallengeSubmissionR challengeName = do
(formWidget, formEnctype) <- generateFormPost $ submissionForm (Just defaultUrl) (defaultBranch scheme) (repoGitAnnexRemote repo) (formWidget, formEnctype) <- generateFormPost $ submissionForm (Just defaultUrl) (defaultBranch scheme) (repoGitAnnexRemote repo)
challengeLayout True challenge $ challengeSubmissionWidget formWidget formEnctype challenge 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 :: Text -> Handler Value
postChallengeSubmissionJsonR challengeName = do postChallengeSubmissionJsonR challengeName = do
Entity userId _ <- requireAuthPossiblyByToken Entity userId _ <- requireAuthPossiblyByToken

View File

@ -20,6 +20,7 @@ apiDescription = generalApi
<> mySubmissionsApi <> mySubmissionsApi
<> challengeReadmeInMarkdownApi <> challengeReadmeInMarkdownApi
<> queryApi <> queryApi
<> challengeSubmissionApi
generalApi :: Swagger generalApi :: Swagger
generalApi = (mempty :: Swagger) generalApi = (mempty :: Swagger)