Packages

OpenAPI code generation for Gleam — parse specs, generate types, routes, clients, and React Query/SWR hooks

Current section

Files

Jump to
nori src nori@codegen@typescript@swr.erl
Raw

src/nori@codegen@typescript@swr.erl

-module(nori@codegen@typescript@swr).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/nori/codegen/typescript/swr.gleam").
-export([generate/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" SWR hooks generator.\n"
"\n"
" Generates `swr-hooks.generated.ts` from CodegenIR.\n"
).
-file("src/nori/codegen/typescript/swr.gleam", 9).
?DOC(" Generate SWR hooks code.\n").
-spec generate(nori@codegen@ir:codegen_i_r()) -> binary().
generate(Ir) ->
Header = <<"// Generated by nori - Do not edit manually"/utf8>>,
Context = nori@codegen@templates:ir_to_ts_swr_context(Ir),
Tmpl = nori@codegen@templates:load_template(
<<"templates"/utf8>>,
<<"typescript_swr"/utf8>>
),
Body = nori@codegen@templates:render(Tmpl, Context),
<<<<<<Header/binary, "\n\n"/utf8>>/binary, Body/binary>>/binary, "\n"/utf8>>.