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

support format: binary #108

Open
ota42y opened this issue May 4, 2021 · 5 comments
Open

support format: binary #108

ota42y opened this issue May 4, 2021 · 5 comments
Labels
ready ready to implement

Comments

@ota42y
Copy link
Owner

ota42y commented May 4, 2021

Plan

OpenAPI 3.0.3 support fomat: binary so we should support it.
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#data-types

Rack set file as Rack::Multipart::UploadedFile so we should check it in string validator.
https://github.com/ota42y/openapi_parser/blob/master/lib/openapi_parser/schema_validators/string_validator.rb#L10

Other

related interagent/committee#255 (comment)

@ota42y ota42y added the ready ready to implement label May 4, 2021
@fmarkwong
Copy link

@ota42y wanted to ask what the status on this is. Is it in production already? I still get the same "expected string but received Hash" validation error for file uploads (with type: string and format: binary)

@ota42y
Copy link
Owner Author

ota42y commented Jan 28, 2023

Sorry, we are not currently implementing it, and we have no plans to do so for the time being.

@pechorin
Copy link

pechorin commented Mar 3, 2023

Sorry for question: are there any workaround for this? For now it's impossible to validate submitted via form data file :/

@ota42y
Copy link
Owner Author

ota42y commented Mar 12, 2023

At the moment there are none.
However, if there is an error, we would like to have some workaround (no verification, but no error either).

@pechorin
Copy link

This code/patch works for me:

module StringValidatorPatch
  def coerce_and_validate(value, schema, **_keyword_args)
    # Diff:
    # :- return OpenAPIParser::ValidateError.build_error_result(value, schema) unless value.kind_of?(String)
    #
    # :+
    if !value.is_a?(String)
      if schema.format == 'binary'
        # Fix: in tests rack uploaded file not converts automatically (committee bug)
        if value[:tempfile]
          return [ActionDispatch::Http::UploadedFile.new(value), nil]
        else
          return [value, nil]
        end
      else
        return OpenAPIParser::ValidateError.build_error_result(value, schema)
      end
    end
    # End of diff

    value, err = check_enum_include(value, schema)
    return [nil, err] if err

    value, err = pattern_validate(value, schema)
    return [nil, err] if err

    value, err = validate_max_min_length(value, schema)
    return [nil, err] if err

    value, err = validate_email_format(value, schema)
    return [nil, err] if err

    value, err = validate_uuid_format(value, schema)
    return [nil, err] if err

    value, err = validate_date_format(value, schema)
    return [nil, err] if err

    value, err = validate_datetime_format(value, schema)
    return [nil, err] if err

    [value, nil]
  end
end

class OpenAPIParser::SchemaValidator::StringValidator
  prepend StringValidatorPatch
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ready to implement
Projects
None yet
Development

No branches or pull requests

3 participants