Skip to content

Commit

Permalink
fix: dont fail if max-suggestions applied (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraagnalluri authored Aug 1, 2023
1 parent a5b6568 commit c7bc286
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
14 changes: 1 addition & 13 deletions cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/manifoldco/promptui"
"github.com/speakeasy-api/speakeasy/internal/sdkgen"
"github.com/speakeasy-api/speakeasy/internal/suggestions"
"github.com/speakeasy-api/speakeasy/internal/utils"
"github.com/speakeasy-api/speakeasy/internal/validation"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -39,7 +38,6 @@ func validateInit() {

//nolint:errcheck
func validateOpenAPIInit() {
validateOpenAPICmd.Flags().BoolP("fix", "f", false, "fix openapi failures with llm suggestions")
validateOpenAPICmd.Flags().BoolP("output-hints", "o", false, "output validation hints in addition to warnings/errors")
validateOpenAPICmd.Flags().StringP("schema", "s", "", "path to the OpenAPI document")
_ = validateOpenAPICmd.MarkFlagRequired("schema")
Expand All @@ -62,22 +60,12 @@ func validateOpenAPI(cmd *cobra.Command, args []string) error {
return err
}

var suggestionsConfig *suggestions.Config
fix, err := cmd.Flags().GetBool("fix")
if err != nil {
return err
}

if fix {
suggestionsConfig = &suggestions.Config{}
}

outputHints, err := cmd.Flags().GetBool("output-hints")
if err != nil {
return err
}

if err := validation.ValidateOpenAPI(cmd.Context(), schemaPath, suggestionsConfig, outputHints); err != nil {
if err := validation.ValidateOpenAPI(cmd.Context(), schemaPath, nil, outputHints); err != nil {
rootCmd.SilenceUsage = true

return err
Expand Down
5 changes: 4 additions & 1 deletion internal/validation/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func ValidateOpenAPI(ctx context.Context, schemaPath string, suggestionsConfig *
if len(vErrs) > 0 {
status := "OpenAPI spec invalid ✖"
github.GenerateSummary(status, vErrs)
return fmt.Errorf(status)
if suggestionsConfig == nil {
return fmt.Errorf(status)
}
return nil
} else {
if findSuggestions {
fmt.Println(promptui.Styler(promptui.FGGreen, promptui.FGBold)("No errors found in OpenAPI spec, skipping suggestions!"))
Expand Down

0 comments on commit c7bc286

Please sign in to comment.