Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: CI
on:
push:
branches-ignore:
- 'generated'
- 'codegen/**'
- 'integrated/**'
- 'stl-preview-head/**'
- 'stl-preview-base/**'
branches:
- '**'
- '!integrated/**'
- '!stl-preview-head/**'
- '!stl-preview-base/**'
- '!generated'
- '!codegen/**'
- 'codegen/stl/**'
pull_request:
branches-ignore:
- 'stl-preview-head/**'
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.5.2"
".": "0.5.3"
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.5.3 (2026-03-17)

Full Changelog: [v0.5.2...v0.5.3](https://github.com/CASParser/cas-parser-go/compare/v0.5.2...v0.5.3)

### Chores

* **internal:** minor cleanup ([5dcbbb1](https://github.com/CASParser/cas-parser-go/commit/5dcbbb199f0fc37d6676c9d259205773c794406f))
* **internal:** tweak CI branches ([6377b4a](https://github.com/CASParser/cas-parser-go/commit/6377b4aa8da9f70467ba34dba7a1ddf4ffcc3743))
* **internal:** use explicit returns ([edbbf41](https://github.com/CASParser/cas-parser-go/commit/edbbf41442d2577fb04903e619b9b67554d10209))
* **internal:** use explicit returns in more places ([af11842](https://github.com/CASParser/cas-parser-go/commit/af11842d738d5907bde4ba49fcd17679a037dc3e))

## 0.5.2 (2026-03-07)

Full Changelog: [v0.5.1...v0.5.2](https://github.com/CASParser/cas-parser-go/compare/v0.5.1...v0.5.2)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Or to pin the version:
<!-- x-release-please-start-version -->

```sh
go get -u 'github.com/CASParser/cas-parser-go@v0.5.2'
go get -u 'github.com/CASParser/cas-parser-go@v0.5.3'
```

<!-- x-release-please-end -->
Expand Down
2 changes: 1 addition & 1 deletion accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r *AccessTokenService) New(ctx context.Context, body AccessTokenNewParams,
opts = slices.Concat(r.Options, opts)
path := "v1/token"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
return res, err
}

type AccessTokenNewResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion camskfintech.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (r *CamsKfintechService) Parse(ctx context.Context, body CamsKfintechParseP
opts = slices.Concat(r.Options, opts)
path := "v4/cams_kfintech/parse"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
return res, err
}

type LinkedHolder struct {
Expand Down
2 changes: 1 addition & 1 deletion cdsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *CdslService) ParsePdf(ctx context.Context, body CdslParsePdfParams, opt
opts = slices.Concat(r.Options, opts)
path := "v4/cdsl/parse"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
return res, err
}

type CdslParsePdfParams struct {
Expand Down
6 changes: 3 additions & 3 deletions cdslfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (r *CdslFetchService) RequestOtp(ctx context.Context, body CdslFetchRequest
opts = slices.Concat(r.Options, opts)
path := "v4/cdsl/fetch"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
return res, err
}

// **Step 2 of 2**: Verify OTP and retrieve CDSL CAS files.
Expand All @@ -63,11 +63,11 @@ func (r *CdslFetchService) VerifyOtp(ctx context.Context, sessionID string, body
opts = slices.Concat(r.Options, opts)
if sessionID == "" {
err = errors.New("missing required session_id parameter")
return
return nil, err
}
path := fmt.Sprintf("v4/cdsl/fetch/%s/verify", url.PathEscape(sessionID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
return res, err
}

type CdslFetchRequestOtpResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestUserAgentHeader(t *testing.T) {
},
}),
)
client.Credits.Check(context.Background())
_, _ = client.Credits.Check(context.Background())
if userAgent != fmt.Sprintf("CasParser/Go %s", internal.PackageVersion) {
t.Errorf("Expected User-Agent to be correct, but got: %#v", userAgent)
}
Expand Down
2 changes: 1 addition & 1 deletion contractnote.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r *ContractNoteService) Parse(ctx context.Context, body ContractNoteParseP
opts = slices.Concat(r.Options, opts)
path := "v4/contract_note/parse"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
return res, err
}

type ContractNoteParseResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion credit.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *CreditService) Check(ctx context.Context, opts ...option.RequestOption)
opts = slices.Concat(r.Options, opts)
path := "v1/credits"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
return res, err
}

type CreditCheckResponse struct {
Expand Down
12 changes: 6 additions & 6 deletions inboundemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ func (r *InboundEmailService) New(ctx context.Context, body InboundEmailNewParam
opts = slices.Concat(r.Options, opts)
path := "v4/inbound-email"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
return res, err
}

// Retrieve details of a specific mailbox including statistics.
func (r *InboundEmailService) Get(ctx context.Context, inboundEmailID string, opts ...option.RequestOption) (res *InboundEmailGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if inboundEmailID == "" {
err = errors.New("missing required inbound_email_id parameter")
return
return nil, err
}
path := fmt.Sprintf("v4/inbound-email/%s", url.PathEscape(inboundEmailID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
return res, err
}

// List all mailboxes associated with your API key. Returns active and inactive
Expand All @@ -112,7 +112,7 @@ func (r *InboundEmailService) List(ctx context.Context, query InboundEmailListPa
opts = slices.Concat(r.Options, opts)
path := "v4/inbound-email"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
return res, err
}

// Permanently delete an inbound email address. It will stop accepting emails.
Expand All @@ -123,11 +123,11 @@ func (r *InboundEmailService) Delete(ctx context.Context, inboundEmailID string,
opts = slices.Concat(r.Options, opts)
if inboundEmailID == "" {
err = errors.New("missing required inbound_email_id parameter")
return
return nil, err
}
path := fmt.Sprintf("v4/inbound-email/%s", url.PathEscape(inboundEmailID))
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
return res, err
}

// An inbound email address for receiving forwarded CAS emails
Expand Down
8 changes: 4 additions & 4 deletions inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r *InboxService) CheckConnectionStatus(ctx context.Context, body InboxChec
opts = slices.Concat(r.Options, opts)
path := "v4/inbox/status"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
return res, err
}

// Initiate OAuth flow to connect user's email inbox.
Expand All @@ -91,7 +91,7 @@ func (r *InboxService) ConnectEmail(ctx context.Context, body InboxConnectEmailP
opts = slices.Concat(r.Options, opts)
path := "v4/inbox/connect"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
return res, err
}

// Revoke email access and invalidate the token.
Expand All @@ -107,7 +107,7 @@ func (r *InboxService) DisconnectEmail(ctx context.Context, body InboxDisconnect
opts = slices.Concat(r.Options, opts)
path := "v4/inbox/disconnect"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
return res, err
}

// Search the user's email inbox for CAS files from known senders (CAMS, KFintech,
Expand All @@ -126,7 +126,7 @@ func (r *InboxService) ListCasFiles(ctx context.Context, params InboxListCasFile
opts = slices.Concat(r.Options, opts)
path := "v4/inbox/cas"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return
return res, err
}

type InboxCheckConnectionStatusResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/apiform/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,5 +469,5 @@ func WriteExtras(writer *multipart.Writer, extras map[string]any) (err error) {
break
}
}
return
return err
}
9 changes: 6 additions & 3 deletions internal/apiform/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,17 @@ func TestEncode(t *testing.T) {
t.Run(name, func(t *testing.T) {
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
writer.SetBoundary("xxx")
err := writer.SetBoundary("xxx")
if err != nil {
t.Errorf("setting boundary for %v failed with error %v", test.val, err)
}

var arrayFmt string = "indices:dots"
arrayFmt := "indices:dots"
if tags := strings.Split(name, ","); len(tags) > 1 {
arrayFmt = tags[1]
}

err := MarshalWithSettings(test.val, writer, arrayFmt)
err = MarshalWithSettings(test.val, writer, arrayFmt)
if err != nil {
t.Errorf("serialization of %v failed with error %v", test.val, err)
}
Expand Down
8 changes: 5 additions & 3 deletions internal/apiform/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func parseFormStructTag(field reflect.StructField) (tag parsedStructTag, ok bool
raw, ok = field.Tag.Lookup(jsonStructTag)
}
if !ok {
return
return tag, ok
}
parts := strings.Split(raw, ",")
if len(parts) == 0 {
Expand All @@ -45,7 +45,7 @@ func parseFormStructTag(field reflect.StructField) (tag parsedStructTag, ok bool
}

parseApiStructTag(field, &tag)
return
return tag, ok
}

func parseApiStructTag(field reflect.StructField, tag *parsedStructTag) {
Expand All @@ -60,11 +60,13 @@ func parseApiStructTag(field reflect.StructField, tag *parsedStructTag) {
tag.extras = true
case "required":
tag.required = true
case "metadata":
tag.metadata = true
}
}
}

func parseFormatStructTag(field reflect.StructField) (format string, ok bool) {
format, ok = field.Tag.Lookup(formatStructTag)
return
return format, ok
}
9 changes: 3 additions & 6 deletions internal/apijson/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (d *decoderBuilder) newStructTypeDecoder(t reflect.Type) decoderFunc {

for _, decoder := range anonymousDecoders {
// ignore errors
decoder.fn(node, value.FieldByIndex(decoder.idx), state)
_ = decoder.fn(node, value.FieldByIndex(decoder.idx), state)
}

for _, inlineDecoder := range inlineDecoders {
Expand Down Expand Up @@ -462,7 +462,7 @@ func (d *decoderBuilder) newStructTypeDecoder(t reflect.Type) decoderFunc {

// Handle null [param.Opt]
if itemNode.Type == gjson.Null && dest.IsValid() && dest.Type().Implements(reflect.TypeOf((*param.Optional)(nil)).Elem()) {
dest.Addr().Interface().(json.Unmarshaler).UnmarshalJSON([]byte(itemNode.Raw))
_ = dest.Addr().Interface().(json.Unmarshaler).UnmarshalJSON([]byte(itemNode.Raw))
continue
}

Expand Down Expand Up @@ -684,8 +684,5 @@ func guardUnknown(state *decoderState, v reflect.Value) bool {

constantString, ok := v.Interface().(interface{ Default() string })
named := v.Type() != stringType
if guardStrict(state, ok && named && v.Equal(reflect.ValueOf(constantString.Default()))) {
return true
}
return false
return guardStrict(state, ok && named && v.Equal(reflect.ValueOf(constantString.Default())))
}
23 changes: 1 addition & 22 deletions internal/apijson/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,28 +286,7 @@ func (e *encoder) newStructTypeEncoder(t reflect.Type) encoderFunc {
return nil, err
}
}
return
}
}

func (e *encoder) newFieldTypeEncoder(t reflect.Type) encoderFunc {
f, _ := t.FieldByName("Value")
enc := e.typeEncoder(f.Type)

return func(value reflect.Value) (json []byte, err error) {
present := value.FieldByName("Present")
if !present.Bool() {
return nil, nil
}
null := value.FieldByName("Null")
if null.Bool() {
return []byte("null"), nil
}
raw := value.FieldByName("Raw")
if !raw.IsNil() {
return e.typeEncoder(raw.Type())(raw)
}
return enc(value.FieldByName("Value"))
return json, err
}
}

Expand Down
9 changes: 2 additions & 7 deletions internal/apijson/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"reflect"
"slices"
"sync"

"github.com/tidwall/gjson"
)
Expand All @@ -15,7 +14,6 @@ import (

type validationEntry struct {
field reflect.StructField
required bool
legalValues struct {
strings []string
// 1 represents true, 0 represents false, -1 represents either
Expand All @@ -24,9 +22,6 @@ type validationEntry struct {
}
}

type validatorFunc func(reflect.Value) exactness

var validators sync.Map
var validationRegistry = map[reflect.Type][]validationEntry{}

func RegisterFieldValidator[T any, V string | bool | int | float64](fieldName string, values ...V) {
Expand Down Expand Up @@ -111,9 +106,9 @@ func (state *decoderState) validateBool(v reflect.Value) {
return
}
b := v.Bool()
if state.validator.legalValues.bools == 1 && b == false {
if state.validator.legalValues.bools == 1 && !b {
state.exactness = loose
} else if state.validator.legalValues.bools == 0 && b == true {
} else if state.validator.legalValues.bools == 0 && b {
state.exactness = loose
}
}
Expand Down
Loading
Loading