@@ -98,6 +98,13 @@ instance ToJSON NamespaceDetails where
98
98
" readme" .= readme
99
99
]
100
100
101
+ instance FromJSON NamespaceDetails where
102
+ parseJSON = Aeson. withObject " NamespaceDetails" \ obj -> do
103
+ fqn <- obj .: " fqn"
104
+ hash <- obj .: " hash"
105
+ readme <- obj .: " readme"
106
+ pure $ NamespaceDetails {.. }
107
+
101
108
deriving instance ToSchema NamespaceDetails
102
109
103
110
-- | A hash qualified name, unlike HashQualified, the hash is required
@@ -168,6 +175,15 @@ instance ToJSON TypeDefinition where
168
175
" typeDocs" .= typeDocs
169
176
]
170
177
178
+ instance FromJSON TypeDefinition where
179
+ parseJSON = Aeson. withObject " TypeDefinition" \ obj -> do
180
+ typeNames <- obj .: " typeNames"
181
+ bestTypeName <- obj .: " bestTypeName"
182
+ defnTypeTag <- obj .: " defnTypeTag"
183
+ typeDefinition <- obj .: " typeDefinition"
184
+ typeDocs <- obj .: " typeDocs"
185
+ pure $ TypeDefinition {.. }
186
+
171
187
deriving instance ToSchema TypeDefinition
172
188
173
189
instance ToJSON TermDefinition where
@@ -181,6 +197,16 @@ instance ToJSON TermDefinition where
181
197
" termDocs" .= termDocs
182
198
]
183
199
200
+ instance FromJSON TermDefinition where
201
+ parseJSON = Aeson. withObject " TermDefinition" \ obj -> do
202
+ termNames <- obj .: " termNames"
203
+ bestTermName <- obj .: " bestTermName"
204
+ defnTermTag <- obj .: " defnTermTag"
205
+ termDefinition <- obj .: " termDefinition"
206
+ signature <- obj .: " signature"
207
+ termDocs <- obj .: " termDocs"
208
+ pure $ TermDefinition {.. }
209
+
184
210
deriving instance ToSchema TermDefinition
185
211
186
212
instance ToJSON DefinitionDisplayResults where
@@ -191,6 +217,13 @@ instance ToJSON DefinitionDisplayResults where
191
217
" missingDefinitions" .= missingDefinitions
192
218
]
193
219
220
+ instance FromJSON DefinitionDisplayResults where
221
+ parseJSON = Aeson. withObject " DefinitionDisplayResults" \ obj -> do
222
+ termDefinitions <- obj .: " termDefinitions"
223
+ typeDefinitions <- obj .: " typeDefinitions"
224
+ missingDefinitions <- obj .: " missingDefinitions"
225
+ pure $ DefinitionDisplayResults {.. }
226
+
194
227
deriving instance ToSchema DefinitionDisplayResults
195
228
196
229
data TermDefinitionDiff = TermDefinitionDiff
@@ -296,6 +329,25 @@ instance ToJSON SemanticSyntaxDiff where
296
329
" toAnnotation" .= toAnnotation
297
330
]
298
331
332
+ instance FromJSON SemanticSyntaxDiff where
333
+ parseJSON = Aeson. withObject " SemanticSyntaxDiff" \ obj -> do
334
+ diffTag :: Text <- obj .: " diffTag"
335
+ case diffTag of
336
+ " old" -> Old <$> obj .: " elements"
337
+ " new" -> New <$> obj .: " elements"
338
+ " both" -> Both <$> obj .: " elements"
339
+ " segmentChange" -> do
340
+ fromSegment <- obj .: " fromSegment"
341
+ toSegment <- obj .: " toSegment"
342
+ annotation <- obj .: " annotation"
343
+ pure $ SegmentChange (fromSegment, toSegment) annotation
344
+ " annotationChange" -> do
345
+ segment <- obj .: " segment"
346
+ fromAnnotation <- obj .: " fromAnnotation"
347
+ toAnnotation <- obj .: " toAnnotation"
348
+ pure $ AnnotationChange segment (fromAnnotation, toAnnotation)
349
+ _ -> fail " Invalid diffTag"
350
+
299
351
-- | A diff of the syntax of a term or type
300
352
--
301
353
-- It doesn't make sense to diff builtins with ABTs, so in that case we just provide the
@@ -504,6 +556,20 @@ instance ToJSON TermDiffResponse where
504
556
" newTerm" .= newTerm
505
557
]
506
558
559
+ instance FromJSON TermDiffResponse where
560
+ parseJSON = Aeson. withObject " TermDiffResponse" \ obj -> do
561
+ diff <- DisplayObjectDiff <$> obj .: " diff"
562
+ diffKind :: Text <- obj .: " diffKind"
563
+ project <- obj .: " project"
564
+ oldBranch <- obj .: " oldBranchRef"
565
+ newBranch <- obj .: " newBranchRef"
566
+ oldTerm <- obj .: " oldTerm"
567
+ newTerm <- obj .: " newTerm"
568
+ case diffKind of
569
+ " diff" -> pure $ TermDiffResponse {.. }
570
+ " mismatched" -> pure $ TermDiffResponse {.. }
571
+ _ -> fail " Invalid diffKind"
572
+
507
573
data TypeDiffResponse = TypeDiffResponse
508
574
{ project :: ProjectName ,
509
575
oldBranch :: ProjectBranchName ,
@@ -542,5 +608,19 @@ instance ToJSON TypeDiffResponse where
542
608
" newType" .= newType
543
609
]
544
610
611
+ instance FromJSON TypeDiffResponse where
612
+ parseJSON = Aeson. withObject " TypeDiffResponse" \ obj -> do
613
+ diff <- DisplayObjectDiff <$> obj .: " diff"
614
+ diffKind :: Text <- obj .: " diffKind"
615
+ project <- obj .: " project"
616
+ oldBranch <- obj .: " oldBranchRef"
617
+ newBranch <- obj .: " newBranchRef"
618
+ oldType <- obj .: " oldType"
619
+ newType <- obj .: " newType"
620
+ case diffKind of
621
+ " diff" -> pure $ TypeDiffResponse {.. }
622
+ " mismatched" -> pure $ TypeDiffResponse {.. }
623
+ _ -> fail " Invalid diffKind"
624
+
545
625
-- | Servant utility for a query param that's required, providing a useful error message if it's missing.
546
626
type RequiredQueryParam = Servant. QueryParam' '[Servant. Required , Servant. Strict ]
0 commit comments