Skip to content

Commit de511cb

Browse files
authored
Merge pull request #829 from hackworthltd/georgefst/structured-textbody
feat!: Use structured text for names in trees, instead of hardcoding dot
2 parents 33c4709 + 08dcafc commit de511cb

File tree

7 files changed

+369
-59
lines changed

7 files changed

+369
-59
lines changed

primer-service/src/Primer/OpenAPI.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import Primer.API (
5050
Selection (..),
5151
Tree,
5252
)
53+
import Primer.API qualified as API
5354
import Primer.Action.Available qualified as Available
5455
import Primer.App (NodeType)
5556
import Primer.App.Base (Level)
@@ -59,6 +60,7 @@ import Primer.Core (
5960
ID (..),
6061
LVarName,
6162
ModuleName,
63+
PrimCon,
6264
)
6365
import Primer.Database (
6466
LastModified,
@@ -121,6 +123,8 @@ deriving via GlobalName 'ADefName instance ToSchema (GlobalName 'AValCon)
121123

122124
deriving via Name instance (ToSchema LVarName)
123125
deriving via PrimerJSON Tree instance ToSchema Tree
126+
deriving via PrimerJSON API.Name instance ToSchema API.Name
127+
deriving via PrimerJSON PrimCon instance ToSchema PrimCon
124128
deriving via PrimerJSON NodeBody instance ToSchema NodeBody
125129
deriving via PrimerJSON NodeFlavor instance ToSchema NodeFlavor
126130
deriving via PrimerJSON Def instance ToSchema Def

primer-service/test/Tests/OpenAPI.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import Primer.Database (
4848
safeMkSessionName,
4949
)
5050
import Primer.Gen.API (genExprTreeOpts)
51+
import Primer.Gen.API qualified as API
5152
import Primer.Gen.Core.Raw (
5253
ExprGen,
5354
evalExprGen,
@@ -171,7 +172,7 @@ tasty_NodeBody :: Property
171172
tasty_NodeBody =
172173
testToJSON $
173174
G.choice
174-
[ TextBody <$> G.text (R.linear 1 20) G.unicode
175+
[ TextBody <$> API.genName
175176
, BoxBody <$> genTree
176177
, pure NoBody
177178
]

primer-service/test/outputs/OpenAPI/openapi.json

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,24 @@
232232
],
233233
"type": "object"
234234
},
235+
"Name": {
236+
"properties": {
237+
"baseName": {
238+
"type": "string"
239+
},
240+
"qualifiedModule": {
241+
"items": {
242+
"type": "string"
243+
},
244+
"minItems": 1,
245+
"type": "array"
246+
}
247+
},
248+
"required": [
249+
"baseName"
250+
],
251+
"type": "object"
252+
},
235253
"NewSessionReq": {
236254
"properties": {
237255
"name": {
@@ -270,7 +288,7 @@
270288
{
271289
"properties": {
272290
"contents": {
273-
"type": "string"
291+
"$ref": "#/components/schemas/Name"
274292
},
275293
"tag": {
276294
"enum": [
@@ -285,6 +303,24 @@
285303
],
286304
"type": "object"
287305
},
306+
{
307+
"properties": {
308+
"contents": {
309+
"$ref": "#/components/schemas/PrimCon"
310+
},
311+
"tag": {
312+
"enum": [
313+
"PrimBody"
314+
],
315+
"type": "string"
316+
}
317+
},
318+
"required": [
319+
"tag",
320+
"contents"
321+
],
322+
"type": "object"
323+
},
288324
{
289325
"properties": {
290326
"contents": {
@@ -484,6 +520,50 @@
484520
],
485521
"type": "object"
486522
},
523+
"PrimCon": {
524+
"oneOf": [
525+
{
526+
"properties": {
527+
"contents": {
528+
"example": "?",
529+
"maxLength": 1,
530+
"minLength": 1,
531+
"type": "string"
532+
},
533+
"tag": {
534+
"enum": [
535+
"PrimChar"
536+
],
537+
"type": "string"
538+
}
539+
},
540+
"required": [
541+
"tag",
542+
"contents"
543+
],
544+
"type": "object"
545+
},
546+
{
547+
"properties": {
548+
"contents": {
549+
"type": "integer"
550+
},
551+
"tag": {
552+
"enum": [
553+
"PrimInt"
554+
],
555+
"type": "string"
556+
}
557+
},
558+
"required": [
559+
"tag",
560+
"contents"
561+
],
562+
"type": "object"
563+
}
564+
],
565+
"type": "object"
566+
},
487567
"Prog": {
488568
"properties": {
489569
"modules": {

primer/gen/Primer/Gen/API.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
13
module Primer.Gen.API (
24
genExprTreeOpts,
5+
genName,
36
) where
47

58
import Foreword
69

710
import Hedgehog (MonadGen)
11+
import Hedgehog.Gen qualified as G
812
import Hedgehog.Gen qualified as Gen
9-
import Primer.API (ExprTreeOpts (..))
13+
import Hedgehog.Range qualified as R
14+
import Primer.API (ExprTreeOpts (..), Name (..))
15+
import Primer.Gen.Core.Raw qualified as Raw
16+
import Primer.Name (unsafeMkName)
1017

1118
genExprTreeOpts :: MonadGen m => m ExprTreeOpts
1219
genExprTreeOpts = do
1320
patternsUnder <- Gen.bool
1421
pure ExprTreeOpts{patternsUnder}
22+
23+
genName :: MonadGen m => m Name
24+
genName = do
25+
baseName <- unsafeMkName <$> G.text (R.linear 1 20) G.unicode
26+
qualifiedModule <- G.maybe Raw.genModuleName
27+
pure Name{..}

0 commit comments

Comments
 (0)