Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
serializeDocument => (
documents: Dictionary,
options: SerializeOptions = {},
): Either =>
pipe(
documents,
record.collect(serializeDocument),
sequenceEither,
either.map(e =>
mapFS(fragment(e), content => format(content, options.prettierConfig || defaultPrettierConfig)),
),
),
);
option.map(properties =>
pipe(
properties,
record.collect((name, value) => {
const isRequired = pipe(
schema.required,
option.map(includes(name)),
option.getOrElse(constFalse),
);
return pipe(
serializeSchemaObjectWithRecursion(from, value, false),
either.map(getSerializedOptionPropertyType(name, isRequired)),
);
}),
sequenceEither,
either.map(s => intercalateSerializedTypes(serializedType(';', ',', [], []), s)),
either.map(getSerializedObjectType(from.name)),
either.map(getSerializedRecursiveType(from, shouldTrackRecursion)),
),
),
export const serializeResponsesDefinitionsObject = (
from: Ref,
responsesDefinitionsObject: ResponsesDefinitionsObject,
): Either =>
pipe(
responsesDefinitionsObject,
record.collect((name, parameterObject) =>
pipe(
from,
addPathParts(name),
either.chain(from => serializeResponse(from, parameterObject)),
),
),
sequenceEither,
either.map(content => directory('responses', content)),
);
ReferenceObjectCodec.is(r)
? pipe(
fromString(r.$ref),
either.mapLeft(
() => new Error(`Invalid ${r.$ref} for ResponsesObject'c code "${code}"`),
),
either.map(getSerializedRefType(from)),
some,
)
: serializeResponseObject(from, r),
),
),
),
array.compact,
sequenceEither,
either.map(uniqSerializedTypesByTypeAndIO),
);
return pipe(
serializedResponses,
either.map(serializedResponses => {
if (serializedResponses.length === 0) {
return SERIALIZED_VOID_TYPE;
}
const combined = intercalateSerializedTypes(serializedType('|', ',', [], []), serializedResponses);
const isUnion = serializedResponses.length > 1;
return serializedType(
combined.type,
isUnion ? `union([${combined.io}])` : combined.io,
concatIfL(isUnion, combined.dependencies, () => [serializedDependency('union', 'io-ts')]),
[],
);
}),
either.chain(schema => {
if (ReferenceObjectCodec.is(schema)) {
return pipe(fromString(schema.$ref), either.map(getSerializedRefType(from)));
} else {
return pipe(schema, serializeSchemaObject(from));
}
}),
either.map(fromSerializedType(isRequired(parameterObject))),
import { fromString } from '../../../../utils/ref';
import { pipe } from 'fp-ts/lib/pipeable';
import { either } from 'fp-ts';
import { fromRef } from '../../../../utils/fs';
export const utilsRef = fromString('#/utils/utils');
const utils = `
`;
export const utilsFile = pipe(
utilsRef,
either.map(ref => fromRef(ref, '.ts', utils)),
);
}
switch (schemaObject.type) {
case 'string':
case 'boolean':
case 'integer':
case 'number': {
return serializePrimitive(from, schemaObject);
}
case 'array': {
const { items } = schemaObject;
const serialized = ReferenceObjectCodec.is(items)
? pipe(
fromString(items.$ref),
mapLeft(() => new Error(`Unable to serialize SchemaObjeft array items ref "${items.$ref}"`)),
either.map(getSerializedRefType(from)),
)
: pipe(items, serializeSchemaObjectWithRecursion(from, false, undefined));
return pipe(serialized, either.map(getSerializedArrayType(name)));
}
case 'object': {
const additionalProperties = pipe(
schemaObject.additionalProperties,
option.filter(isAllowedAdditionalProperties),
option.map(additionalProperties => {
if (ReferenceObjectCodec.is(additionalProperties)) {
return pipe(
additionalProperties.$ref,
fromString,
mapLeft(
() =>
new Error(
option.map(fills =>
pipe(
fills,
nonEmptyArray.map(fill => serializeGradient(fill.gradient)),
nonEmptyArray.nonEmptyArray.sequence(either.either),
either.map(gradients => `backgroundImage: '${gradients.join(', ')}'`),
),
),
option.map(includes(name)),
option.getOrElse(constFalse),
);
if (ReferenceObjectCodec.is(property)) {
return pipe(
property.$ref,
fromString,
mapLeft(
() =>
new Error(
`Unable to serialize SchemaObject property "${name}" ref "${property.$ref}"`,
),
),
either.map(getSerializedRefType(from)),
either.map(getSerializedOptionPropertyType(name, isRequired)),
);
} else {
return pipe(
property,
serializeSchemaObjectWithRecursion(from, false, undefined),
either.map(getSerializedOptionPropertyType(name, isRequired)),
);
}
}),
sequenceEither,
export const serializeDefinitions = (from: Ref, definitions: DefinitionsObject): Either =>
pipe(
definitions,
record.collect((name, definition) =>
pipe(
from,
addPathParts(name),
either.chain(from => serializeDefinition(from, name, definition)),
),
),
sequenceEither,
either.map(serialized => directory(DEFINITIONS_DIRECTORY, serialized)),
);