Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Make sure to use custom Description component so we have markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Aug 13, 2018
1 parent 858ec8e commit 9d2af0b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions example/swagger-files/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"type": "string",
"description": "This is a string with a description"
},
"string with markdown description": {
"type": "string",
"description": "This is a string with a **markdown** description: [link](ref:action-object)"
},
"string without description": {
"type": "string"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/api-explorer/__tests__/Params.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const React = require('react');
const { mount } = require('enzyme');
const extensions = require('@readme/oas-extensions');

const Description = require('../src/form-components/DescriptionField');

const createParams = require('../src/Params');

const Oas = require('../src/lib/Oas');
Expand Down Expand Up @@ -34,6 +36,15 @@ describe('form id attribute', () => {
});
});

test('should use custom description component', () => {
const params = mount(
<div>
<Params {...props} />
</div>,
);
expect(params.find(Description).length).toBe(1);
});

test('boolean should render as <select>', () => {
const params = mount(
<div>
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/api-explorer/src/Params.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const FileWidget = require('react-jsonschema-form/lib/components/widgets/FileWid
const DateTimeWidget = require('react-jsonschema-form/lib/components/widgets/DateTimeWidget')
.default;

// const DescriptionField = require('./form-components/DescriptionField');
const DescriptionField = require('./form-components/DescriptionField');
const createBaseInput = require('./form-components/BaseInput');
const createSelectWidget = require('./form-components/SelectWidget');
const createArrayField = require('./form-components/ArrayField');
Expand Down Expand Up @@ -63,7 +63,7 @@ function Params({
return onChange({ [schema.type]: form.formData });
}}
fields={{
// DescriptionField,
DescriptionField,
ArrayField,
SchemaField,
}}
Expand Down
10 changes: 5 additions & 5 deletions packages/api-explorer/src/form-components/DescriptionField.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Modified version of https://github.com/mozilla-services/react-jsonschema-form/blob/2d390f6e56d5c54e715c5daa8b0610be5c62e91e/src/components/fields/DescriptionField.js
// Modified version of https://github.com/mozilla-services/react-jsonschema-form/blob/aadbbe9701c4db9df761e86f0280e1ecafc509f8/src/components/fields/DescriptionField.js
const React = require('react');
const PropTypes = require('prop-types');

const markdown = require('../lib/markdown');

function DescriptionField(props) {
const { id, description } = props;
if (!description) {
// See #312: Ensure compatibility with old versions of React.
return null;
}

if (!description) return null;

if (typeof description === 'string') {
return (
<p
Expand All @@ -20,6 +19,7 @@ function DescriptionField(props) {
/>
);
}

return (
<div id={id} className="field-description">
{description}
Expand Down

0 comments on commit 9d2af0b

Please sign in to comment.