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

Disable coerece_form_params option in the case of application/json #301

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

meganemura
Copy link
Contributor

@meganemura meganemura commented Feb 12, 2021

To fix #286.

This disables coerece_form_params option in the case of application/json.
But, disabling coerce_form_params prevents coercing DateTime in object.

https://github.com/ota42y/openapi_parser/blob/d17334a866b39fa197d324b9d321df2b03d469b6/lib/openapi_parser/schema_validators/object_validator.rb#L41

I found that defining ObjectValidator#initialize(validator, coerce_value, datetime_coerce_class) in OpenAPIParser and adding coercing condition like below makes it working well. but I'm not sure this way is good or not.

-value.merge!(coerced_values.to_h) if @coerce_value
+value.merge!(coerced_values.to_h) if @coerce_value || !@datetime_coerce_class.nil?

@ota42y
Copy link
Member

ota42y commented Mar 20, 2021

Thanks for the PR.
I think this PR is good, because we should not converting json by coerce_form_params=true.

When we use form/path paramemter integer will be convert string so we need string to integer.
However we don't need convet JSON because it have a types so I'd like to make this behavior the default in next major version (we shouldn't break backward compatibility).
So we need create an option called corece_json_params, and if it is not set, we should show a warning message and set 'true' (we will change default false in next version)

But, converting the datetime format string to Datetime object is useful for JSON users, so I think many user will want to use it.
So we should enable this feature separately from the corece_json_params disable.

To summarize

  • Do not coerce json by coerce_form_param=true
    • This PR is goodl 👍
  • Add coerce_json_param
    • We can keep the current behavior by default
    • We should change default false in next version
  • Rename coerce_date_times to convert_stirng_by_datetime_formant
    • do a convert regardless of coerce_json_param=false (requires a change to openapi_parser)
    • Use coerce to convert string to OpenAPI definition types, and convert to change from OpenAPI definition types to Ruby's object.

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.

problem with oneOf: string/integer
2 participants