Skip to content

Commit

Permalink
feat: add generator tool
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 25, 2024
1 parent e9d6d6c commit de32077
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 60 deletions.
2 changes: 2 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2636,6 +2636,7 @@ Authorization ( Scopes: ledger:write )
|script|object|false|none|none|
|» plain|string|true|none|none|
|» vars|object|false|none|none|
|»» **additionalProperties**|string|false|none|none|
|reference|string|false|none|none|
|metadata|[V2Metadata](#schemav2metadata)|true|none|none|

Expand Down Expand Up @@ -3191,6 +3192,7 @@ Authorization ( Scopes: ledger:write )
|*anonymous*|BULK_SIZE_EXCEEDED|
|*anonymous*|INTERPRETER_PARSE|
|*anonymous*|INTERPRETER_RUNTIME|
|*anonymous*|LEDGER_ALREADY_EXISTS|

<h2 id="tocS_V2LedgerInfoResponse">V2LedgerInfoResponse</h2>
<!-- backwards compatibility -->
Expand Down
3 changes: 2 additions & 1 deletion internal/api/v2/controllers_ledgers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ func createLedger(systemController system.Controller) http.HandlerFunc {
if err := systemController.CreateLedger(r.Context(), chi.URLParam(r, "ledger"), configuration); err != nil {
switch {
case errors.Is(err, system.ErrInvalidLedgerConfiguration{}) ||
errors.Is(err, system.ErrLedgerAlreadyExists) ||
errors.Is(err, ledger.ErrInvalidLedgerName{}) ||
errors.Is(err, ledger.ErrInvalidBucketName{}):
api.BadRequest(w, ErrValidation, err)
case errors.Is(err, system.ErrLedgerAlreadyExists):
api.BadRequest(w, ErrLedgerAlreadyExists, err)
default:
common.HandleCommonErrors(w, r, err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/api/v2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
ErrCompilationFailed = "COMPILATION_FAILED"
ErrMetadataOverride = "METADATA_OVERRIDE"
ErrBulkSizeExceeded = "BULK_SIZE_EXCEEDED"
ErrLedgerAlreadyExists = "LEDGER_ALREADY_EXISTS"

ErrInterpreterParse = "INTERPRETER_PARSE"
ErrInterpreterRuntime = "INTERPRETER_RUNTIME"
Expand Down
4 changes: 3 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3296,7 +3296,8 @@ components:
vars:
type: object
properties: {}
additionalProperties: true
additionalProperties:
type: string
example:
user: users:042
required:
Expand Down Expand Up @@ -3455,6 +3456,7 @@ components:
- BULK_SIZE_EXCEEDED
- INTERPRETER_PARSE
- INTERPRETER_RUNTIME
- LEDGER_ALREADY_EXISTS
example: VALIDATION
V2LedgerInfoResponse:
type: object
Expand Down
4 changes: 3 additions & 1 deletion openapi/v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,8 @@ components:
vars:
type: object
properties: {}
additionalProperties: true
additionalProperties:
type: string
example:
user: users:042
required:
Expand Down Expand Up @@ -1725,6 +1726,7 @@ components:
- BULK_SIZE_EXCEEDED
- INTERPRETER_PARSE
- INTERPRETER_RUNTIME
- LEDGER_ALREADY_EXISTS
example: VALIDATION
V2LedgerInfoResponse:
type: object
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/.speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
lockVersion: 2.0.0
id: a9ac79e1-e429-4ee3-96c4-ec973f19bec3
management:
docChecksum: db305ef0d86f319f00b70be811eefeea
docChecksum: 169efa4fe3c5d6561f06920598d20df4
docVersion: v1
speakeasyVersion: 1.351.0
generationVersion: 2.384.1
releaseVersion: 0.4.18
configChecksum: 37cc61b909fcb3fb116f1cd48c1fc99a
releaseVersion: 0.4.20
configChecksum: e66e70c75590218ba585d230919d03e3
features:
go:
additionalDependencies: 0.1.0
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/.speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: true
go:
version: 0.4.18
version: 0.4.20
additionalDependencies: {}
allowUnknownFieldsInWeakUnions: false
clientServerStatusCodesAsErrors: true
Expand Down
37 changes: 19 additions & 18 deletions pkg/client/docs/models/components/v2errorsenum.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@

## Values

| Name | Value |
| -------------------------------- | -------------------------------- |
| `V2ErrorsEnumInternal` | INTERNAL |
| `V2ErrorsEnumInsufficientFund` | INSUFFICIENT_FUND |
| `V2ErrorsEnumValidation` | VALIDATION |
| `V2ErrorsEnumConflict` | CONFLICT |
| `V2ErrorsEnumCompilationFailed` | COMPILATION_FAILED |
| `V2ErrorsEnumMetadataOverride` | METADATA_OVERRIDE |
| `V2ErrorsEnumNotFound` | NOT_FOUND |
| `V2ErrorsEnumRevertOccurring` | REVERT_OCCURRING |
| `V2ErrorsEnumAlreadyRevert` | ALREADY_REVERT |
| `V2ErrorsEnumNoPostings` | NO_POSTINGS |
| `V2ErrorsEnumLedgerNotFound` | LEDGER_NOT_FOUND |
| `V2ErrorsEnumImport` | IMPORT |
| `V2ErrorsEnumTimeout` | TIMEOUT |
| `V2ErrorsEnumBulkSizeExceeded` | BULK_SIZE_EXCEEDED |
| `V2ErrorsEnumInterpreterParse` | INTERPRETER_PARSE |
| `V2ErrorsEnumInterpreterRuntime` | INTERPRETER_RUNTIME |
| Name | Value |
| --------------------------------- | --------------------------------- |
| `V2ErrorsEnumInternal` | INTERNAL |
| `V2ErrorsEnumInsufficientFund` | INSUFFICIENT_FUND |
| `V2ErrorsEnumValidation` | VALIDATION |
| `V2ErrorsEnumConflict` | CONFLICT |
| `V2ErrorsEnumCompilationFailed` | COMPILATION_FAILED |
| `V2ErrorsEnumMetadataOverride` | METADATA_OVERRIDE |
| `V2ErrorsEnumNotFound` | NOT_FOUND |
| `V2ErrorsEnumRevertOccurring` | REVERT_OCCURRING |
| `V2ErrorsEnumAlreadyRevert` | ALREADY_REVERT |
| `V2ErrorsEnumNoPostings` | NO_POSTINGS |
| `V2ErrorsEnumLedgerNotFound` | LEDGER_NOT_FOUND |
| `V2ErrorsEnumImport` | IMPORT |
| `V2ErrorsEnumTimeout` | TIMEOUT |
| `V2ErrorsEnumBulkSizeExceeded` | BULK_SIZE_EXCEEDED |
| `V2ErrorsEnumInterpreterParse` | INTERPRETER_PARSE |
| `V2ErrorsEnumInterpreterRuntime` | INTERPRETER_RUNTIME |
| `V2ErrorsEnumLedgerAlreadyExists` | LEDGER_ALREADY_EXISTS |
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
| Field | Type | Required | Description | Example |
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `Plain` | *string* | :heavy_check_mark: | N/A | vars {<br/>account $user<br/>}<br/>send [COIN 10] (<br/> source = @world<br/> destination = $user<br/>)<br/> |
| `Vars` | map[string]*any* | :heavy_minus_sign: | N/A | {<br/>"user": "users:042"<br/>} |
| `Vars` | map[string]*string* | :heavy_minus_sign: | N/A | {<br/>"user": "users:042"<br/>} |
4 changes: 2 additions & 2 deletions pkg/client/docs/sdks/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func main() {
destination = $user
)
",
Vars: map[string]any{
Vars: map[string]string{
"user": "users:042",
},
},
Expand Down Expand Up @@ -959,7 +959,7 @@ func main() {
destination = $user
)
",
Vars: map[string]any{
Vars: map[string]string{
"user": "users:042",
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/formance.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ func New(opts ...SDKOption) *Formance {
sdkConfiguration: sdkConfiguration{
Language: "go",
OpenAPIDocVersion: "v1",
SDKVersion: "0.4.18",
SDKVersion: "0.4.20",
GenVersion: "2.384.1",
UserAgent: "speakeasy-sdk/go 0.4.18 2.384.1 v1 github.com/formancehq/ledger/pkg/client",
UserAgent: "speakeasy-sdk/go 0.4.20 2.384.1 v1 github.com/formancehq/ledger/pkg/client",
Hooks: hooks.New(),
},
}
Expand Down
35 changes: 19 additions & 16 deletions pkg/client/models/components/v2errorsenum.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ import (
type V2ErrorsEnum string

const (
V2ErrorsEnumInternal V2ErrorsEnum = "INTERNAL"
V2ErrorsEnumInsufficientFund V2ErrorsEnum = "INSUFFICIENT_FUND"
V2ErrorsEnumValidation V2ErrorsEnum = "VALIDATION"
V2ErrorsEnumConflict V2ErrorsEnum = "CONFLICT"
V2ErrorsEnumCompilationFailed V2ErrorsEnum = "COMPILATION_FAILED"
V2ErrorsEnumMetadataOverride V2ErrorsEnum = "METADATA_OVERRIDE"
V2ErrorsEnumNotFound V2ErrorsEnum = "NOT_FOUND"
V2ErrorsEnumRevertOccurring V2ErrorsEnum = "REVERT_OCCURRING"
V2ErrorsEnumAlreadyRevert V2ErrorsEnum = "ALREADY_REVERT"
V2ErrorsEnumNoPostings V2ErrorsEnum = "NO_POSTINGS"
V2ErrorsEnumLedgerNotFound V2ErrorsEnum = "LEDGER_NOT_FOUND"
V2ErrorsEnumImport V2ErrorsEnum = "IMPORT"
V2ErrorsEnumTimeout V2ErrorsEnum = "TIMEOUT"
V2ErrorsEnumBulkSizeExceeded V2ErrorsEnum = "BULK_SIZE_EXCEEDED"
V2ErrorsEnumInterpreterParse V2ErrorsEnum = "INTERPRETER_PARSE"
V2ErrorsEnumInterpreterRuntime V2ErrorsEnum = "INTERPRETER_RUNTIME"
V2ErrorsEnumInternal V2ErrorsEnum = "INTERNAL"
V2ErrorsEnumInsufficientFund V2ErrorsEnum = "INSUFFICIENT_FUND"
V2ErrorsEnumValidation V2ErrorsEnum = "VALIDATION"
V2ErrorsEnumConflict V2ErrorsEnum = "CONFLICT"
V2ErrorsEnumCompilationFailed V2ErrorsEnum = "COMPILATION_FAILED"
V2ErrorsEnumMetadataOverride V2ErrorsEnum = "METADATA_OVERRIDE"
V2ErrorsEnumNotFound V2ErrorsEnum = "NOT_FOUND"
V2ErrorsEnumRevertOccurring V2ErrorsEnum = "REVERT_OCCURRING"
V2ErrorsEnumAlreadyRevert V2ErrorsEnum = "ALREADY_REVERT"
V2ErrorsEnumNoPostings V2ErrorsEnum = "NO_POSTINGS"
V2ErrorsEnumLedgerNotFound V2ErrorsEnum = "LEDGER_NOT_FOUND"
V2ErrorsEnumImport V2ErrorsEnum = "IMPORT"
V2ErrorsEnumTimeout V2ErrorsEnum = "TIMEOUT"
V2ErrorsEnumBulkSizeExceeded V2ErrorsEnum = "BULK_SIZE_EXCEEDED"
V2ErrorsEnumInterpreterParse V2ErrorsEnum = "INTERPRETER_PARSE"
V2ErrorsEnumInterpreterRuntime V2ErrorsEnum = "INTERPRETER_RUNTIME"
V2ErrorsEnumLedgerAlreadyExists V2ErrorsEnum = "LEDGER_ALREADY_EXISTS"
)

func (e V2ErrorsEnum) ToPointer() *V2ErrorsEnum {
Expand Down Expand Up @@ -68,6 +69,8 @@ func (e *V2ErrorsEnum) UnmarshalJSON(data []byte) error {
case "INTERPRETER_PARSE":
fallthrough
case "INTERPRETER_RUNTIME":
fallthrough
case "LEDGER_ALREADY_EXISTS":
*e = V2ErrorsEnum(v)
return nil
default:
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/models/components/v2posttransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

type V2PostTransactionScript struct {
Plain string `json:"plain"`
Vars map[string]any `json:"vars,omitempty"`
Plain string `json:"plain"`
Vars map[string]string `json:"vars,omitempty"`
}

func (o *V2PostTransactionScript) GetPlain() string {
Expand All @@ -19,7 +19,7 @@ func (o *V2PostTransactionScript) GetPlain() string {
return o.Plain
}

func (o *V2PostTransactionScript) GetVars() map[string]any {
func (o *V2PostTransactionScript) GetVars() map[string]string {
if o == nil {
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/api_transactions_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ var _ = Context("Ledger accounts list API tests", func() {
source = @world
destination = @bob
)`,
Vars: map[string]interface{}{},
Vars: map[string]string{},
},
},
Ledger: "default",
Expand Down Expand Up @@ -365,7 +365,7 @@ var _ = Context("Ledger accounts list API tests", func() {
source = @world
destination = @bob
)`,
Vars: map[string]interface{}{
Vars: map[string]string{
"amount": "USD -100",
},
},
Expand Down Expand Up @@ -393,7 +393,7 @@ var _ = Context("Ledger accounts list API tests", func() {
Metadata: map[string]string{},
Script: &components.V2PostTransactionScript{
Plain: `XXX`,
Vars: map[string]interface{}{},
Vars: map[string]string{},
},
},
Ledger: "default",
Expand Down Expand Up @@ -422,7 +422,7 @@ var _ = Context("Ledger accounts list API tests", func() {
}
set_tx_meta("foo", "bar")
`,
Vars: map[string]interface{}{
Vars: map[string]string{
"amount": "USD 100",
},
},
Expand All @@ -449,7 +449,7 @@ var _ = Context("Ledger accounts list API tests", func() {
destination = @bob
)
set_tx_meta("foo", "bar")`,
Vars: map[string]interface{}{},
Vars: map[string]string{},
},
},
Ledger: "default",
Expand All @@ -471,7 +471,7 @@ var _ = Context("Ledger accounts list API tests", func() {
source = @world
destination = @bob
)`,
Vars: map[string]interface{}{},
Vars: map[string]string{},
},
},
DryRun: pointer.For(true),
Expand Down
6 changes: 1 addition & 5 deletions test/performance/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,12 @@ func (benchmark *Benchmark) createTransaction(
script string,
vars map[string]string,
) (*ledger.Transaction, error) {
varsAsMapAny := make(map[string]any)
for k, v := range vars {
varsAsMapAny[k] = v
}
response, err := client.Ledger.V2.CreateTransaction(ctx, operations.V2CreateTransactionRequest{
Ledger: l.Name,
V2PostTransaction: components.V2PostTransaction{
Script: &components.V2PostTransactionScript{
Plain: script,
Vars: varsAsMapAny,
Vars: vars,
},
},
})
Expand Down
Loading

0 comments on commit de32077

Please sign in to comment.