Skip to content

Commit 5abd4a7

Browse files
committed
change exports structure
1 parent 8efa487 commit 5abd4a7

11 files changed

+29
-58
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ lib-cov
1212

1313
# dist
1414
dist/
15+
tmp/
1516

1617
# Coverage directory used by tools like istanbul
1718
coverage

gulp-tasks/build.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import config from './config';
99
const $ = global.$;
1010

1111
function build() {
12-
return browserify({ entries: [path.join('src', config.entryFileName + '.js')] })
12+
return browserify({
13+
standalone: 'OpenAPISampler',
14+
entries: [path.join('src', config.entryFileName + '.js')]
15+
})
1316
.transform('babelify', {presets: ['es2015']})
1417
.bundle()
1518
.pipe(source(config.exportFileName + '.js'))

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="dist/openapi-sampler.js"> </script>

karma.conf.js

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ module.exports = function (config) {
4040
]
4141
},
4242
files: [
43-
'./test/setup/browser.js',
4443
'./dist/openapi-sampler.js',
4544
'node_modules/babel-polyfill/dist/polyfill.js',
4645
'test/**/*.spec.js'

package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi-sampler",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Tool for generation samples based on OpenAPI payload/response schema",
55
"main": "dist/openapi-sampler.js",
66
"jsnext:main": "src/openapi-sampler.js",
@@ -77,9 +77,5 @@
7777
"vinyl-buffer": "^1.0.0",
7878
"vinyl-source-stream": "^1.1.0",
7979
"watchify": "^3.7.0"
80-
},
81-
"babelBoilerplateOptions": {
82-
"entryFileName": "openapi-sampler.js",
83-
"mainVarName": "OpenAPISampler"
8480
}
8581
}

src/openapi-sampler.js

+13-19
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@ import { traverse } from './traverse';
22
import { sampleArray, sampleBoolean, sampleNumber, sampleObject, sampleString} from './samplers/index';
33
import { normalize } from './normalize';
44

5-
const OpenAPISampler = {
6-
7-
sample(schema) {
8-
normalize(schema);
9-
return traverse(schema);
10-
},
11-
12-
_registerSampler(type, sampler) {
13-
OpenAPISampler._samplers[type] = sampler;
14-
},
15-
16-
_samplers: {}
5+
export var _samplers = {};
176

7+
export function sample(schema) {
8+
normalize(schema);
9+
return traverse(schema);
1810
};
1911

20-
OpenAPISampler._registerSampler('array', sampleArray);
21-
OpenAPISampler._registerSampler('boolean', sampleBoolean);
22-
OpenAPISampler._registerSampler('integer', sampleNumber);
23-
OpenAPISampler._registerSampler('number', sampleNumber);
24-
OpenAPISampler._registerSampler('object', sampleObject);
25-
OpenAPISampler._registerSampler('string', sampleString);
12+
export function _registerSampler(type, sampler) {
13+
_samplers[type] = sampler;
14+
};
2615

27-
export default OpenAPISampler;
16+
_registerSampler('array', sampleArray);
17+
_registerSampler('boolean', sampleBoolean);
18+
_registerSampler('integer', sampleNumber);
19+
_registerSampler('number', sampleNumber);
20+
_registerSampler('object', sampleObject);
21+
_registerSampler('string', sampleString);

src/samplers/string.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function defaultSample(min, max) {
4545
}
4646

4747
function ipv4Sample() {
48-
return '192.168.0.1'
48+
return '192.168.0.1';
4949
}
5050

5151
const stringFormats = {

src/traverse.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import OpenAPISampler from './openapi-sampler';
1+
import { _samplers } from './openapi-sampler';
22

33
export function traverse(schema) {
44
if (schema.example) {
@@ -14,7 +14,7 @@ export function traverse(schema) {
1414
}
1515

1616
let type = schema.type;
17-
let sampler = OpenAPISampler._samplers[type];
17+
let sampler = _samplers[type];
1818
if (sampler) return sampler(schema);
1919
return {};
2020
}

test/runner.html

-28
This file was deleted.

test/setup/setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = function(root) {
22
root = root ? root : global;
33
root.expect = root.chai.expect;
4-
var OpenAPISampler = require('../../src/openapi-sampler').default;
4+
var OpenAPISampler = require('../../src/openapi-sampler');
55
beforeEach(function() {
66
// Using these globally-available Sinon features is preferrable, as they're
77
// automatically restored for you in the subsequent `afterEach`

test/unit/string.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ describe('sampleString', () => {
5757
res = () => sampleString({format: 'date-time', minLength: 100});
5858
expect(res).to.throw();
5959
});
60+
61+
it('should return ip for ipv4 format', () => {
62+
res = sampleString({format: 'ipv4'});
63+
expect(res).to.equal('192.168.0.1');
64+
});
6065
});

0 commit comments

Comments
 (0)