UNPKG

swagger-client

Version:

SwaggerJS - a collection of interfaces for OAI specs

24 lines (23 loc) 565 B
/* Serializer that serializes according to a media type instead of OpenAPI's `style` + `explode` constructs. */ export default function serialize(value, mediaType) { if (mediaType.includes('application/json')) { if (typeof value === 'string') { // Assume the user has a JSON string return value; } if (Array.isArray(value)) { value = value.map(v => { try { return JSON.parse(v); } catch (e) { return v; } }); } return JSON.stringify(value); } return String(value); }