-module(oas@generator@lift). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -define(FILEPATH, "src/oas/generator/lift.gleam"). -export([do_lift/2, lift/1]). -export_type([schema/1, fields/0, primitive/0]). -type schema(OBE) :: {named, binary()} | {primitive, primitive()} | {array, schema(integer())} | {tuple, list(schema(integer()))} | {compound, OBE} | {dictionary, schema(integer())} | unsupported. -type fields() :: {fields, list({binary(), {schema(integer()), boolean()}}), gleam@option:option(schema(integer())), list(binary())}. -type primitive() :: boolean | integer | number | string | null | always | never. -file("src/oas/generator/lift.gleam", 45). -spec not_top(schema(fields()), list(fields())) -> {schema(integer()), list(fields())}. not_top(Top, Acc) -> case Top of {compound, Fields} -> Id = erlang:length(Acc), Acc@1 = [Fields | Acc], {{compound, Id}, Acc@1}; {named, Name} -> {{named, Name}, Acc}; {primitive, Primitive} -> {{primitive, Primitive}, Acc}; {array, Items} -> {{array, Items}, Acc}; {tuple, Items@1} -> {{tuple, Items@1}, Acc}; {dictionary, Values} -> {{dictionary, Values}, Acc}; unsupported -> {unsupported, Acc} end. -file("src/oas/generator/lift.gleam", 61). -spec do_lift(oas:ref(oas:schema()), list(fields())) -> {schema(fields()), boolean(), list(fields())}. do_lift(Schema, Acc) -> case Schema of {ref, Ref, _, _} -> {{named, Ref}, false, Acc}; {inline, Schema@1} -> case Schema@1 of {boolean, Nullable, _, _, _} -> {{primitive, boolean}, Nullable, Acc}; {integer, _, _, _, _, _, Nullable@1, _, _, _} -> {{primitive, integer}, Nullable@1, Acc}; {number, _, _, _, _, _, Nullable@2, _, _, _} -> {{primitive, number}, Nullable@2, Acc}; {string, _, _, _, _, Nullable@3, _, _, _} -> {{primitive, string}, Nullable@3, Acc}; {null, _, _, _} -> {{primitive, null}, false, Acc}; {array, _, _, _, Items, Nullable@4, _, _, _} -> {Top, _, Acc@1} = do_lift(Items, Acc), {Schema@2, Acc@2} = not_top(Top, Acc@1), {{array, Schema@2}, Nullable@4, Acc@2}; {object, Properties, Required, Additional_properties, _, _, Nullable@5, _, _, _} -> case {gleam@dict:is_empty(Properties), Additional_properties} of {true, {some, Values}} -> {Top@1, _, Acc@3} = do_lift(Values, Acc), {Schema@3, Acc@4} = not_top(Top@1, Acc@3), {{dictionary, Schema@3}, Nullable@5, Acc@4}; {_, _} -> {Acc@8, Properties@1} = gleam@list:map_fold( begin _pipe = Properties, maps:to_list(_pipe) end, Acc, fun(Acc@5, Property) -> {Field, Schema@4} = Property, {Top@2, Nullable@6, Acc@6} = do_lift( Schema@4, Acc@5 ), {Schema@5, Acc@7} = not_top(Top@2, Acc@6), {Acc@7, {Field, {Schema@5, Nullable@6}}} end ), {Additional, Acc@11} = case Additional_properties of {some, Values@1} -> {Top@3, _, Acc@9} = do_lift(Values@1, Acc@8), {Schema@6, Acc@10} = not_top(Top@3, Acc@9), {{some, Schema@6}, Acc@10}; none -> {none, Acc@8} end, {{compound, {fields, Properties@1, Additional, Required}}, Nullable@5, Acc@11} end; {all_of, {non_empty_list, Schema@7, []}} -> do_lift(Schema@7, Acc); {all_of, Items@1} -> {Acc@15, Items@2} = gleam@list:map_fold( begin _pipe@1 = Items@1, non_empty_list:to_list(_pipe@1) end, Acc, fun(Acc@12, Item) -> {Top@4, _, Acc@13} = do_lift(Item, Acc@12), {Schema@8, Acc@14} = not_top(Top@4, Acc@13), {Acc@14, Schema@8} end ), {{tuple, Items@2}, false, Acc@15}; {any_of, {non_empty_list, Schema@9, []}} -> do_lift(Schema@9, Acc); {one_of, {non_empty_list, Schema@10, []}} -> do_lift(Schema@10, Acc); {any_of, _} -> {unsupported, false, Acc}; {one_of, _} -> {unsupported, false, Acc}; always_passes -> {{primitive, always}, false, Acc}; always_fails -> {{primitive, never}, false, Acc} end end. -file("src/oas/generator/lift.gleam", 41). -spec lift(oas:ref(oas:schema())) -> {schema(fields()), boolean(), list(fields())}. lift(Schema) -> do_lift(Schema, []).