Skip to content

Commit 1ee0521

Browse files
fix(respect): issue with json encoding for custom content-type (#2490)
1 parent d8c71f8 commit 1ee0521

5 files changed

Lines changed: 292 additions & 280 deletions

File tree

.changeset/twelve-actors-tell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/respect-core": patch
3+
"@redocly/cli": patch
4+
---
5+
6+
Corrected an issue where `Respect` did not properly JSON-encode request bodies for custom content-types containing numbers.

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ npm i -g redocly-cli.tgz
281281
(cd tests/smoke/basic/ && redocly build-docs openapi.yaml -o pre-built/redoc.html)
282282
```
283283

284+
Don't forget to visually check the [changes](tests/smoke/basic/pre-built/redoc.html) in browser.
284285
For other commands you'd have to do something similar.
285286

286287
### Performance benchmark

packages/respect-core/src/utils/__tests__/api-fetcher.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('normalizeHeaders', () => {
3232
});
3333

3434
describe('isJsonContentType', () => {
35-
it('should return true if json mime type', () => {
35+
it('should return true if json content type', () => {
3636
const result = isJsonContentType('application/json');
3737
expect(result).toEqual(true);
3838
});
@@ -42,10 +42,15 @@ describe('isJsonContentType', () => {
4242
expect(result).toEqual(true);
4343
});
4444

45-
it('should return false if not json mime type', () => {
45+
it('should return false if not json content type', () => {
4646
const result = isJsonContentType('application/xml');
4747
expect(result).toEqual(false);
4848
});
49+
50+
it('should return true if json content type with numbers', () => {
51+
const result = isJsonContentType('application/ast.some.test.value-3v3.info+json');
52+
expect(result).toEqual(true);
53+
});
4954
});
5055

5156
describe('isXmlContentType', () => {

packages/respect-core/src/utils/api-fetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function normalizeHeaders(headers: Record<string, string> | undefined) {
4949
}
5050

5151
export function isJsonContentType(contentType: string) {
52-
return /^application\/([a-z.-]+\+)?json$/.test(contentType);
52+
return /^application\/([a-z0-9.-]+\+)?json$/.test(contentType);
5353
}
5454

5555
export function isXmlContentType(contentType: string) {

0 commit comments

Comments
 (0)