Sign in

    moonbitstack/moonapi/endpoint does not have a README file

    Endpoint

    pub(all) struct Endpoint {
    params : Array[Param]
    request_body :
    Schema
    ?
    request_required : Bool
    responses : Array[ResponseSpec]
    } derive(Eq)

    The runtime endpoint descriptor a route can carry — the one first-class value that replaces FastAPI reading a handler's signature. Walked once for the OpenAPI operation (parameters + requestBody + responses, with every named object hoisted into components/schemas) and for request validation.

    Endpoint::equal

    fn Endpoint::equal(Endpoint, Endpoint) -> Bool

    Endpoint::new

    fn Endpoint::new(params? : Array[Param], request_body? :
    Schema
    , request_required? : Bool, responses? : Array[ResponseSpec]) -> Endpoint

    Build an endpoint descriptor. Everything is optional: a bare Endpoint::new() describes an endpoint with no parameters, no body, and (on emit) a default 200 OK response.

    Endpoint::not_equal

    fn Endpoint::not_equal(x : Endpoint, y : Endpoint) -> Bool

    Endpoint::validate

    Validate an inbound request ctx against this endpoint descriptor: every declared parameter (path / query / header / cookie) plus the JSON request body, all off the same descriptor tree that emits the OpenAPI operation. Returns the accumulated errors — an empty array means the request conforms, otherwise pass them to unprocessable for a FastAPI-shaped 422.

    Param

    pub(all) struct Param {
    name : String
    loc : ParamLoc
    schema :
    Schema

    required : Bool
    description : String
    constraints : Array[
    Constraint
    ]
    default : Json?
    alias_ : String
    } derive(Eq)

    A single request parameter descriptor: its name, location, scalar schema, whether it is required, an optional description, its value constraints, the default that stands in when the request omits it, and the alias it travels under on the wire. Path parameters are always required (OpenAPI requires it); the constructor keeps the caller's value but validation treats path params as mandatory.

    Param::equal

    fn Param::equal(Param, Param) -> Bool

    Param::is_required

    fn Param::is_required(self : Param) -> Bool

    Whether a request must carry this parameter. One with a default never must — its absence is answered by the default, exactly as a Python default argument is.

    Param::key

    fn Param::key(self : Param) -> String

    The name this parameter travels under: its alias when it has one, else its own name. This is what is read off the request, what the document calls it, and what a validation error's loc points at — all three being the client's view of the parameter.

    Param::new

    fn Param::new(name : String, loc : ParamLoc, schema? :
    Schema
    , required? : Bool, description? : String, constraints? : Array[
    Constraint
    ], default? : Json, alias_? : String) -> Param

    Build a parameter descriptor. schema defaults to a string and required to true. constraints are the Pydantic-style bounds FastAPI reads off a Query(ge=…, max_length=…) — emitted into the parameter's documented schema and enforced on the inbound value. default is emitted and makes the parameter optional, since a value that has one is never missing. alias is the name the parameter travels under when that differs from the one the code calls it (← Query(alias="item-query")).

    Param::not_equal

    fn Param::not_equal(x : Param, y : Param) -> Bool

    ParamLoc

    pub(all) enum ParamLoc {
    InPath
    InQuery
    InHeader
    InCookie
    } derive(Eq)

    Where a parameter is carried, the OpenAPI in locations: the path, the query string, a header, or a cookie.

    ParamLoc::equal

    fn ParamLoc::equal(ParamLoc, ParamLoc) -> Bool

    ParamLoc::not_equal

    fn ParamLoc::not_equal(x : ParamLoc, y : ParamLoc) -> Bool

    ResponseSpec

    pub(all) struct ResponseSpec {
    status : Int
    description : String
    body :
    Schema
    ?
    } derive(Eq)

    A single response descriptor: the HTTP status, a human description, and an optional body schema (None for an empty body, e.g. 204).

    ResponseSpec::equal

    ResponseSpec::new

    fn ResponseSpec::new(status : Int, description? : String, body? :
    Schema
    ) -> ResponseSpec

    Build a response descriptor. description defaults to "OK" and there is no body unless one is given.

    ResponseSpec::not_equal

    fn ResponseSpec::not_equal(x : ResponseSpec, y : ResponseSpec) -> Bool

    loc_str

    fn loc_str(l : ParamLoc) -> String

    The OpenAPI in string for a location.