Skip to content

Commit

Permalink
Fix rendering sysl constraints for large values (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriehSchneier committed Aug 19, 2024
1 parent abfb49a commit 428d0fd
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,28 @@ plugins: \
internal/bundles/assets/transformer_cli.arraiz: pkg/importer/avro/transformer_cli.arrai go.mod
$(BUNDLE)

internal/bundles/assets/import_sql_cli.arraiz: pkg/importer/sql/import_sql_cli.arrai pkg/importer/sql/sql.arrai go.mod
internal/bundles/assets/import_sql_cli.arraiz: \
pkg/importer/sql/import_sql_cli.arrai \
pkg/importer/sql/sql.arrai \
$(shell find pkg/arrai/sysl-renderer -name '*.arrai') \
go.mod
$(BUNDLE)

internal/bundles/assets/import_openapi_cli.arraiz: pkg/importer/openapi/import_openapi_cli.arrai pkg/importer/cli.arrai $(shell find pkg/importer/openapi -name '*.arrai') go.mod
internal/bundles/assets/import_openapi_cli.arraiz: \
pkg/importer/openapi/import_openapi_cli.arrai \
pkg/importer/cli.arrai \
$(shell find pkg/importer/openapi -name '*.arrai') \
$(shell find pkg/arrai/sysl-renderer -name '*.arrai') \
go.mod
$(BUNDLE)

# There are many files that change the proto importer logic.
# Check all arrai files within the directory for changes before bundling.
internal/bundles/assets/import_proto_cli.arraiz: pkg/importer/proto/import_proto_cli.arrai $(shell find pkg/importer/proto -name '*.arrai') go.mod
internal/bundles/assets/import_proto_cli.arraiz: \
pkg/importer/proto/import_proto_cli.arrai \
$(shell find pkg/importer/proto -name '*.arrai') \
$(shell find pkg/arrai/sysl-renderer -name '*.arrai') \
go.mod
$(BUNDLE)

internal/bundles/exporters/proto/transform.arraiz: transforms/exporters/proto/transform.arrai $(shell find transforms/exporters/proto -name '*.arrai') go.mod
Expand Down
Binary file modified internal/bundles/assets/import_openapi_cli.arraiz
Binary file not shown.
Binary file modified internal/bundles/assets/import_proto_cli.arraiz
Binary file not shown.
Binary file modified internal/bundles/assets/import_sql_cli.arraiz
Binary file not shown.
7 changes: 3 additions & 4 deletions pkg/arrai/sysl-renderer/sysl_mod_renderers.arrai
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ let renderTypeUsage = \type
};
let (?:opt:false, ?:constraint:{}, ...) = type;

# FIXME handle precision
let constraintStr = cond constraint {
[(length: ('max': maxLength, 'min': minLength), ...)]: $`(${minLength}..${maxLength})`,
[(length: ('max': maxLength), ...)]: $`(${maxLength})`,
[(length: ('min': minLength), ...)]: $`(${minLength}..)`,
[(length: ('max': maxLength, 'min': minLength), ...)]: $`(${minLength:d}..${maxLength:d})`,
[(length: ('max': maxLength), ...)]: $`(${maxLength:d})`,
[(length: ('min': minLength), ...)]: $`(${minLength:d}..)`,
};

let bitWidth = cond constraint {
Expand Down
6 changes: 6 additions & 0 deletions pkg/importer/tests/openapi3/min-max.sysl
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ TestApp "Simple":
@json_tag = "k"
l <: int(6)?:
@json_tag = "l"
maxLength <: string(2147483647)?:
@json_tag = "maxLength"
minAndMaxLength <: string(2147483646..2147483647)?:
@json_tag = "minAndMaxLength"
minLength <: string(2147483646..)?:
@json_tag = "minLength"
10 changes: 10 additions & 0 deletions pkg/importer/tests/openapi3/min-max.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ components:
l:
type: integer
maxLength: 6 # invalid, but sysl shouldn't crash
maxLength:
type: string
maxLength: 2147483647
minLength:
type: string
minLength: 2147483646
minAndMaxLength:
type: string
minLength: 2147483646
maxLength: 2147483647

0 comments on commit 428d0fd

Please sign in to comment.