diff --git a/src/__fixtures__/default-schema.json b/src/__fixtures__/default-schema.json
index 4167fd7a..8cb3daf4 100644
--- a/src/__fixtures__/default-schema.json
+++ b/src/__fixtures__/default-schema.json
@@ -2,6 +2,11 @@
"title": "User",
"type": "object",
"properties": {
+ "profile_photo": {
+ "type": "string",
+ "contentMediaType": "application/octet-stream",
+ "description": "This is user's profile photo"
+ },
"name": {
"type": "string",
"const": "Constant name",
diff --git a/src/components/__tests__/SchemaRow.spec.tsx b/src/components/__tests__/SchemaRow.spec.tsx
index bd6351e2..65f71425 100644
--- a/src/components/__tests__/SchemaRow.spec.tsx
+++ b/src/components/__tests__/SchemaRow.spec.tsx
@@ -260,4 +260,33 @@ describe('SchemaRow component', () => {
});
});
});
+ describe('schema node with contentMediaType', () => {
+ let schema: JSONSchema4;
+
+ beforeEach(() => {
+ schema = {
+ type: 'object',
+ properties: {
+ profile_photo: {
+ type: 'string',
+ contentMediaType: 'application/octet-stream',
+ description: "This is user's profile photo",
+ },
+ },
+ };
+ });
+
+ it('should render correct type name for binary type', () => {
+ const tree = buildTree(schema);
+
+ const schemaNode = findNodeWithPath(tree, ['properties', 'profile_photo']);
+ if (!schemaNode) {
+ throw Error('Node not found, invalid configuration');
+ }
+ const wrapper = mount();
+ const spanWrapper = wrapper.find({ 'data-test': 'property-type' });
+ expect(spanWrapper.at(0).text()).toContain('string');
+ wrapper.unmount();
+ });
+ });
});
diff --git a/src/utils/getApplicableFormats.ts b/src/utils/getApplicableFormats.ts
index a4d49e92..b689c514 100644
--- a/src/utils/getApplicableFormats.ts
+++ b/src/utils/getApplicableFormats.ts
@@ -3,6 +3,19 @@ import { RegularNode, SchemaNodeKind } from '@stoplight/json-schema-tree';
import { COMMON_JSON_SCHEMA_AND_OAS_FORMATS } from '../consts';
export function getApplicableFormats(schemaNode: RegularNode): [type: SchemaNodeKind, format: string] | null {
+ // JSON Schema itself doesn't directly support defining binary data types.
+ // Within the http-spec repository, we address this limitation using
+ // OpenAPI features i.e. `contentMediaType: 'application/octet-stream'`.
+ // which is specific to OpenAPI and not supported by JSON Schema itself.
+
+ if (
+ schemaNode.fragment['contentMediaType'] === 'application/octet-stream' &&
+ schemaNode.types &&
+ schemaNode.types.length > 0
+ ) {
+ return [schemaNode.types[0], 'binary'];
+ }
+
if (schemaNode.format === null) {
return null;
}