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

reproduce #625 #629

Closed
wants to merge 1 commit into from
Closed

reproduce #625 #629

wants to merge 1 commit into from

Conversation

fenollp
Copy link
Collaborator

@fenollp fenollp commented Oct 7, 2022

cc #625

Look into

// parsePrimitive returns a value that is created by parsing a source string to a primitive type
// that is specified by a schema. The function returns nil when the source string is empty.
// The function panics when a schema has a non primitive type.
func parsePrimitive(raw string, schema *openapi3.SchemaRef) (interface{}, error) {
if raw == "" {
return nil, nil
}
switch schema.Value.Type {
case "integer":
v, err := strconv.ParseFloat(raw, 64)
if err != nil {
return nil, &ParseError{Kind: KindInvalidFormat, Value: raw, Reason: "an invalid " + schema.Value.Type, Cause: err.(*strconv.NumError).Err}
}
return v, nil
case "number":
v, err := strconv.ParseFloat(raw, 64)
if err != nil {
return nil, &ParseError{Kind: KindInvalidFormat, Value: raw, Reason: "an invalid " + schema.Value.Type, Cause: err.(*strconv.NumError).Err}
}
return v, nil
case "boolean":
v, err := strconv.ParseBool(raw)
if err != nil {
return nil, &ParseError{Kind: KindInvalidFormat, Value: raw, Reason: "an invalid " + schema.Value.Type, Cause: err.(*strconv.NumError).Err}
}
return v, nil
case "string":
return raw, nil
default:
panic(fmt.Sprintf("schema has non primitive type %q", schema.Value.Type))
}
}

Signed-off-by: Pierre Fenoll <[email protected]>
@fenollp
Copy link
Collaborator Author

fenollp commented Nov 15, 2022

Superseeded by #664

@fenollp fenollp closed this Nov 15, 2022
@fenollp fenollp deleted the issue625 branch November 15, 2022 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant