Skip to content

Commit 9b08239

Browse files
committed
feat: support boolean literal constraints
1 parent c246fe8 commit 9b08239

15 files changed

Lines changed: 52 additions & 25 deletions

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Please refer to the official [Seam Docs](https://docs.seam.co/latest/) to get st
1414
Parts of this SDK are generated from always up-to-date type information
1515
provided by [@seamapi/types](https://github.com/seamapi/types/).
1616
This ensures all API methods, request shapes, and response shapes are
17-
accurate and fully typed.
17+
accurate and fully typed. Ruby cannot statically enforce literal booleans, so
18+
the generated YARD types use `TrueClass` and `FalseClass` to document singleton
19+
constraints.
1820

1921
<!-- toc -->
2022

‎codegen/lib/handlebars-helpers.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,20 @@ const nullable = (
3434
value: { isOptional: boolean; isNullable: boolean },
3535
): string => (value.isOptional || value.isNullable ? `${type}, nil` : type)
3636

37-
const scalarType = (format: string, isInt = false): string => {
37+
const scalarType = (
38+
format: string,
39+
isInt = false,
40+
booleanValues?: boolean[],
41+
): string => {
3842
switch (format) {
39-
case 'boolean':
40-
return 'Boolean'
43+
case 'boolean': {
44+
const values = [...new Set(booleanValues)]
45+
return values.length === 1
46+
? values[0]
47+
? 'TrueClass'
48+
: 'FalseClass'
49+
: 'Boolean'
50+
}
4151
case 'number':
4252
return isInt ? 'Integer' : 'Float'
4353
case 'datetime':
@@ -61,6 +71,7 @@ export const rubyPropertyType = (property: Property): string => {
6171
: scalarType(
6272
property.format,
6373
property.format === 'number' && property.isInt,
74+
property.format === 'boolean' ? property.values : undefined,
6475
)
6576
// BaseResource normalizes response lists to [] even when the API sends nil.
6677
return nullable(
@@ -93,6 +104,7 @@ export const rubyParameterType = (parameter: Parameter): string => {
93104
: scalarType(
94105
parameter.format,
95106
parameter.format === 'number' && parameter.isInt,
107+
parameter.format === 'boolean' ? parameter.values : undefined,
96108
)
97109
// Only a nullable parameter accepts the Seam::NULL sentinel, and only an
98110
// optional parameter accepts nil.

‎codegen/lib/merge-properties.ts‎

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

67+
if (first.format === 'boolean') {
68+
const booleans = occurrences as Array<
69+
Extract<Property, { format: 'boolean' }>
70+
>
71+
const values = booleans.some(({ values }) => values == null)
72+
? undefined
73+
: [...new Set(booleans.flatMap(({ values }) => values ?? []))]
74+
const merged = { ...first, ...docs }
75+
if (values == null) delete merged.values
76+
else merged.values = values
77+
return merged
78+
}
79+
6780
if (first.format === 'object') {
6881
return {
6982
...first,

‎lib/seam/resources/access_code.rb‎

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

‎lib/seam/resources/acs_access_group.rb‎

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

‎lib/seam/resources/acs_credential.rb‎

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

‎lib/seam/resources/acs_user.rb‎

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

‎lib/seam/resources/device.rb‎

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

‎lib/seam/resources/unmanaged_access_code.rb‎

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

‎lib/seam/resources/unmanaged_device.rb‎

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

0 commit comments

Comments
 (0)