Skip to content

Commit

Permalink
impl typescript stub generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannm committed Mar 29, 2024
1 parent 6ef844f commit b14348e
Show file tree
Hide file tree
Showing 10 changed files with 591 additions and 177 deletions.
14 changes: 12 additions & 2 deletions example/ex-04-stubgen/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ var SampleDesc desc.ServiceDescFunc = func() *desc.Service {
desc.NewContract().
SetInput(&dto.VeryComplexRequest{}).
SetOutput(&dto.VeryComplexResponse{}).
NamedSelector("ComplexDummy", fasthttp.REST(http.MethodPost, "/complexDummy")).
NamedSelector("ComplexDummy2", fasthttp.REST(http.MethodPost, "/complexDummy/:key1")).
NamedSelector("ComplexDummy", fasthttp.POST("/complexDummy")).
NamedSelector("ComplexDummy2", fasthttp.POST("/complexDummy/:key1")).
AddModifier(func(envelope *kit.Envelope) {
envelope.SetHdr("X-Custom-Header", "justForTestingModifier")
}).
SetHandler(DummyHandler),
).
AddContract(
desc.NewContract().
SetInput(&dto.VeryComplexRequest{}).
SetOutput(&dto.VeryComplexResponse{}).
NamedSelector("GetComplexDummy", fasthttp.GET("/complexDummy/:key1/xs/:sKey1")).
AddModifier(func(envelope *kit.Envelope) {
envelope.SetHdr("X-Custom-Header", "justForTestingModifier")
}).
Expand Down
6 changes: 6 additions & 0 deletions example/ex-04-stubgen/dto/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ package dto

import "encoding/json"

type SimpleHdr struct {
Key1 string `json:"sKey1"`
Key2 int `json:"sKey2"`
}

type VeryComplexRequest struct {
SimpleHdr
Key1 string `json:"key1"`
Key1Ptr *string `json:"key1Ptr"`
MapKey1 map[string]int `json:"mapKey1"`
Expand Down
14 changes: 7 additions & 7 deletions example/ex-04-stubgen/stub/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func main() {
stubgen.WithStubName("sampleService"),
).MustGenerate(api.SampleDesc)

//stubgen.New(
// stubgen.WithGenFunc(stubgen.TypeScriptStub, ".ts"),
// stubgen.WithTags("json"),
// stubgen.WithPkgName("sampleservice"),
// stubgen.WithFolderName("sampleservicets"),
// stubgen.WithStubName("sampleService"),
//).MustGenerate(api.SampleDesc)
stubgen.New(
stubgen.WithGenFunc(stubgen.TypeScriptStub, ".ts"),
stubgen.WithTags("json"),
stubgen.WithPkgName("sampleservice"),
stubgen.WithFolderName("sampleservicets"),
stubgen.WithStubName("sampleService"),
).MustGenerate(api.SampleDesc)
}
291 changes: 291 additions & 0 deletions example/ex-04-stubgen/stub/sampleservice/stub.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b14348e

Please sign in to comment.