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(fetch): support explode property #1604

Merged

Conversation

soartec-lab
Copy link
Member

@soartec-lab soartec-lab commented Aug 31, 2024

Status

READY

Description

Related #1285

The fetch clent now supports OpenAPI's explode type query params.

parameters:
  - name: limit
    in: query
    description: How many items to return at one time
    explode: true
    schema:
      type: array
      items:
        type: integer

Before

Sets the array as a query parameter regardless of the value of explode like a ?parameter=a,b,c

Object.entries(params || {}).forEach(([key, value]) => {
  if (value === null) {
    normalizedParams.append(key, 'null');
  } else if (value !== undefined) {
    normalizedParams.append(key, value.toString());
  }
});

// => ?parameter=a,b,c

After

Modify query parameter construction by referencing the value of explode.

When default or set false to explode:

The generated processing is as follows:

Object.entries(params || {}).forEach(([key, value]) => {
  if (value !== undefined) {
    normalizedParams.append(key, value === null ? 'null' : value.toString());
  }
});

// => ?parameter=a&parameter=b&parameter=c

When set true to explode:

The generated processing is as follows:

Object.entries(params || {}).forEach(([key, value]) => {
+  if (value instanceof Array) {
+    value.forEach((v) => normalizedParams.append(key, v === null ? 'null' : v.toString()));
+  }
    
  if (value !== undefined) {
    normalizedParams.append(key, value === null ? 'null' : value.toString())
  }
});

// => parameter=a&parameter=b&parameter=c

Related PRs

This is a PR derived from #1580 and solves the same problem

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

You can check by i added test case.

@soartec-lab soartec-lab force-pushed the feat/fetch/support-explode-property branch from 50e3a9b to 7a3644c Compare August 31, 2024 01:31
@soartec-lab soartec-lab requested a review from melloware August 31, 2024 01:36
@soartec-lab soartec-lab added enhancement New feature or request fetch Fetch client related issue labels Aug 31, 2024
@soartec-lab soartec-lab modified the milestone: 7.0.2 Aug 31, 2024
@soartec-lab
Copy link
Member Author

@n2k3
I created a new PR based on #1580 that you created. Does control with explode property solve your problem?

@soartec-lab soartec-lab merged commit 8e9f8ac into orval-labs:master Sep 1, 2024
2 checks passed
@soartec-lab soartec-lab linked an issue Sep 1, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fetch Fetch client related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for CSV/explode=false query parameters "styles"
2 participants