Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
t: Traversal,
oai: OpenAPIObject,
p: PathItem,
): Parameter[] =>
t
.composePrism(
new Prism(
s =>
isReference(s)
? getParameterFromRef(oai, s.$ref.split("/")[3])
: some(s),
a => a,
),
)
.composePrism(
new Prism(
s =>
s.in === (header ? "header" : "query") && s.required ? some(s) : none,
a => a,
),
)
.composeGetter(new Getter(i => i))
.getAll(p)
.filter(a =>
a.schema ? !isNone(schemaPrism(oai).getOption(a.schema)) : false,
)
.map(b => ({
...b,
schema: b.schema
? isReference(b.schema)
? changeRef(b.schema)
: changeRefs(b.schema)
const internalGetParameter = (
t: Traversal,
vname: string,
pathItem: PathItem,
oas: OpenAPIObject,
) =>
t
.composePrism(new Prism(
i => isReference(i)
? discernName(getParameterFromRef(oas, refName(i)), vname)
: discernName(some(i), vname),
a => a,
))
.composeOptional(Optional.fromNullableProp()("schema"))
.composeGetter(identityGetter())
.getAll(pathItem);
import { Prism } from 'monocle-ts'
import { tryCatch } from 'fp-ts/lib/Either'
export type JSONObject = { [key: string]: JSONType }
export interface JSONArray extends Array {}
export type JSONType = null | string | number | boolean | JSONArray | JSONObject
export const StringJSONPrism = new Prism(
s => tryCatch(() => JSON.parse(s)).toOption(),
a => JSON.stringify(a)
)
import { Prism } from 'monocle-ts'
import { some, none } from 'fp-ts/lib/Option'
export const AnyStringPrism = new Prism(s => (typeof s === 'string' ? some(s) : none), a => a)
export function prism<s>(predicate: Predicate>): Prism, S> {
return new Prism(s => (predicate(s) ? some(s) : none), identity)
}
</s>
import { Prism } from 'monocle-ts'
import { some, none } from 'fp-ts/lib/Option'
export const AnyNumberPrism = new Prism(s => (typeof s === 'number' ? some(s) : none), a => a)
export function get(codec: t.Type): Prism {
return new Prism(s => fromEither(codec.decode(s)), codec.encode)
}
const rejectOptionals = (i: IExtendedObjectType): ITameExtendedObjectType =>
new Iso<
IExtendedObjectType,
Array<[string, ExtendedValueType | IMaybeJSONValue]>
>(
a => Object.entries(a),
q => q.reduce((a, b) => ({ ...a, [b[0]]: b[1] }), {}),
)
.composeTraversal(fromTraversable(array)())
.composePrism(
new Prism<
[string, ExtendedValueType | IMaybeJSONValue],
[string, ExtendedValueType]
>(
a =>
((
q: string,
r: ExtendedValueType | IMaybeJSONValue,
): Option<[string, ExtendedValueType]> =>
MaybeJSONValue.is(r) ? none : some([q, r]))(a[0], a[1]),
a => a,
),
)
.composeGetter(identityGetter())
.getAll(i)
.reduce((a, b) => ({ ...a, [b[0]]: b[1] }), {});