Skip to content

Commit

Permalink
Merge pull request #924 from pmcelhaney/that-alternation-didnt-work
Browse files Browse the repository at this point in the history
revert a type change that made things worse
  • Loading branch information
pmcelhaney authored May 29, 2024
2 parents 10c02d2 + 9e285a5 commit a279081
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-oranges-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"counterfact": patch
---

reverted type change for .json() -- it had unintended consequences
7 changes: 4 additions & 3 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ The `$.response` object is used to build a valid response for the URL and reques
- `.random()` returns random data, using `examples` and other metadata from the OpenAPI document.
- `.header(name, value)` adds a response header. It will only show up when a response header is expected and you haven't already provided it.
- `.match(contentType, content)` is used to return content which matches the content type. If the API is intended to serve one of multiple content types, depending on the client's `Accepts:` header, you can chain multiple `match()` calls.
- `.json(content)`, `.text(content)`, `.html(content)`, and `.xml(content)` are shorthands for the `match()` function, e.g. `.text(content)` is shorthand for `.match("text/plain", content)`.
- if the content type is XML, you can pass a JSON object, and Counterfact will automatically convert it to XML for you
- The `.json()` shortcut handles both JSON and XML.
- `.json(content)` is shorthand for `.match("application/json", content)`
- `.text(content)` is shorthand for `.match("text/plain", content)`
- `.html(content)` is shorthand for `.match("text/html", content)`
- `.xml(content)` is shorthand for `.match("application/xml", content)`

You can build a response by chaining one or more of these functions, e.g.

Expand Down
4 changes: 2 additions & 2 deletions src/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ type GenericResponseBuilderInner<
? never
: HeaderFunction<Response>;
html: MaybeShortcut<"text/html", Response>;
json: MaybeShortcut<"application/json" | "text/json" | "text/x-json" | "application/xml" | "text/xml", Response>;
json: MaybeShortcut<"application/json", Response>;
match: [keyof Response["content"]] extends [never]
? never
: MatchFunction<Response>;
random: [keyof Response["content"]] extends [never]
? never
: RandomFunction<Response>;
text: MaybeShortcut<"text/plain", Response>;
xml: MaybeShortcut<"application/xml" | "text/xml", Response>;
xml: MaybeShortcut<"application/xml", Response>;
}>;

type GenericResponseBuilder<
Expand Down

0 comments on commit a279081

Please sign in to comment.