Skip to content

Commit

Permalink
feat: Support skipping of type generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Jan 14, 2025
1 parent 024f71e commit 51bf6ef
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,10 @@ func (s Schema) hasNumericConstraints() bool {
s.MultipleOf != nil
}

var possibleSkipFields = []string{"title", "description", "required", "default", "additionalProperties"}
var possibleSkipFields = []string{"type", "title", "description", "required", "default", "additionalProperties"}

type SkipAutoGenerationConfig struct {
Title, Description, Required, Default, AdditionalProperties bool
Type, Title, Description, Required, Default, AdditionalProperties bool
}

func NewSkipAutoGenerationConfig(flag []string) (*SkipAutoGenerationConfig, error) {
Expand All @@ -610,6 +610,9 @@ func NewSkipAutoGenerationConfig(flag []string) (*SkipAutoGenerationConfig, erro
if !slices.Contains(possibleSkipFields, fieldName) {
invalidFlags = append(invalidFlags, fieldName)
}
if fieldName == "type" {
config.Type = true
}
if fieldName == "title" {
config.Title = true
}
Expand Down Expand Up @@ -880,7 +883,7 @@ func YamlToSchema(
}
}

if keyNodeSchema.Type.IsEmpty() {
if keyNodeSchema.Type.IsEmpty() && !skipAutoGeneration.Type {
nodeType, err := typeFromTag(valueNode.Tag)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 51bf6ef

Please sign in to comment.