Skip to content

Commit 80dcd62

Browse files
authored
Support Blueprint boolean constraints (#619)
1 parent 2afc124 commit 80dcd62

82 files changed

Lines changed: 168 additions & 107 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codegen/layouts/resource.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional, Union
1+
from typing import Any, Dict, List, Literal, Optional, Union
22
from dataclasses import dataclass
33
from ..deep_attr_dict import DeepAttrDict
44
from ..resource_mapping import ResourceMapping

codegen/layouts/route.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Any, List, Dict, Union
1+
from typing import Optional, Any, List, Dict, Literal, Union
22
import abc
33
from ..client import SeamHttpClient
44
from ..route import route_metadata

codegen/lib/layouts/resources.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ const mergeOccurrences = (occurrences: Property[], path: string): Property => {
107107
)
108108
}
109109

110+
if (first.format === 'boolean') {
111+
const booleans = occurrences as Array<
112+
Extract<Property, { format: 'boolean' }>
113+
>
114+
const values = booleans.some(({ values }) => values == null)
115+
? undefined
116+
: [...new Set(booleans.flatMap(({ values }) => values ?? []))]
117+
const merged = { ...first, ...docs }
118+
if (values == null) delete merged.values
119+
else merged.values = values
120+
return merged
121+
}
122+
110123
if (first.format === 'object') {
111124
return {
112125
...first,

codegen/lib/python-type.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const mapParameterToPythonType = (parameter: Parameter): string => {
1818
return parameter.isInt ? 'int' : 'float'
1919
}
2020

21+
if (parameter.format === 'boolean') {
22+
return mapBooleanToPythonType(parameter.values)
23+
}
24+
2125
return mapScalarFormatToPythonType(parameter.format)
2226
}
2327

@@ -51,6 +55,10 @@ export const mapRequiredPropertyToPythonType = (
5155
return property.isInt ? 'int' : 'float'
5256
}
5357

58+
if (property.format === 'boolean') {
59+
return mapBooleanToPythonType(property.values)
60+
}
61+
5462
// Batch resource properties are lists of the named resource on the wire,
5563
// though the blueprint types them as records.
5664
if (property.format === 'record' && 'resourceType' in property) {
@@ -64,6 +72,11 @@ export const mapRequiredPropertyToPythonType = (
6472
return mapScalarFormatToPythonType(property.format)
6573
}
6674

75+
const mapBooleanToPythonType = (values?: boolean[]): string =>
76+
values == null || values.length === 0
77+
? 'bool'
78+
: `Literal[${values.map((value) => (value ? 'True' : 'False')).join(', ')}]`
79+
6780
const mapScalarFormatToPythonType = (format: ScalarFormat): string => {
6881
switch (format) {
6982
case 'string':

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929
},
3030
"devDependencies": {
31-
"@seamapi/blueprint": "^1.5.1",
31+
"@seamapi/blueprint": "^1.6.0",
3232
"@seamapi/fake-seam-connect": "1.86.0",
3333
"@seamapi/smith": "^1.1.0",
3434
"@seamapi/types": "1.1001.0",

seam/resources/access_code.py

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seam/resources/access_grant.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seam/resources/access_method.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seam/resources/acs_access_group.py

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)