-
Notifications
You must be signed in to change notification settings - Fork 85
Fixes and enhancements for array query param handling #241
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
Merged
bourdakos1
merged 8 commits into
cloud-annotations:main
from
chris48s:array-query-params
Mar 14, 2023
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
770f706
add examples to demo site with array query params
chris48s b41b95d
fix infinite loop on pages with array query params
chris48s 554aafa
respect maxItems property
chris48s 144e8c4
respect style and explode properties, add tests
chris48s d616c10
different fix for infinite render loop
chris48s 71ac129
use disabled button if we've hit maxItems
chris48s 55e3c2c
adjust button enabled/disabled logic
chris48s 0298434
correct logic
chris48s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| version: 1.0.0 | ||
| title: "" | ||
| servers: | ||
| - url: https://example.com | ||
| paths: | ||
| /Things: | ||
| get: | ||
| summary: View Things | ||
| parameters: | ||
| - name: "arrayParam" | ||
| in: "query" | ||
| required: false | ||
| description: "You can pass 0, 1 or 2 occurrences of this in the query string" | ||
| style: "form" | ||
| explode: true | ||
| schema: | ||
| type: "array" | ||
| maxItems: 2 | ||
| items: | ||
| type: "string" | ||
| responses: | ||
| "200": | ||
| description: OK | ||
| /Stuff: | ||
| get: | ||
| summary: View Stuff | ||
| parameters: | ||
| - name: "arrayParam" | ||
| in: "query" | ||
| required: false | ||
| description: "You can pass 0, 1 or 2 occurrences of this in the query string" | ||
| style: "pipeDelimited" | ||
| explode: false | ||
| schema: | ||
| type: "array" | ||
| maxItems: 2 | ||
| items: | ||
| type: "string" | ||
| responses: | ||
| "200": | ||
| description: OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/buildPostmanRequest.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* ============================================================================ | ||
| * Copyright (c) Cloud Annotations | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * ========================================================================== */ | ||
|
|
||
| import sdk from "postman-collection"; | ||
|
|
||
| import { openApiQueryParams2PostmanQueryParams } from "./buildPostmanRequest"; | ||
|
|
||
| describe("openApiQueryParams2PostmanQueryParams", () => { | ||
| it("should transform empty array to empty array", () => { | ||
| const expected: sdk.QueryParam[] = []; | ||
| const actual = openApiQueryParams2PostmanQueryParams([]); | ||
| expect(actual).toStrictEqual(expected); | ||
| }); | ||
|
|
||
| it("default to comma delimited", () => { | ||
| const expected: sdk.QueryParam[] = [ | ||
| new sdk.QueryParam({ key: "arrayParam", value: "abc,def" }), | ||
| ]; | ||
| const actual = openApiQueryParams2PostmanQueryParams([ | ||
| { | ||
| name: "arrayParam", | ||
| in: "query", | ||
| value: ["abc", "def"], | ||
| }, | ||
| ]); | ||
| expect(actual).toStrictEqual(expected); | ||
| }); | ||
|
|
||
| it("should expand params if explode=true", () => { | ||
| const expected: sdk.QueryParam[] = [ | ||
| new sdk.QueryParam({ key: "arrayParam", value: "abc" }), | ||
| new sdk.QueryParam({ key: "arrayParam", value: "def" }), | ||
| ]; | ||
| const actual = openApiQueryParams2PostmanQueryParams([ | ||
| { | ||
| name: "arrayParam", | ||
| in: "query", | ||
| style: "form", | ||
| explode: true, | ||
| value: ["abc", "def"], | ||
| }, | ||
| ]); | ||
| expect(actual).toStrictEqual(expected); | ||
| }); | ||
|
|
||
| it("should respect style=pipeDelimited", () => { | ||
| const expected: sdk.QueryParam[] = [ | ||
| new sdk.QueryParam({ key: "arrayParam", value: "abc|def" }), | ||
| ]; | ||
| const actual = openApiQueryParams2PostmanQueryParams([ | ||
| { | ||
| name: "arrayParam", | ||
| in: "query", | ||
| style: "pipeDelimited", | ||
| value: ["abc", "def"], | ||
| }, | ||
| ]); | ||
| expect(actual).toStrictEqual(expected); | ||
| }); | ||
|
|
||
| it("should respect style=spaceDelimited", () => { | ||
| const expected: sdk.QueryParam[] = [ | ||
| new sdk.QueryParam({ key: "arrayParam", value: "abc%20def" }), | ||
| ]; | ||
| const actual = openApiQueryParams2PostmanQueryParams([ | ||
| { | ||
| name: "arrayParam", | ||
| in: "query", | ||
| style: "spaceDelimited", | ||
| value: ["abc", "def"], | ||
| }, | ||
| ]); | ||
| expect(actual).toStrictEqual(expected); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.