Skip to content

Commit 5a97716

Browse files
authored
allow missing transactions templates (#1266)
1 parent 74b9676 commit 5a97716

File tree

12 files changed

+48
-47
lines changed

12 files changed

+48
-47
lines changed

docs/api/README.md

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

internal/controller/ledger/controller_default.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ func (ctrl *DefaultController) createTransaction(ctx context.Context, store Stor
421421
logger := logging.FromContext(ctx).WithField("req", uuid.NewString()[:8])
422422
ctx = logging.ContextWithLogger(ctx, logger)
423423

424-
if schema != nil {
424+
if schema != nil && len(schema.Transactions) > 0 {
425425
if parameters.Input.Template == "" {
426426
err := newErrSchemaValidationError(parameters.SchemaVersion, fmt.Errorf("transactions on this ledger must use a template"))
427427
if ctrl.schemaEnforcementMode == SchemaEnforcementStrict {
@@ -438,6 +438,8 @@ func (ctrl *DefaultController) createTransaction(ctx context.Context, store Stor
438438
} else {
439439
return nil, newErrSchemaValidationError(parameters.SchemaVersion, fmt.Errorf("failed to find transaction template `%s`", parameters.Input.Template))
440440
}
441+
} else if parameters.Input.Template != "" {
442+
return nil, newErrSchemaValidationError(parameters.SchemaVersion, fmt.Errorf("can only use templates on a schema with transaction definitions"))
441443
}
442444

443445
m, err := ctrl.getParser(parameters.Input.Runtime).Parse(parameters.Input.Plain)

internal/schema.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ func NewSchema(version string, data SchemaData) (Schema, error) {
2626
if data.Chart == nil {
2727
return Schema{}, NewErrInvalidSchema(errors.New("missing chart of accounts"))
2828
}
29-
if data.Transactions == nil {
30-
return Schema{}, NewErrInvalidSchema(errors.New("missing transaction templates"))
31-
}
3229
if err := data.Transactions.Validate(); err != nil {
3330
return Schema{}, NewErrInvalidSchema(err)
3431
}

openapi.yaml

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

openapi/v2.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3268,7 +3268,6 @@ components:
32683268
$ref: "#/components/schemas/V2QueryTemplates"
32693269
required:
32703270
- chart
3271-
- transactions
32723271
V2Schema:
32733272
type: object
32743273
description: Complete schema structure with metadata

pkg/client/.speakeasy/gen.lock

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

pkg/client/docs/models/components/v2schema.md

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

pkg/client/docs/models/components/v2schemadata.md

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

pkg/client/docs/sdks/v2/README.md

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

pkg/client/models/components/v2schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type V2Schema struct {
1616
// Chart of account
1717
Chart map[string]V2ChartSegment `json:"chart"`
1818
// Transaction templates
19-
Transactions map[string]V2TransactionTemplate `json:"transactions"`
19+
Transactions map[string]V2TransactionTemplate `json:"transactions,omitempty"`
2020
// Query templates
2121
Queries map[string]V2QueryTemplate `json:"queries,omitempty"`
2222
}
@@ -55,7 +55,7 @@ func (o *V2Schema) GetChart() map[string]V2ChartSegment {
5555

5656
func (o *V2Schema) GetTransactions() map[string]V2TransactionTemplate {
5757
if o == nil {
58-
return map[string]V2TransactionTemplate{}
58+
return nil
5959
}
6060
return o.Transactions
6161
}

0 commit comments

Comments
 (0)