-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(OAO) :: {named, binary()} | {primitive, primitive()} | {array, schema(integer())} | {tuple, list(schema(integer()))} | {compound, OAO} | unsupported. -type fields() :: {fields, list({binary(), {schema(integer()), boolean()}}), list(binary())}. -type primitive() :: boolean | integer | number | string | null | always | never. -file("src/oas/generator/lift.gleam", 39). -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}; unsupported -> {unsupported, Acc} end. -file("src/oas/generator/lift.gleam", 54). -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, Nullable@5, _, _, _} -> {Acc@6, Properties@1} = gleam@list:map_fold( begin _pipe = Properties, maps:to_list(_pipe) end, Acc, fun(Acc@3, Property) -> {Field, Schema@3} = Property, {Top@1, Nullable@6, Acc@4} = do_lift( Schema@3, Acc@3 ), {Schema@4, Acc@5} = not_top(Top@1, Acc@4), {Acc@5, {Field, {Schema@4, Nullable@6}}} end ), {{compound, {fields, Properties@1, Required}}, Nullable@5, Acc@6}; {all_of, {non_empty_list, Schema@5, []}} -> do_lift(Schema@5, Acc); {all_of, Items@1} -> {Acc@10, Items@2} = gleam@list:map_fold( begin _pipe@1 = Items@1, non_empty_list:to_list(_pipe@1) end, Acc, fun(Acc@7, Item) -> {Top@2, _, Acc@8} = do_lift(Item, Acc@7), {Schema@6, Acc@9} = not_top(Top@2, Acc@8), {Acc@9, Schema@6} end ), {{tuple, Items@2}, false, Acc@10}; {any_of, {non_empty_list, Schema@7, []}} -> do_lift(Schema@7, Acc); {one_of, {non_empty_list, Schema@8, []}} -> do_lift(Schema@8, 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", 35). -spec lift(oas:ref(oas:schema())) -> {schema(fields()), boolean(), list(fields())}. lift(Schema) -> do_lift(Schema, []).