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

feat: support for query parameter serialization style "deepObject" #78

Merged
merged 10 commits into from
Jul 22, 2024

Conversation

vdayanand
Copy link
Member

@vdayanand vdayanand commented Jul 4, 2024

Introduction

The deepObject style is used for complex object serialization in query parameters for OpenAPI 3.0 (https://swagger.io/docs/specification/serialization). This style enables the representation of nested objects particularly suitable for APIs that need to handle hierarchical data structures.

Description

The deepObject format represents nested objects and arrays by encoding each level of nesting as a separate query parameter, using square brackets to denote the hierarchy. Each parameter consists of a base key followed by one or more nested keys.
Key Elements

  • Nested Objects: Represented by square brackets, where each bracket level denotes a deeper level of the object hierarchy.
  • Arrays: Represented by numeric keys inside square brackets, indicating the index of each element in the array.

Note: OpenAPI spec doesn't define array de-serialization for deepObject. So basically we have extended it for arrays

Examples
  1. a[b][c][d]=value1&a[b][c][e]=value2&a[f]=value3 would be intermediately deserialized as
{
  "a": {
    "b": {
      "c": {
        "d": "value1",
        "e": "value2"
      }
    },
    "f": "value3"
  }
}
  1. a[b][0]=value1&&a[b][1]=value2 would be intermediately deserialized as:
{
  "a": {
    "b": [
      "value1",
      "value2"
    ]
  }
}

@vdayanand vdayanand changed the title feat: support for query parameter deserialization of type "deepObject" feat: support for query parameter deserialization style "deepObject" Jul 4, 2024
Copy link
Member

@tanmaykm tanmaykm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except for some minor comments!
Will be awesome to have the client side implementation too and have an end-to-end test.

src/server.jl Outdated Show resolved Hide resolved
src/server.jl Outdated Show resolved Hide resolved
src/server.jl Outdated Show resolved Hide resolved
src/server.jl Outdated Show resolved Hide resolved
@vdayanand
Copy link
Member Author

Added client support as well. I will add end to end tests

@vdayanand vdayanand changed the title feat: support for query parameter deserialization style "deepObject" feat: support for query parameter serialization style "deepObject" Jul 5, 2024
src/client.jl Outdated Show resolved Hide resolved
src/client.jl Show resolved Hide resolved
src/client.jl Outdated Show resolved Hide resolved
src/json.jl Outdated Show resolved Hide resolved
@vdayanand vdayanand marked this pull request as ready for review July 10, 2024 08:25
@vdayanand
Copy link
Member Author

I have added EOE test for deep object

@vdayanand vdayanand requested a review from tanmaykm July 10, 2024 17:18
src/client.jl Outdated Show resolved Hide resolved
src/client.jl Show resolved Hide resolved
src/json.jl Show resolved Hide resolved
src/server.jl Outdated Show resolved Hide resolved
src/server.jl Outdated Show resolved Hide resolved
src/server.jl Outdated
for param in params
current = deserialized_dict
for part in param.keylist[1:end-1]
current = get!(current, part, Dict{String, Any}())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to get!(current, part) do format? That would create the Dict only if necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

vdayanand and others added 3 commits July 22, 2024 11:23
Co-authored-by: Tanmay Mohapatra <[email protected]>
Co-authored-by: Tanmay Mohapatra <[email protected]>
Co-authored-by: Tanmay Mohapatra <[email protected]>
src/server.jl Outdated Show resolved Hide resolved
@vdayanand vdayanand requested a review from tanmaykm July 22, 2024 07:15
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.

2 participants