Skip to content

Commit 336f5c1

Browse files
Remove schema from external schemas (#14)
* Remove schema from external schemas * test: add test for input schema duplicate
1 parent 6ebe4cb commit 336f5c1

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function SerializerSelector () {
1010
}
1111

1212
function responseSchemaCompiler (fjsOpts, { schema /* method, url, httpStatus */ }) {
13+
if (fjsOpts.schema && schema.$id && fjsOpts.schema[schema.$id]) {
14+
fjsOpts.schema = { ...fjsOpts.schema }
15+
delete fjsOpts.schema[schema.$id]
16+
}
1317
return fastJsonStringify(schema, fjsOpts)
1418
}
1519

test/duplicate-schema.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
const t = require('tap')
4+
const FjsCompiler = require('../index')
5+
6+
t.test('Use input schema duplicate in the externalSchemas', async t => {
7+
t.plan(1)
8+
const externalSchemas = {
9+
schema1: {
10+
$id: 'schema1',
11+
type: 'number'
12+
},
13+
schema2: {
14+
$id: 'schema2',
15+
type: 'string'
16+
}
17+
}
18+
19+
const factory = FjsCompiler()
20+
const compiler = factory(externalSchemas)
21+
22+
compiler({ schema: externalSchemas.schema1 })
23+
compiler({ schema: externalSchemas.schema2 })
24+
25+
t.pass()
26+
})

0 commit comments

Comments
 (0)