openapi-core icon indicating copy to clipboard operation
openapi-core copied to clipboard

Add deepObject support

Open Yarn-e opened this issue 4 years ago • 0 comments

Problem statement

Currently deepObjects are not supported, this PR adds that support.

Description

Example spec

components:
    parameters:
      exampleParameter:
        name: paramObj
        in: query
        required: true
        explode: true
        style: deepObject
        schema:
          type: object
          properties: 
            count: 
              type: integer
            name:
              type: string

Sadly it doesn't really fit in the ParameterDeserializersFactory ideology as it would never reach that step as get_value() in parameters.py would always fail as it tries to find the name of the param_or_header in the specific location. This is because how a deepObjects query param looks like (e.g. someurl.com/?paramObj[count]=1&paramObj[name]=John), the function would try to find paramObj in the location, which it would not find as the QueryParams will be split into a dict like this: {'paramObj[count]': 1, 'paramObj[name]': John}.

In my proposed solution it would split the location dict key into 2 parts, the actual key we want to find paramObj and then create a dict of the 2nd part of the key (whats inside the brackets) with its actual value: {'count': 1, 'name': 'John'}. Afterwards this dict is checked via the schema of the object.

I highly doubt this solution will get accepted, so if you know a way to make this cleaner/better please lmk 🙏

Todos

  • [x] Tests

Related issue

  • https://github.com/p1c2u/openapi-core/issues/250

Yarn-e avatar Nov 16 '21 14:11 Yarn-e