-module(nori@reference). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/nori/reference.gleam"). -export([to_inline/1, is_reference/1, is_inline/1, get_ref/1, map/2, flat_map/2]). -export_type([ref/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( " Reference handling for OpenAPI specifications.\n" "\n" " OpenAPI allows objects to be defined inline or referenced via JSON Reference ($ref).\n" " This module provides the generic `Ref` type to handle both cases uniformly.\n" ). -type ref(LQQ) :: {inline, LQQ} | {reference, binary()}. -file("src/nori/reference.gleam", 28). ?DOC(" Extracts the value from a `Ref` if it's inline, returns `Error` if it's a reference.\n"). -spec to_inline(ref(LQR)) -> {ok, LQR} | {error, binary()}. to_inline(Ref) -> case Ref of {inline, Value} -> {ok, Value}; {reference, R} -> {error, R} end. -file("src/nori/reference.gleam", 36). ?DOC(" Checks if a `Ref` is a reference (not inline).\n"). -spec is_reference(ref(any())) -> boolean(). is_reference(Ref) -> case Ref of {reference, _} -> true; {inline, _} -> false end. -file("src/nori/reference.gleam", 44). ?DOC(" Checks if a `Ref` is inline (not a reference).\n"). -spec is_inline(ref(any())) -> boolean(). is_inline(Ref) -> case Ref of {inline, _} -> true; {reference, _} -> false end. -file("src/nori/reference.gleam", 52). ?DOC(" Gets the reference string if this is a `Reference`, otherwise `None`.\n"). -spec get_ref(ref(any())) -> {ok, binary()} | {error, nil}. get_ref(Ref) -> case Ref of {reference, R} -> {ok, R}; {inline, _} -> {error, nil} end. -file("src/nori/reference.gleam", 60). ?DOC(" Maps a function over the inline value, leaving references unchanged.\n"). -spec map(ref(LRD), fun((LRD) -> LRF)) -> ref(LRF). map(Ref, F) -> case Ref of {inline, Value} -> {inline, F(Value)}; {reference, R} -> {reference, R} end. -file("src/nori/reference.gleam", 68). ?DOC(" Applies a function that returns a `Ref` to an inline value.\n"). -spec flat_map(ref(LRH), fun((LRH) -> ref(LRJ))) -> ref(LRJ). flat_map(Ref, F) -> case Ref of {inline, Value} -> F(Value); {reference, R} -> {reference, R} end.