Skip to content

Commit

Permalink
feat: validation specific usage gen error message (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-timothy-albert authored Nov 14, 2024
1 parent 6f30157 commit 409348b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/usagegen/usagegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"bytes"
"context"
"fmt"
"github.com/speakeasy-api/sdk-gen-config/workflow"
"github.com/speakeasy-api/speakeasy-core/openapi"
"io/fs"
"os"
"regexp"
"sort"
"strings"

"github.com/speakeasy-api/sdk-gen-config/workflow"
"github.com/speakeasy-api/speakeasy-core/openapi"

"github.com/speakeasy-api/speakeasy/internal/utils"

"github.com/pkg/errors"
Expand Down Expand Up @@ -69,10 +70,18 @@ func Generate(ctx context.Context, customerID, lang, schemaPath, header, token,
}

if errs := g.Generate(ctx, schema, schemaPath, lang, configPath, isRemote, false); len(errs) > 0 {
isValidationError := false
for _, err := range errs {
if strings.Contains(err.Error(), "validation error:") {
isValidationError = true
}
l.Error("", zap.Error(err))
}

if isValidationError {
return fmt.Errorf("failed to generate usage snippets: the provided openapi spec is not valid for sdk generation")
}

return fmt.Errorf("failed to generate usage snippets for %s ✖", lang)
}

Expand Down

0 comments on commit 409348b

Please sign in to comment.