Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/__fixtures__/default-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions src/components/__tests__/SchemaRow.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<SchemaRow schemaNode={schemaNode} nestingLevel={0} />);
const spanWrapper = wrapper.find({ 'data-test': 'property-type' });
expect(spanWrapper.at(0).text()).toContain('string<binary>');
wrapper.unmount();
});
});
});
13 changes: 13 additions & 0 deletions src/utils/getApplicableFormats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down