Beispiel #1
0
 def _internal_get_component(
     o: OpenAPIObject, i: Union[C, Reference]
 ) -> Optional[C]:
     return (
         (f(o, ref_name(i)) if isinstance(i, Reference) else i)
         if i is not None
         else None
     )
Beispiel #2
0
def schema_prism(oai: OpenAPIObject) -> lenses.ui.BaseUiLens[S, T, X, Y]:
    return lens.Prism(
        lambda s: get_schema_from_ref(oai, ref_name(s))
        if isinstance(s, Reference)
        else s,
        lambda a: a,
        ignore_none=True,
    )
Beispiel #3
0
def internal_get_parameter_schemas(
    t: lenses.ui.BaseUiLens[S, T, X, Y],
    vname: str,
    path_item: PathItem,
    oas: OpenAPIObject,
) -> Sequence[Schema]:
    return (
        t.Prism(
            lambda i: discern_name(get_parameter_from_ref(oas, ref_name(i)), vname)
            if isinstance(i, Reference)
            else discern_name(i, vname),
            lambda a: a,
            ignore_none=True,
        )
        .add_lens(schema_o)
        .collect()(path_item)
    )
Beispiel #4
0
def get_required_request_query_or_header_parameters_internal(
    header: bool, l: lenses.ui.BaseUiLens[S, T, X, Y], oai: OpenAPIObject, p: PathItem
) -> Sequence[Parameter]:
    # TODO: really dirty cast
    # is this even the case
    # copied from unmock, but need to investigate
    return [
        replace(
            parameter,
            name=parameter.name if not header else parameter.name.lower(),
            schema=change_ref(parameter.schema)
            if isinstance(parameter.schema, Reference)
            else change_refs(parameter.schema)
            if parameter.schema is not None
            else Schema(_type="string"),
        )
        for parameter in l.Prism(
            lambda s: get_parameter_from_ref(oai, ref_name(s))
            if isinstance(s, Reference)
            else s,
            lambda a: a,
            ignore_none=True,
        )
        .Prism(
            lambda s: s
            if (s._in == ("header" if header else "query")) and s.required
            else None,
            lambda a: a,
            ignore_none=True,
        )
        .collect()(p)
        if parameter.schema is not None
        and (
            len(lens.Each().add_lens(schema_prism(oai)).collect()([parameter.schema]))
            > 0
        )
    ]
def test_ref_name():
    assert "Foo" == ref_name(Reference(_ref="#/components/schemas/Foo", _x=None))