Skip to content
Merged
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
6 changes: 2 additions & 4 deletions internal/api/client.gen.go

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

2 changes: 2 additions & 0 deletions scripts/gen-flags/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ func extractCommandConfig(name, path, method string, op *Operation, schemas map[
}

func processField(commandName, fieldName string, field *Field, schemas map[string]*Field) (*FieldConfig, error) {
ApplyDescriptionOverride(commandName, fieldName, field)

category, err := ClassifyField(field, schemas)
if err != nil {
return nil, err
Expand Down
26 changes: 25 additions & 1 deletion scripts/gen-flags/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ var FlattenWithoutPrefix = map[string]map[string]bool{
},
}

// FieldDescriptionOverrides contains command-scoped descriptions for fields
// whose OpenAPI metadata is currently flattened away before flag generation.
var FieldDescriptionOverrides = map[string]map[string]string{
"SessionStart": {
"browser_type": "The browser type to use. Can be chromium, chrome or firefox.",
},
}

// Field represents a field in an OpenAPI schema
type Field struct {
Name string
Expand Down Expand Up @@ -163,6 +171,17 @@ type FieldConfig struct {
SubFields []*FieldConfig // For flattened objects
}

func ApplyDescriptionOverride(commandName, fieldName string, field *Field) {
if field.Description != "" {
return
}
if commandOverrides, ok := FieldDescriptionOverrides[commandName]; ok {
if description, ok := commandOverrides[fieldName]; ok {
field.Description = description
}
}
}

// ClassifyField determines how to generate flags for a field
func ClassifyField(field *Field, schemas map[string]*Field) (FieldCategory, error) {
// Check if field should be skipped entirely
Expand All @@ -183,8 +202,13 @@ func ClassifyField(field *Field, schemas map[string]*Field) (FieldCategory, erro
}
// Check if the referenced type is an enum
if len(refField.Enum) > 0 {
// Copy enum values to field for later use
// Copy enum metadata to field for later use. Some OpenAPI
// generators put enum descriptions on the referenced schema instead
// of the field itself.
field.Enum = refField.Enum
if field.Description == "" {
field.Description = refField.Description
}
field.Type = "string"
return CategoryEnumFlag, nil
}
Expand Down
Loading