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

Commit

Permalink
Make sure manual examples are shown even if x-samples-enabled: false
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Aug 17, 2018
1 parent 47326f5 commit dbca3a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/api-explorer/__tests__/CodeSample.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ describe('code examples', () => {
expect(codeSample.find('pre.tomorrow-night.tabber-body').length).toBe(1);
});

test('should display custom examples even if SAMPLES_ENABLED is false', () => {
const docProps = {
setLanguage: () => {},
operation: new Operation({}, '/pet/{id}', 'get'),
language: 'node',
examples: [
{
language: 'javascript',
code: 'console.log(1);',
},
],
};
const codeSample = shallow(
<CodeSample
{...docProps}
oas={
new Oas({
[extensions.SAMPLES_ENABLED]: false,
servers: [{ url: 'http://example.com' }],
})
}
/>,
);

expect(codeSample.find('.code-sample-body').length).toBe(1);
expect(codeSample.find('pre.tomorrow-night.tabber-body').length).toBe(1);
});

test('should not error if no code given', () => {
const docProps = {
setLanguage: () => {},
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/src/CodeSample.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class CodeSample extends React.Component {
return (
<div className="code-sample tabber-parent">
{(() => {
if (examples.length) return this.renderExamples(examples, setLanguage);
if (!oas[extensions.SAMPLES_ENABLED]) {
return <div className="hub-no-code">No code samples available</div>;
}
if (examples.length) return this.renderExamples(examples, setLanguage);
const { snippet, code } = generateCodeSnippet(oas, operation, formData, language);
return (
<div>
Expand Down

0 comments on commit dbca3a5

Please sign in to comment.