Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handle anonymous name #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 25.1.2
elixir 1.14.3
elixir 1.16.1-otp-26
erlang 26.0.2
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Config

config :logger, level: :warn
config :logger, level: :warning
3 changes: 2 additions & 1 deletion lib/printer/any_of_printer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 10 additions & 4 deletions lib/printer/utils/naming.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand Down