You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					24 lines
				
				809 B
			
		
		
			
		
	
	
					24 lines
				
				809 B
			| 
								 
											3 years ago
										 
									 | 
							
								'use strict'
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								const fastJsonStringify = require('fast-json-stringify')
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								function SerializerSelector () {
							 | 
						||
| 
								 | 
							
								  return function buildSerializerFactory (externalSchemas, serializerOpts) {
							 | 
						||
| 
								 | 
							
								    const fjsOpts = Object.assign({}, serializerOpts, { schema: externalSchemas })
							 | 
						||
| 
								 | 
							
								    return responseSchemaCompiler.bind(null, fjsOpts)
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								function responseSchemaCompiler (fjsOpts, { schema /* method, url, httpStatus */ }) {
							 | 
						||
| 
								 | 
							
								  if (fjsOpts.schema && schema.$id && fjsOpts.schema[schema.$id]) {
							 | 
						||
| 
								 | 
							
								    fjsOpts.schema = { ...fjsOpts.schema }
							 | 
						||
| 
								 | 
							
								    delete fjsOpts.schema[schema.$id]
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return fastJsonStringify(schema, fjsOpts)
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.exports = SerializerSelector
							 | 
						||
| 
								 | 
							
								module.exports.default = SerializerSelector
							 | 
						||
| 
								 | 
							
								module.exports.SerializerSelector = SerializerSelector
							 | 
						||
| 
								 | 
							
								module.exports.StandaloneSerializer = require('./standalone')
							 |