moonbitstack/moonctl/gen does not have a README file

    TemplateFile

    pub(all) struct TemplateFile {
    path : String
    text : String
    }

    One file of a template directory: where it sits relative to the directory's root, and what is in it. Both are templates over the spec.

    binders_parse_text

    fn binders_parse_text(spec :
    Spec
    ) -> Bool

    Whether any binder reads a value out of text, which is what moonbitlang/core/string is imported for. A spec whose request fields are all text or all in the body needs none of it, and an unused import fails moon check in a generated project.

    bound_types

    The request types spec's routes declare, in the order they first appear, each with its fields — the types a binder is written for. A route naming a type the spec never declares is left out: there is nothing to build.

    generate

    fn generate(spec :
    Spec
    , template? : String) -> String raise
    Refused

    Generate compilable moonapi scaffolding from a spec: a MoonBit struct for every type block, a build_app that wires every route to its handler, plus a stub for each handler. The routing part depends only on moonbitstack/moonapi and moonbitstack/moonasgi; the emitted schemas are dependency-free.

    Pass template to render the spec through the runtime template engine (see generate_with) instead of the built-in generator; omit it for the default scaffold.

    generate_builtin

    fn generate_builtin(spec :
    Spec
    ) -> String

    generate_with

    fn generate_with(spec :
    Spec
    , template_source : String) -> String raise
    Refused

    Generate code from a Spec with a caller-supplied template instead of the built-in generator — the runtime-template path goctl exposes for custom scaffolds. Equivalent to render(template_source, spec_to_value(spec)).

    group_note

    fn group_note(g :
    Group
    ) -> String

    A group's annotations spelled the way the spec wrote them, e.g. group: user,prefix: /api/v1, middleware: Log. Empty for a group that carries nothing.

    number_json

    fn number_json(raw : String) ->
    Json

    raw as a JSON number, or as a string when it does not read as one — a tag option is text until something asks it to be a number.

    render_binder

    fn render_binder(name : String, fields : Array[
    Field
    ]) -> String

    bind_<type> for one request type: read every field from the place its tag names, then build the struct. A field bound from the body and one bound from the path are read the same way the request puts them there, so a request whose body and path disagree takes each value from where its tag says.

    render_binders

    fn render_binders(spec :
    Spec
    ) -> String

    Every binder spec needs, with the helpers they read through, as the internal/types package's generated source tail. Empty when no route declares a request type.

    render_structs

    fn render_structs(types : Array[
    TypeDef
    ], derive_json? : Bool) -> String

    A MoonBit struct for every type block, in the order the spec declared them, each followed by whatever its tags asked to be checked (see render_checks).

    render_template_dir

    fn render_template_dir(spec :
    Spec
    , files : Array[TemplateFile]) -> Array[(String, String)] raise
    Refused

    Render every file of a template directory. The result is in the order the caller listed them, so a file that has to exist first (a moon.mod) can be put first.

    render_template_file

    fn render_template_file(spec :
    Spec
    , t : TemplateFile) -> (String, String) raise
    Refused

    Render t's path and text over spec, returning the file to write. A path is rendered like any other template, so {{.service}}/moon.mod becomes greet/moon.mod.

    route_path

    fn route_path(path : String) -> String

    A spec path as the route template moonapi reads: each :name segment of the spec becomes {name}.

    spec_to_value

    Expose a parsed .api Spec as template Value data: a Dict with service (string), services (list of {name, routes}), routes (list of {verb, path, route, handler, summary, hasSummary, group, hasGroup, req, resp,hasReq, hasResp}, where route is path as the framework spells it), types (list of {name, fields:[{name,type}]}), groups (list of the @server blocks) and hasTypes (bool). This is what the template-driven generator ranges over.