Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
49e33d6
add new register custom code command
idbentley Sep 23, 2025
8df96f5
add commands for registercustomcode
idbentley Sep 23, 2025
38fe3e5
pass sufficient context to support generation
idbentley Sep 24, 2025
f61a7d1
feat: implement register custom code functionality
Sep 26, 2025
2da7241
removed theirs
Sep 29, 2025
59f7396
implemented new workflow
Sep 29, 2025
cf13c9e
update registercustomcode to run generation in a manner more consiste…
idbentley Sep 29, 2025
e2eb25a
use object oriented interface to workflow file
idbentley Sep 29, 2025
8d4aa57
remove pause command, and update generation so applying custom code i…
idbentley Sep 29, 2025
59d93fd
don't fetch new build
idbentley Sep 29, 2025
dae01c8
added compilation and linting to registercustomcode
Oct 1, 2025
a3b2c27
iter
idbentley Oct 1, 2025
da30201
improved output
idbentley Oct 1, 2025
484530b
back out commit upon fialure
idbentley Oct 1, 2025
9382bcd
cleanup
idbentley Oct 1, 2025
0a73cd8
disabled versioning
Oct 7, 2025
a583160
iter
idbentley Oct 3, 2025
4b2be1a
remove unused resolve flag
idbentley Oct 7, 2025
be00abc
skip version
idbentley Oct 6, 2025
cc22172
introduce hash
idbentley Oct 7, 2025
36bca50
support multi target workflows
idbentley Oct 8, 2025
400b54e
fix command.go
idbentley Oct 8, 2025
af628fb
fix multi-build
idbentley Oct 8, 2025
b5bcaad
cleanup
idbentley Oct 9, 2025
db90d53
New conflict resolution flow
Oct 9, 2025
df3743a
fixes
Oct 10, 2025
a37fcaa
cleanup and prevent common issues
idbentley Oct 10, 2025
ccd4429
reintroduce accidental deletion
idbentley Oct 10, 2025
6406863
Saving patches to .diff file instead of gen.lock
Oct 23, 2025
5177446
Integration test for perfect custom code scenario
Oct 23, 2025
ac8b44e
Fixed patch deletion when no custom code is found + integration tests…
Oct 24, 2025
5dd125c
test improvement
Oct 24, 2025
6180540
tests and added added git reset --hard HEAD after capturing patches b…
Oct 27, 2025
fa2fc1e
Catching conflict error from the generator
Oct 28, 2025
131c26c
tests
Oct 28, 2025
e907a2e
reverse strategy + multitarget tests
Oct 28, 2025
efeaeae
multitarget conflict resolution fix
Oct 29, 2025
bba77ba
use byprefix functions instead of bylinenumber
idbentley Nov 3, 2025
a57b83d
cleanup and tests passing
idbentley Nov 5, 2025
24d0a3b
tests
idbentley Nov 5, 2025
9f41acd
cleanup and fix tests
idbentley Nov 5, 2025
b639ee1
cleanup
idbentley Nov 5, 2025
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
139 changes: 139 additions & 0 deletions cmd/customcode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package cmd

import (
"context"
"fmt"

"github.com/speakeasy-api/speakeasy/internal/charm/styles"
"github.com/speakeasy-api/speakeasy/internal/utils"
"github.com/speakeasy-api/speakeasy/internal/model"
"github.com/speakeasy-api/speakeasy/internal/model/flag"
"github.com/speakeasy-api/speakeasy/internal/registercustomcode"
"github.com/speakeasy-api/speakeasy/internal/log"
"github.com/speakeasy-api/speakeasy/internal/env"

"github.com/speakeasy-api/speakeasy/internal/run"
"go.uber.org/zap"
)

type RegisterCustomCodeFlags struct {
Show bool `json:"show"`
Apply bool `json:"apply-only"`
ApplyReverse bool `json:"apply-reverse"`
InstallationURL string `json:"installationURL"`
InstallationURLs map[string]string `json:"installationURLs"`
Repo string `json:"repo"`
RepoSubdir string `json:"repo-subdir"`
RepoSubdirs map[string]string `json:"repo-subdirs"`
SkipVersioning bool `json:"skip-versioning"`
Output string `json:"output"`
SetVersion string `json:"set-version"`

}

var registerCustomCodeCmd = &model.ExecutableCommand[RegisterCustomCodeFlags]{
Usage: "customcode",
Short: "Register custom code with the OpenAPI generation system.",
Long: `Register custom code with the OpenAPI generation system.`,
Run: registerCustomCode,
Flags: []flag.Flag{
flag.BooleanFlag{
Name: "show",
Shorthand: "s",
Description: "show custom code patches",
},
flag.BooleanFlag{
Name: "apply-only",
Shorthand: "a",
Description: "apply existing custom code patches without running generation",
},
flag.EnumFlag{
Name: "output",
Shorthand: "o",
Description: "What to output while running",
AllowedValues: []string{"summary", "mermaid", "console"},
DefaultValue: "summary",
},
},
}

func registerCustomCode(ctx context.Context, flags RegisterCustomCodeFlags) error {
logger := log.From(ctx).With(zap.String("method", "RegisterCustomCode"))

// If --show flag is provided, show existing customcode
if flags.Show {
wf, _, err := utils.GetWorkflowAndDir()
if err != nil {
return fmt.Errorf("Could not find workflow file")
}
var allErrors []error
for targetName, target := range wf.Targets {
logger.Info("Showing target", zap.String("target_name", targetName))
if err := registercustomcode.ShowCustomCodePatch(ctx, target); err != nil {
allErrors = append(allErrors, fmt.Errorf("target %s: %w", targetName, err))
}
}
if len(allErrors) > 0 {
return fmt.Errorf("errors occurred: %v", allErrors)
}
return nil
}

// If --apply-only flag is provided, only apply existing patches
if flags.Apply {
wf, _, err := utils.GetWorkflowAndDir()
if err != nil {
return fmt.Errorf("Could not find workflow file")
}
for _, target := range wf.Targets {
registercustomcode.ApplyCustomCodePatch(ctx, target)
}
return nil
}

// Call the registercustomcode functionality
return registercustomcode.RegisterCustomCode(ctx, func(targetName string) error {
opts := []run.Opt{
run.WithTarget(targetName),
run.WithRepo(flags.Repo),
run.WithRepoSubDirs(flags.RepoSubdirs),
run.WithInstallationURLs(flags.InstallationURLs),
run.WithSkipVersioning(true),
run.WithSkipApplyCustomCode(),
}
workflow, err := run.NewWorkflow(
ctx,
opts...,
)
defer func() {
// we should leave temp directories for debugging if run fails
if env.IsGithubAction() {
workflow.Cleanup()
}
}()

switch flags.Output {
case "summary":
err = workflow.RunWithVisualization(ctx)
if err != nil {
return err
}
case "mermaid":
err = workflow.Run(ctx)
workflow.RootStep.Finalize(err == nil)
mermaid, err := workflow.RootStep.ToMermaidDiagram()
if err != nil {
return err
}
log.From(ctx).Println("\n" + styles.MakeSection("Mermaid diagram of workflow", mermaid, styles.Colors.Blue))
case "console":
err = workflow.Run(ctx)
// workflow.RootStep.Finalize(err == nil)
if err != nil {
return err
}
}
return nil
}, )

}
4 changes: 4 additions & 0 deletions cmd/quickstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ func retryWithSampleSpec(ctx context.Context, workflowFile *workflow.Workflow, i
run.WithTarget(initialTarget),
run.WithShouldCompile(!skipCompile),
)
if err != nil {
return false, err
}
wf.FromQuickstart = true

if err != nil {
return false, fmt.Errorf("failed to parse workflow: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ func Init(version, artifactArch string) {
addCommand(rootCmd, AskCmd)
addCommand(rootCmd, reproCmd)
addCommand(rootCmd, orphanedFilesCmd)
addCommand(rootCmd, registerCustomCodeCmd)
pullInit()
// addCommand(rootCmd, pullCmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be re-added before merging. Locally this raised an error for me.

}

func addCommand(cmd *cobra.Command, command model.Command) {
Expand Down
13 changes: 13 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type RunFlags struct {
SkipTesting bool `json:"skip-testing"`
SkipVersioning bool `json:"skip-versioning"`
SkipUploadSpec bool `json:"skip-upload-spec"`
SkipCustomCode bool `json:"skip-custom-code"`
FrozenWorkflowLock bool `json:"frozen-workflow-lockfile"`
Force bool `json:"force"`
Output string `json:"output"`
Expand Down Expand Up @@ -129,6 +130,10 @@ var runCmd = &model.ExecutableCommand[RunFlags]{
Name: "skip-upload-spec",
Description: "skip uploading the spec to the registry",
},
flag.BooleanFlag{
Name: "skip-custom-code",
Description: "skip applying custom code patches during generation",
},
flag.BooleanFlag{
Name: "frozen-workflow-lockfile",
Description: "executes using the stored inputs from the workflow.lock, such that no OAS change occurs",
Expand Down Expand Up @@ -439,6 +444,10 @@ func runNonInteractive(ctx context.Context, flags RunFlags) error {
run.WithSourceLocation(flags.SourceLocation),
}

if flags.SkipCustomCode {
opts = append(opts, run.WithSkipApplyCustomCode())
}

if flags.Minimal {
opts = append(opts, minimalOpts...)
}
Expand Down Expand Up @@ -502,6 +511,10 @@ func runInteractive(ctx context.Context, flags RunFlags) error {
run.WithSourceLocation(flags.SourceLocation),
}

if flags.SkipCustomCode {
opts = append(opts, run.WithSkipApplyCustomCode())
}

if flags.Minimal {
opts = append(opts, minimalOpts...)
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ replace github.com/pb33f/doctor => github.com/speakeasy-api/doctor v0.20.0-fixva

replace github.com/pb33f/libopenapi => github.com/speakeasy-api/libopenapi v0.21.9-fixhiddencomps-fixed

replace github.com/speakeasy-api/openapi-generation/v2 => ../openapi-generation
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be removed before merging.


require (
github.com/AlekSi/pointer v1.2.0
github.com/KimMachineGun/automemlimit v0.7.1
Expand Down
Loading
Loading