diff --git a/.changeset/twelve-actors-tell.md b/.changeset/twelve-actors-tell.md new file mode 100644 index 0000000000..d02ddb6de5 --- /dev/null +++ b/.changeset/twelve-actors-tell.md @@ -0,0 +1,6 @@ +--- +"@redocly/respect-core": patch +"@redocly/cli": patch +--- + +Corrected an issue where `Respect` did not properly JSON-encode request bodies for custom content-types containing numbers. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed22b086c3..bffa95e152 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -281,6 +281,7 @@ npm i -g redocly-cli.tgz (cd tests/smoke/basic/ && redocly build-docs openapi.yaml -o pre-built/redoc.html) ``` +Don't forget to visually check the [changes](tests/smoke/basic/pre-built/redoc.html) in browser. For other commands you'd have to do something similar. ### Performance benchmark diff --git a/packages/respect-core/src/utils/__tests__/api-fetcher.test.ts b/packages/respect-core/src/utils/__tests__/api-fetcher.test.ts index 6302175689..ef4f63aa9e 100644 --- a/packages/respect-core/src/utils/__tests__/api-fetcher.test.ts +++ b/packages/respect-core/src/utils/__tests__/api-fetcher.test.ts @@ -32,7 +32,7 @@ describe('normalizeHeaders', () => { }); describe('isJsonContentType', () => { - it('should return true if json mime type', () => { + it('should return true if json content type', () => { const result = isJsonContentType('application/json'); expect(result).toEqual(true); }); @@ -42,10 +42,15 @@ describe('isJsonContentType', () => { expect(result).toEqual(true); }); - it('should return false if not json mime type', () => { + it('should return false if not json content type', () => { const result = isJsonContentType('application/xml'); expect(result).toEqual(false); }); + + it('should return true if json content type with numbers', () => { + const result = isJsonContentType('application/ast.some.test.value-3v3.info+json'); + expect(result).toEqual(true); + }); }); describe('isXmlContentType', () => { diff --git a/packages/respect-core/src/utils/api-fetcher.ts b/packages/respect-core/src/utils/api-fetcher.ts index 7709526ff8..9d02e310e1 100644 --- a/packages/respect-core/src/utils/api-fetcher.ts +++ b/packages/respect-core/src/utils/api-fetcher.ts @@ -49,7 +49,7 @@ export function normalizeHeaders(headers: Record | undefined) { } export function isJsonContentType(contentType: string) { - return /^application\/([a-z.-]+\+)?json$/.test(contentType); + return /^application\/([a-z0-9.-]+\+)?json$/.test(contentType); } export function isXmlContentType(contentType: string) { diff --git a/tests/smoke/basic/pre-built/redoc.html b/tests/smoke/basic/pre-built/redoc.html index 838db49617..cf5300b5ba 100644 --- a/tests/smoke/basic/pre-built/redoc.html +++ b/tests/smoke/basic/pre-built/redoc.html @@ -12,284 +12,284 @@ margin: 0; } - -

Sample API (1.0.0)

Download OpenAPI specification:

Get a greeting message

Responses

Response samples

Content type
application/json
{
  • "message": "string"
}
+ " fill="currentColor">

Sample API (1.0.0)

Download OpenAPI specification:

Get a greeting message

Responses

Response samples

Content type
application/json
{
  • "message": "string"
}