Skip to content

Commit

Permalink
Revert ParseSchema default token limit of 1500, add ParseSchemaWithLi…
Browse files Browse the repository at this point in the history
…mit, ParseSchemasWithLimit (#306)

Signed-off-by: Steve Coffman <[email protected]>
  • Loading branch information
StevenACoffman authored Jun 12, 2024
1 parent 36a3658 commit 55a3c47
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion parser/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,39 @@ func ParseSchemas(inputs ...*Source) (*SchemaDocument, error) {
func ParseSchema(source *Source) (*SchemaDocument, error) {
p := parser{
lexer: lexer.New(source),
maxTokenLimit: 15000, // default value
maxTokenLimit: 0, // default value is unlimited
}
sd, err := p.parseSchemaDocument(), p.err
if err != nil {
return nil, err
}

for _, def := range sd.Definitions {
def.BuiltIn = source.BuiltIn
}
for _, def := range sd.Extensions {
def.BuiltIn = source.BuiltIn
}

return sd, nil
}

func ParseSchemasWithLimit(maxTokenLimit int, inputs ...*Source) (*SchemaDocument, error) {
sd := &SchemaDocument{}
for _, input := range inputs {
inputAst, err := ParseSchemaWithLimit(input, maxTokenLimit)
if err != nil {
return nil, err
}
sd.Merge(inputAst)
}
return sd, nil
}

func ParseSchemaWithLimit(source *Source, maxTokenLimit int) (*SchemaDocument, error) {
p := parser{
lexer: lexer.New(source),
maxTokenLimit: maxTokenLimit, // 0 is unlimited
}
sd, err := p.parseSchemaDocument(), p.err
if err != nil {
Expand Down

0 comments on commit 55a3c47

Please sign in to comment.