openapi_parser icon indicating copy to clipboard operation
openapi_parser copied to clipboard

Validate path params defined on the path item

Open danielfone opened this issue 5 years ago • 5 comments

Since parameters can be defined on both the path item or the operation, we need to validate path params against both objects, like we do with the query params.

danielfone avatar Jul 04 '20 10:07 danielfone

@ota42y ahh good catch! I'm not likely to be able to look at this for a week or so. If I get to it before you I'm happy to have a go, otherwise all yours. Thanks! 😁

danielfone avatar Aug 10 '20 11:08 danielfone

There is no reason to rush to release a new version, so give it a try! 😄

ota42y avatar Aug 10 '20 11:08 ota42y

@ota42y I haven't added any specs for this yet, I wanted to see what you thought of the implementation. I've opted to merge the individual hashes explicitly in the OpenAPIParser::Schemas::Operation class since I think it makes it clearer what's going on.

Alternatively, we could add a public ParameterValidatable#merged_params method and keep the merging all inside the ParameterValidatable concern. Something like:

  # module OpenAPIParser::ParameterValidatable
  def merged_params
    return divided_parameter_hash unless parent&.respond_to?(:merged_params)

    @merged_params ||= Hash.new do |merged_params, location|
      parent_params = parent.merged_params[location] || {}
      merged_params[location] = parent_params.merge(divided_parameter_hash[location])
    end
  end

  def header_parameter_hash
    merged_params['header'] || {}
  end

  # etc…

I think this is a more abstract and less obvious approach though.

What do you think?

danielfone avatar Aug 30 '20 10:08 danielfone

Sorry for late reply... 🙇

I think this is a more abstract and less obvious approach though. I think so too.

Your approach( merging in the OpenAPIParser::Schemas::Operation ) is very good 👍 👍 👍 👍 👍

  • Performance is good because once merged it will not change after that.
  • Components Object does not have Operation Object in OpenAPI 3 definition so Operation Object is always under the Path Item Object.

ota42y avatar Sep 22 '20 11:09 ota42y

@ota42y thanks for the feedback. I'll add some specs and ping you for a final review.

danielfone avatar Sep 22 '20 21:09 danielfone