-
Notifications
You must be signed in to change notification settings - Fork 14
feat: support exploded form parameters in docs #2130
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
Changes from all commits
8e90809
e6d74e6
9440725
d33f4ea
5a73774
3ecc984
5c07530
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { | ||
HttpRequestBodyShape, | ||
PropertyKey, | ||
TypeShape, | ||
} from "@fern-api/fdr-sdk/api-definition"; | ||
import { PlaygroundFormStateBody } from "../../types"; | ||
import { serializeFormStateBody } from "../serialize"; | ||
|
||
const STRING_VALUE_SHAPE: TypeShape = { | ||
type: "alias", | ||
value: { | ||
type: "primitive", | ||
value: { | ||
type: "string", | ||
format: undefined, | ||
regex: undefined, | ||
minLength: undefined, | ||
maxLength: undefined, | ||
default: undefined, | ||
}, | ||
}, | ||
}; | ||
|
||
describe("serializeFormStateBody", () => { | ||
it("handles exploded form data parameters", async () => { | ||
const shape: HttpRequestBodyShape = { | ||
type: "formData", | ||
fields: [ | ||
{ | ||
type: "property", | ||
key: PropertyKey("tags"), | ||
description: undefined, | ||
availability: undefined, | ||
valueShape: STRING_VALUE_SHAPE, | ||
exploded: true, | ||
contentType: "application/json", | ||
}, | ||
], | ||
description: undefined, | ||
availability: undefined, | ||
}; | ||
|
||
const body: PlaygroundFormStateBody = { | ||
type: "form-data", | ||
value: { | ||
tags: { | ||
type: "json", | ||
value: ["tag1", "tag2", "tag3"], | ||
}, | ||
}, | ||
}; | ||
|
||
const result = await serializeFormStateBody(shape, body, true); | ||
|
||
expect(result).toEqual({ | ||
type: "form-data", | ||
value: { | ||
tags: { | ||
type: "exploded", | ||
value: ["tag1", "tag2", "tag3"], | ||
contentType: "application/json", | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it("converts single value to array for exploded parameters", async () => { | ||
const shape: HttpRequestBodyShape = { | ||
type: "formData", | ||
fields: [ | ||
{ | ||
type: "property", | ||
key: PropertyKey("tag"), | ||
valueShape: STRING_VALUE_SHAPE, | ||
exploded: true, | ||
contentType: "application/json", | ||
description: undefined, | ||
availability: undefined, | ||
}, | ||
], | ||
description: undefined, | ||
availability: undefined, | ||
}; | ||
|
||
const body: PlaygroundFormStateBody = { | ||
type: "form-data", | ||
value: { | ||
tag: { | ||
type: "json", | ||
value: "single-tag", | ||
}, | ||
}, | ||
}; | ||
|
||
const result = await serializeFormStateBody(shape, body, true); | ||
|
||
expect(result).toEqual({ | ||
type: "form-data", | ||
value: { | ||
tag: { | ||
type: "exploded", | ||
value: ["single-tag"], | ||
contentType: "application/json", | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet!