Skip to content

feat: speakeasy quickstart react-query #1403

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

Closed
wants to merge 3 commits into from
Closed
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
21 changes: 17 additions & 4 deletions cmd/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ import (
)

type QuickstartFlags struct {
SkipCompile bool `json:"skip-compile"`
Schema string `json:"schema"`
OutDir string `json:"out-dir"`
TargetType string `json:"target"`
SkipCompile bool `json:"skip-compile"`
Schema string `json:"schema"`
OutDir string `json:"out-dir"`
TargetType string `json:"target"`
IsReactQuery bool `json:"is-react-query"`

// If the quickstart should be based on a pre-existing template (hosted in the Speakeasy Registry)
From string `json:"from"`
Expand All @@ -56,6 +57,17 @@ var quickstartCmd = &model.ExecutableCommand[QuickstartFlags]{
Long: `Guided setup to help you create a new SDK in minutes.`,
Run: quickstartExec,
RequiresAuth: true,
NonInteractiveSubcommands: []model.Command{
&model.ExecutableCommand[QuickstartFlags]{
Usage: "react-query",
Short: "Quickstart a TypeScript SDK with React Query enabled",
Run: func(ctx context.Context, flags QuickstartFlags) error {
flags.TargetType = "typescript"
flags.IsReactQuery = true
return quickstartExec(ctx, flags)
},
},
},
Flags: []flag.Flag{
flag.BooleanFlag{
Name: "skip-compile",
Expand Down Expand Up @@ -111,6 +123,7 @@ func quickstartExec(ctx context.Context, flags QuickstartFlags) error {
Targets: make(map[string]workflow.Target),
},
LanguageConfigs: make(map[string]*sdkGenConfig.Configuration),
IsReactQuery: flags.IsReactQuery,
}

if flags.Schema != "" {
Expand Down
18 changes: 17 additions & 1 deletion prompts/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func PromptForTargetConfig(targetName string, wf *workflow.Workflow, target *wor
if isQuickstart {
setDevContainerDefaults(output, wf, target)
setEnvVarPrefixDefaults(output, target, sdkClassName)
setReactQueryDefaults(output, target, quickstart.IsReactQuery)
}

return output, nil
Expand All @@ -185,6 +186,14 @@ func setDevContainerDefaults(output *config.Configuration, wf *workflow.Workflow
}
}

func setReactQueryDefaults(output *config.Configuration, target *workflow.Target, isReactQuery bool) {
if target.Target == "typescript" && isReactQuery {
if cfg, ok := output.Languages[target.Target]; ok && cfg.Cfg != nil {
cfg.Cfg["enableReactQuery"] = true
}
}
}

func setEnvVarPrefixDefaults(output *config.Configuration, target *workflow.Target, sdkClassName string) {
if target.Target == "go" || target.Target == "typescript" || target.Target == "python" {
if cfg, ok := output.Languages[target.Target]; ok && cfg.Cfg != nil {
Expand All @@ -200,10 +209,17 @@ func configBaseForm(ctx context.Context, quickstart *Quickstart) (*QuickstartSta
return nil, err
}

// Set defaults for new SDKs
if quickstart != nil {
setDevContainerDefaults(output, quickstart.WorkflowFile, &target)
setEnvVarPrefixDefaults(output, &target, output.Generation.SDKClassName)
setReactQueryDefaults(output, &target, quickstart.IsReactQuery)
}

quickstart.LanguageConfigs[key] = output
}

var nextState QuickstartState = Complete
nextState := Complete
return &nextState, nil
}

Expand Down
1 change: 1 addition & 0 deletions prompts/statemappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Quickstart struct {
IsUsingSampleOpenAPISpec bool
IsUsingTemplate bool
SDKName string
IsReactQuery bool
}

type Defaults struct {
Expand Down