diff --git a/.changeset/yellow-oranges-promise.md b/.changeset/yellow-oranges-promise.md new file mode 100644 index 00000000..4349efde --- /dev/null +++ b/.changeset/yellow-oranges-promise.md @@ -0,0 +1,5 @@ +--- +"counterfact": patch +--- + +reverted type change for .json() -- it had unintended consequences diff --git a/docs/usage.md b/docs/usage.md index dc32d638..2102ee7c 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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. diff --git a/src/server/types.d.ts b/src/server/types.d.ts index 9b10f35d..cc613b34 100644 --- a/src/server/types.d.ts +++ b/src/server/types.d.ts @@ -99,7 +99,7 @@ type GenericResponseBuilderInner< ? never : HeaderFunction; 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; @@ -107,7 +107,7 @@ type GenericResponseBuilderInner< ? never : RandomFunction; text: MaybeShortcut<"text/plain", Response>; - xml: MaybeShortcut<"application/xml" | "text/xml", Response>; + xml: MaybeShortcut<"application/xml", Response>; }>; type GenericResponseBuilder<