forked from filipg/gonito
Clean up Swagger documentation, enhance properties
Breaking change: "version" property for leaderboard entry is a list of integers now
This commit is contained in:
parent
387ffae20d
commit
30c7727d6a
@ -520,14 +520,20 @@ gatherSHA1ForCollectionOfFiles files = do
|
|||||||
contentss <- mapM readFile $ sort files
|
contentss <- mapM readFile $ sort files
|
||||||
return $ CHS.finalize $ foldl' CHS.update CHS.init contentss
|
return $ CHS.finalize $ foldl' CHS.update CHS.init contentss
|
||||||
|
|
||||||
|
anonymizedLabel :: Text
|
||||||
|
anonymizedLabel = "[anonymized]"
|
||||||
|
|
||||||
|
nameNotGivenLabel :: Text
|
||||||
|
nameNotGivenLabel = "[name not given]"
|
||||||
|
|
||||||
formatSubmitter :: User -> Text
|
formatSubmitter :: User -> Text
|
||||||
formatSubmitter user = if userIsAnonymous user
|
formatSubmitter user = if userIsAnonymous user
|
||||||
then
|
then
|
||||||
"[anonymised]"
|
anonymizedLabel
|
||||||
else
|
else
|
||||||
case userName user of
|
case userName user of
|
||||||
Just name -> name
|
Just name -> name
|
||||||
Nothing -> "[name not given]"
|
Nothing -> nameNotGivenLabel
|
||||||
|
|
||||||
fieldWithTooltip :: forall master msg msg1. (RenderMessage master msg, RenderMessage master msg1) => msg -> msg1 -> FieldSettings master
|
fieldWithTooltip :: forall master msg msg1. (RenderMessage master msg, RenderMessage master msg1) => msg -> msg1 -> FieldSettings master
|
||||||
fieldWithTooltip name tooltip = (bfs name) { fsTooltip = Just $ SomeMessage tooltip }
|
fieldWithTooltip name tooltip = (bfs name) { fsTooltip = Just $ SomeMessage tooltip }
|
||||||
|
@ -75,7 +75,7 @@ instance ToJSON LeaderboardEntry where
|
|||||||
[ "submitter" .= (formatSubmitter $ leaderboardUser entry)
|
[ "submitter" .= (formatSubmitter $ leaderboardUser entry)
|
||||||
, "team" .= (teamIdent <$> entityVal <$> leaderboardTeam entry)
|
, "team" .= (teamIdent <$> entityVal <$> leaderboardTeam entry)
|
||||||
, "when" .= (submissionStamp $ leaderboardBestSubmission entry)
|
, "when" .= (submissionStamp $ leaderboardBestSubmission entry)
|
||||||
, "version" .= (formatVersion $ leaderboardVersion entry)
|
, "version" .= leaderboardVersion entry
|
||||||
, "description" .= descriptionToBeShown (leaderboardBestSubmission entry)
|
, "description" .= descriptionToBeShown (leaderboardBestSubmission entry)
|
||||||
(leaderboardBestVariant entry)
|
(leaderboardBestVariant entry)
|
||||||
(leaderboardParams entry)
|
(leaderboardParams entry)
|
||||||
@ -84,6 +84,8 @@ instance ToJSON LeaderboardEntry where
|
|||||||
, "isPublic" .= (submissionIsPublic $ leaderboardBestSubmission entry)
|
, "isPublic" .= (submissionIsPublic $ leaderboardBestSubmission entry)
|
||||||
, "isReevaluable" .= (leaderboardIsReevaluable entry)
|
, "isReevaluable" .= (leaderboardIsReevaluable entry)
|
||||||
, "isVisible" .= (leaderboardIsVisible entry)
|
, "isVisible" .= (leaderboardIsVisible entry)
|
||||||
|
, "id" .= (leaderboardBestSubmissionId entry)
|
||||||
|
, "variant" .= (leaderboardBestVariantId entry)
|
||||||
]
|
]
|
||||||
|
|
||||||
declareLeaderboardSwagger :: Declare (Definitions Schema) Swagger
|
declareLeaderboardSwagger :: Declare (Definitions Schema) Swagger
|
||||||
@ -155,6 +157,44 @@ addJsonKey :: Text -> Value -> Value -> Value
|
|||||||
addJsonKey key val (Object xs) = Object $ HMS.insert key val xs
|
addJsonKey key val (Object xs) = Object $ HMS.insert key val xs
|
||||||
addJsonKey _ _ xs = xs
|
addJsonKey _ _ xs = xs
|
||||||
|
|
||||||
|
|
||||||
|
-- Helper definitions for properties used in more than one place
|
||||||
|
|
||||||
|
isVisibleSchema :: Referenced Schema
|
||||||
|
isVisibleSchema = Inline $ toSchema (DPR.Proxy :: DPR.Proxy Bool)
|
||||||
|
& description .~ Just "Whether the details of the submissions are visible (i.e. either the submission is public or the user has the right permissions)"
|
||||||
|
|
||||||
|
isPublicSchema :: Referenced Schema
|
||||||
|
isPublicSchema = Inline $ toSchema (DPR.Proxy :: DPR.Proxy Bool)
|
||||||
|
& description .~ Just "Whether the submissions is public (i.e. whether its details are available to everyone)"
|
||||||
|
|
||||||
|
hashSchema :: Referenced Schema
|
||||||
|
hashSchema = Inline $ toSchema (DPR.Proxy :: DPR.Proxy String)
|
||||||
|
& description .~ Just "Git SHA1 commit hash; could be used as an argument for queries (if the submission is visible)"
|
||||||
|
& example .~ Just "ec41f0e2636bfedbd765c9871c813f7c5b896c51"
|
||||||
|
|
||||||
|
versionSchema :: Referenced Schema
|
||||||
|
versionSchema = Inline $ toSchema (DPR.Proxy :: DPR.Proxy [Int])
|
||||||
|
& description .~ Just "Challenge version under which the submission was done"
|
||||||
|
& example .~ Just (toJSON [2 :: Int, 0, 1])
|
||||||
|
|
||||||
|
submitterSchema :: Referenced Schema
|
||||||
|
submitterSchema = Inline $ toSchema (DPR.Proxy :: DPR.Proxy String)
|
||||||
|
& description .~ Just ("Name of the submitter, might be a special value in square brackets, e.g. " <> anonymizedLabel <> " or " <> nameNotGivenLabel)
|
||||||
|
& example .~ Just "John Smith"
|
||||||
|
|
||||||
|
submissionIdSchema :: Referenced Schema
|
||||||
|
submissionIdSchema = Inline $ toSchema (DPR.Proxy :: DPR.Proxy Int)
|
||||||
|
& description .~ Just "Internal database identifier of the submission"
|
||||||
|
& example .~ Just(toJSON (42 :: Int))
|
||||||
|
|
||||||
|
variantIdSchema :: Referenced Schema
|
||||||
|
variantIdSchema = Inline $ toSchema (DPR.Proxy :: DPR.Proxy Int)
|
||||||
|
& description .~ Just "Internal database identifier of the submission variant"
|
||||||
|
& example .~ Just (toJSON (53 :: Int))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
instance ToJSON LeaderboardEntryView where
|
instance ToJSON LeaderboardEntryView where
|
||||||
toJSON v = addJsonKey "evaluations"
|
toJSON v = addJsonKey "evaluations"
|
||||||
(toJSON $ leaderboardEntryViewEvaluations v)
|
(toJSON $ leaderboardEntryViewEvaluations v)
|
||||||
@ -163,23 +203,28 @@ instance ToJSON LeaderboardEntryView where
|
|||||||
instance ToSchema LeaderboardEntryView where
|
instance ToSchema LeaderboardEntryView where
|
||||||
declareNamedSchema _ = do
|
declareNamedSchema _ = do
|
||||||
stringSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy String)
|
stringSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy String)
|
||||||
intSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy Int)
|
|
||||||
boolSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy Bool)
|
boolSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy Bool)
|
||||||
evaluationsSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy [EvaluationView])
|
evaluationsSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy [EvaluationView])
|
||||||
|
|
||||||
return $ NamedSchema (Just "LeaderboardEntry") $ mempty
|
return $ NamedSchema (Just "LeaderboardEntry") $ mempty
|
||||||
& type_ .~ SwaggerObject
|
& type_ .~ SwaggerObject
|
||||||
& properties .~
|
& properties .~
|
||||||
fromList [ ("submitter", stringSchema)
|
fromList [ ("submitter", submitterSchema)
|
||||||
, ("team", stringSchema)
|
, ("team", stringSchema)
|
||||||
, ("when", stringSchema)
|
, ("when", stringSchema)
|
||||||
, ("version", stringSchema)
|
, ("version", versionSchema)
|
||||||
, ("description", stringSchema)
|
, ("description", stringSchema)
|
||||||
, ("times", intSchema)
|
, ("times", Inline $ toSchema (DPR.Proxy :: DPR.Proxy Int)
|
||||||
, ("hash", stringSchema)
|
& description .~ Just "How many times a submission from the same user/of the same tag was submitted"
|
||||||
|
& minProperties .~ Just 1
|
||||||
|
& example .~ Just (toJSON (2:: Int)))
|
||||||
|
, ("hash", hashSchema)
|
||||||
, ("evaluations", evaluationsSchema)
|
, ("evaluations", evaluationsSchema)
|
||||||
, ("isPublic", boolSchema)
|
, ("isPublic", isPublicSchema)
|
||||||
, ("isReevaluable", boolSchema)
|
, ("isReevaluable", boolSchema)
|
||||||
, ("isVisible", boolSchema)
|
, ("isVisible", isVisibleSchema)
|
||||||
|
, ("id", submissionIdSchema)
|
||||||
|
, ("variantId", variantIdSchema)
|
||||||
]
|
]
|
||||||
& required .~ [ "submitter", "when", "version", "description", "times", "hash", "evaluations" ]
|
& required .~ [ "submitter", "when", "version", "description", "times", "hash", "evaluations" ]
|
||||||
|
|
||||||
@ -1255,26 +1300,25 @@ instance ToSchema SubmissionView where
|
|||||||
stringSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy String)
|
stringSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy String)
|
||||||
boolSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy Bool)
|
boolSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy Bool)
|
||||||
intSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy Int)
|
intSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy Int)
|
||||||
intsSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy [Int])
|
|
||||||
tagsSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy [TagView])
|
tagsSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy [TagView])
|
||||||
evalsSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy [EvaluationView])
|
evalsSchema <- declareSchemaRef (DPR.Proxy :: DPR.Proxy [EvaluationView])
|
||||||
return $ NamedSchema (Just "SubmissionView") $ mempty
|
return $ NamedSchema (Just "SubmissionView") $ mempty
|
||||||
& type_ .~ SwaggerObject
|
& type_ .~ SwaggerObject
|
||||||
& properties .~
|
& properties .~
|
||||||
fromList [ ("id", intSchema)
|
fromList [ ("id", submissionIdSchema)
|
||||||
, ("variant", intSchema)
|
, ("variant", variantIdSchema)
|
||||||
, ("rank", intSchema)
|
, ("rank", intSchema)
|
||||||
, ("submitter", stringSchema)
|
, ("submitter", submitterSchema)
|
||||||
, ("when", stringSchema)
|
, ("when", stringSchema)
|
||||||
, ("version", intsSchema)
|
, ("version", versionSchema)
|
||||||
, ("description", stringSchema)
|
, ("description", stringSchema)
|
||||||
, ("tags", tagsSchema)
|
, ("tags", tagsSchema)
|
||||||
, ("hash", stringSchema)
|
, ("hash", hashSchema)
|
||||||
, ("evaluations", evalsSchema)
|
, ("evaluations", evalsSchema)
|
||||||
, ("isOwner", boolSchema)
|
, ("isOwner", boolSchema)
|
||||||
, ("isReevaluable", boolSchema)
|
, ("isReevaluable", boolSchema)
|
||||||
, ("isVisible", boolSchema)
|
, ("isVisible", isVisibleSchema)
|
||||||
, ("isPublic", boolSchema)
|
, ("isPublic", isPublicSchema)
|
||||||
, ("team", stringSchema)
|
, ("team", stringSchema)
|
||||||
]
|
]
|
||||||
& required .~ [ "id", "variant", "rank", "submitter", "when", "version",
|
& required .~ [ "id", "variant", "rank", "submitter", "when", "version",
|
||||||
|
Loading…
Reference in New Issue
Block a user