Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert ParseSchema default token limit of 1500, add ParseSchemaWithLimit, ParseSchemasWithLimit #306

Merged
merged 1 commit into from
Jun 12, 2024
Merged
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
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