Skip to content

Commit ab5a922

Browse files
feat(cli): add support for vendor-specific JSON content types in example validation (#11114)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent da53801 commit ab5a922

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/cli/cli/versions.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# yaml-language-server: $schema=../../../fern-versions-yml.schema.json
2+
- changelogEntry:
3+
- summary: |
4+
Add support for vendor-specific JSON content types in example validation. Content types like `application/vnd.bc.v1+json` are now accepted as valid JSON content types when validating examples against `literal<"application/json">` types.
5+
type: feat
6+
irVersion: 63
7+
createdAt: "2025-12-09"
8+
version: 3.5.0
9+
210
- changelogEntry:
311
- summary: |
412
Fix parsing of `<Code>` components with `for` attribute for synced tabs. The `for` attribute is now properly preserved when converting `<Code>` components to markdown code blocks, allowing synced tabs to work correctly across multiple `<CodeGroup>` sections.

packages/cli/generation/ir-generator/src/examples/validateTypeReferenceExample.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FernWorkspace } from "@fern-api/api-workspace-commons";
2-
import { assertNever, getDuplicates, isPlainObject } from "@fern-api/core-utils";
2+
import { assertNever, getDuplicates, isPlainObject, MediaType } from "@fern-api/core-utils";
33
import { EXAMPLE_REFERENCE_PREFIX, RawSchemas, visitRawTypeReference } from "@fern-api/fern-definition-schema";
44
import {
55
DoubleValidationRules,
@@ -243,7 +243,7 @@ export function validateTypeReferenceExample({
243243
)(example);
244244
case "string":
245245
return createValidator(
246-
(e) => e === expectedLiteral.string,
246+
(e) => e === expectedLiteral.string || areMediaTypesCompatible(expectedLiteral.string, e),
247247
`"${expectedLiteral.string}"`
248248
)(example);
249249
default:
@@ -557,3 +557,22 @@ function areLiteralTypesEquivalent({ expected, actual }: { expected: Literal; ac
557557
assertNever(expected);
558558
}
559559
}
560+
561+
function areMediaTypesCompatible(expected: string, example: RawSchemas.ExampleTypeReferenceSchema): boolean {
562+
if (typeof example !== "string") {
563+
return false;
564+
}
565+
566+
const expectedMediaType = MediaType.parse(expected);
567+
const exampleMediaType = MediaType.parse(example);
568+
569+
if (expectedMediaType == null || exampleMediaType == null) {
570+
return false;
571+
}
572+
573+
if (expectedMediaType.isJSON() && exampleMediaType.isJSON()) {
574+
return true;
575+
}
576+
577+
return false;
578+
}

0 commit comments

Comments
 (0)