Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

omise-go v2 (codegen) #42

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

omise-go v2 (codegen) #42

wants to merge 5 commits into from

Conversation

rezigned
Copy link
Contributor

@rezigned rezigned commented May 28, 2020

Code generation

  • Models
  • Params
  • Requests
  • Generate example usage for each endpoint.
  • Generate search types

Testing

  • Fix tests
  • Add missing tests (for new endpoints)
  • Test real network requests

New API Design

  • Upgrade to new design
  • Add context support

New API Design

charge, err := client.Charge().Create(ctx, &omise.CreateChargeParams{
	Amount:      204842,
	Currency:    "THB",
	Description: "initial charge.",
	Card:        token.ID,
})

Others

  • Update README.md
  • Remove forum link

@rezigned rezigned force-pushed the omise-go-v2 branch 2 times, most recently from 25c36e1 to 76a4402 Compare June 15, 2020 09:52
@rezigned rezigned changed the title Add go.mod for omise-go v2 and generate model files omise-go v2 (codegen) Jun 23, 2020
@iporsut
Copy link
Contributor

iporsut commented Jun 25, 2020

Could you add newline at the end of file of generated file?

@rezigned
Copy link
Contributor Author

Sure krub. Thank you.

@rezigned rezigned force-pushed the omise-go-v2 branch 2 times, most recently from 5aafb1f to 80be80a Compare July 1, 2020 04:48
rezigned added 2 commits July 1, 2020 13:23
Add type alias and rename based struct for List

Regenerate *_list.go

Generate resource files (wip)

Remove Base struct + regenerate request files

Prepend omise package prefix to field type + auto import package

Generate nested resources (wip)

Add resource prefix for list actions

Fix duplicate refund struct types

Append List struct to list operations

Update ordering path to v2

Generate extra params for endpoints

Regenerate operations/*

Generate all params

Generate Vault endpoint for token

Update test to include v2

Update fixtures path

Generate comments

Ignore golint for now (focus on tests)

Generate omitempty tags

Generate struct pointers

Reorder json fields in tests

Regenerate int64 and int types

Update fixtures path

Force non-null fields

Generate *bool for charge.capture

Generate documentation (wip)

Generate documentation (wip)

Add tests for capability

Generate float64 for floating point fields

Add tests for forex

Add DateString type for date fields in params

Generate custom DateString type

Fix test failed due to case-sensitivity in linux

Update tests for schedule + make Weekday non-pointer

Fix more tests in schedule resource

Make Schedule's start_date and end_date nullable

Generate ListChargeSchedules struct

Re-generate ListChargeSchedules struct

Make enum types non-reference

Update tests and fixtures for source

Add tests for system_info (/)

Generate search types

Re-generate event.data

Update tests for schedule

Add network tests for source

Re-enable golint for v2

Add comments for enums

Generate comments for enums

Generate more comments

Remove old codes

Regenerate files with newlines at the end of files

Regenerate files with newlines at the end of files (cont)

Regenerate files with newlines at the end of files (cont)

Regenerate files with newlines at the end of files (done)

Cleanup go mod dependencies
Update new API design

Update method description

Update method description (cont)

Update method description (cont)

Update method description (cont)

Update method description (cont)

Update Account tests

Update Balance tests

Update Capability tests

Update Card tests

Update Charge tests

Update Charge tests (github's down)

Update Charge tests

Add default API Version

Update Charge tests

Update Customer tests

Fix wrong version in client_test

Regenerate list resources

Regenerate dispute resource

Update Event/Forex/Link tests

Update List tests

Update Occurrence tests

Update Recipient tests + Regenerate params

Update Refund tests

Update Source tests

Update SystemInfo tests

Update Transaction tests

Update Transfer tests

Update Token tests

Update Schedule tests

Update Search tests

Update Search tests

Regenerate Search resource

Regenerate ChargeStatus

Add context support

Use req.Context instead of NewRequestWithContext due to go versions (1.13+)

Refactor Client.Do
@choestelus
Copy link

I think this need to run gofmt first, even if it is generated code. what do you think? @rezigned


// UnmarshalJSON Date type
func (d *Date) UnmarshalJSON(b []byte) error {
tm, err := time.Parse("\"2006-01-02\"", string(b))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be

tm, err := time.Parse(`"2006-01-02"`, string(b))

instead of escaping special characters


const (
API Endpoint = "https://api.omise.co"
Vault = "https://vault.omise.co"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is untyped constant here intended?

"net/http"
)

var _ = fmt.Println

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any reason for fmt to remains as imported package here?

return ok
}

func assertJSONEquals(t *testing.T, prefix string, m1 map[string]interface{}, m2 map[string]interface{}) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's https://pkg.go.dev/github.com/stretchr/testify/require?tab=doc#JSONEq for this kind of assertion and it's already imported here. could be use that instead

package omise

// MfaRecoveryCodes represents resource object.
type MfaRecoveryCodes struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acronym in go should remains all capital case, Mfa -> MFA if this is Multi-Factor Authentication here

r "github.com/stretchr/testify/require"
)

var _ = fmt.Println

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this


client := testutil.NewFixedClient(t)
receipt, _ := client.Receipt().Retrieve(context.Background(), &omise.RetrieveReceiptParams{ReceiptID})
a.Equal(t, ReceiptID, receipt.ID)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check first if receipt is not nil if using assert package, not require here
otherwise when this fails, everything else will be failed too and produce a lot of useless failure messages since the root cause is nil.

expected := `{"amount":192188}`

b, err := json.Marshal(req)
r.Nil(t, err, "err should be nothing")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use r.NoError(t, err, "err should be nothing") here

type QrCode struct {
Base
Email string `json:"email"`
MfaProvisioningURI string `json:"mfa_provisioning_uri"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mfa here should be MFA or there's some limitations that prevent this kind of naming?

Comment on lines +17 to +21
SourceInstallmentKtc SourceType = "installment_ktc"
SourceInternetBankingBay SourceType = "internet_banking_bay"
SourceInternetBankingBbl SourceType = "internet_banking_bbl"
SourceInternetBankingKtb SourceType = "internet_banking_ktb"
SourceInternetBankingScb SourceType = "internet_banking_scb"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it should be all-capital letters for bank acronym, not camelCase?

"versions": [
"2019-05-29"
]
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline here please

],
"country": "TH",
"zero_interest_installments": true
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline here please

"base": "USD",
"quote": "THB",
"rate": 30.4847017
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline here please

"message": null,
"result": null,
"created": "2017-06-08T04:46:50Z"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline please

"created": "2017-06-08T04:46:50Z"
}
]
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline please

"terminal_id": "POS-01",
"type": "bill_payment_tesco_lotus",
"zero_interest_installments": null
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline please

"terminal_id": "POS-01",
"type": "bill_payment_tesco_lotus",
"zero_interest_installments": null
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline here too please

"name": "JOHN DOE",
"created": "2015-06-02T09:26:59Z"
},
"created": "2015-01-15T10:04:47Z"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is missing comma at the end of this line intended?

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 3, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 29 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants