From 1dabfbca02f4533ec83c8b244a4138c21bb405d1 Mon Sep 17 00:00:00 2001 From: setop <7794056+setop@users.noreply.github.com> Date: Tue, 23 Jul 2024 05:21:17 +0200 Subject: [PATCH] fix handle anonymous name fix handle object has no properties chore update to elixir 1.16 and fix related warnings closes #180 --- .tool-versions | 4 ++-- config/prod.exs | 2 +- lib/printer/any_of_printer.ex | 3 ++- lib/printer/utils/naming.ex | 14 ++++++++++---- mix.exs | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.tool-versions b/.tool-versions index 2219323..2674fef 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 25.1.2 -elixir 1.14.3 +elixir 1.16.1-otp-26 +erlang 26.0.2 diff --git a/config/prod.exs b/config/prod.exs index 3da7d10..63787d4 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -1,3 +1,3 @@ import Config -config :logger, level: :warn +config :logger, level: :warning diff --git a/lib/printer/any_of_printer.ex b/lib/printer/any_of_printer.ex index a9c4faf..38399c3 100644 --- a/lib/printer/any_of_printer.ex +++ b/lib/printer/any_of_printer.ex @@ -279,7 +279,8 @@ defmodule JS2E.Printer.AnyOfPrinter do schema_dict, module_name ) do - type_def.properties + type_def + |> Map.get(:properties, []) |> Enum.map(fn {child_name, child_path} -> with {:ok, {child_type_def, child_schema_def}} <- Resolver.resolve_type( diff --git a/lib/printer/utils/naming.ex b/lib/printer/utils/naming.ex index bd66ffb..d224a2b 100644 --- a/lib/printer/utils/naming.ex +++ b/lib/printer/utils/naming.ex @@ -78,7 +78,11 @@ defmodule JS2E.Printer.Utils.Naming do """ @spec normalize_identifier(String.t(), casing) :: String.t() - def normalize_identifier(identifier, casing \\ :none) do + def normalize_identifier(identifier, casing \\ :none) + def normalize_identifier(:anonymous, _) do + "Hash" + end + def normalize_identifier(identifier, casing) do normalized_identifier = identifier |> kebab_to_camel_case @@ -186,12 +190,14 @@ defmodule JS2E.Printer.Utils.Naming do # Turns a kebab-cased identifier into a camelCased one @spec kebab_to_camel_case(String.t()) :: String.t() - defp kebab_to_camel_case(str) do + defp kebab_to_camel_case(str) when is_binary(str) do str |> String.split("-") |> Enum.map_join(fn word -> upcase_first(word) end) end + defp kebab_to_camel_case(_), do: {:error, "Input must be a string"} + # Turns a snake_cased identifier into a camelCased one @spec snake_to_camel_case(String.t()) :: String.t() defp snake_to_camel_case(str) do @@ -220,7 +226,7 @@ defmodule JS2E.Printer.Utils.Naming do @spec upcase_first(String.t()) :: String.t() def upcase_first(string) when is_binary(string) do if String.length(string) > 0 do - String.upcase(String.at(string, 0)) <> String.slice(string, 1..-1) + String.upcase(String.at(string, 0)) <> String.slice(string, 1..-1//1) else "" end @@ -238,7 +244,7 @@ defmodule JS2E.Printer.Utils.Naming do @spec downcase_first(String.t()) :: String.t() def downcase_first(string) when is_binary(string) do if String.length(string) > 0 do - String.downcase(String.at(string, 0)) <> String.slice(string, 1..-1) + String.downcase(String.at(string, 0)) <> String.slice(string, 1..-1//1) else "" end diff --git a/mix.exs b/mix.exs index 2b549c5..a2e7cce 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule JS2E.MixProject do use Mix.Project @version "2.9.1" - @elixir_version "~> 1.14" + @elixir_version "~> 1.16" def project do [