Skip to content

Commit

Permalink
chore: Warn and continue when failing to load a spec (googleapis#9989)
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma authored Jul 15, 2022
1 parent b225c78 commit ce433a5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
44 changes: 24 additions & 20 deletions lib/google_apis/generator/elixir_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,30 @@ defmodule GoogleApis.Generator.ElixirGenerator do
"""
@spec generate_client(ApiConfig.t()) :: any()
def generate_client(api_config) do
token = Token.build(api_config)
if updated_discovery_revision?(token) do
token
|> load_models
|> set_model_filenames
|> update_model_properties
|> create_directories
|> write_model_files
|> load_global_optional_params
|> load_apis
|> set_api_filenames
|> write_api_files
|> write_connection
|> write_metadata
|> write_mix_exs
|> write_readme
|> write_license
|> write_gitignore
|> write_config_exs
|> write_test_helper_exs
case Token.build(api_config) do
nil ->
IO.puts("Unable to read spec file #{ApiConfig.google_spec_file(api_config)}")
token ->
if updated_discovery_revision?(token) do
token
|> load_models
|> set_model_filenames
|> update_model_properties
|> create_directories
|> write_model_files
|> load_global_optional_params
|> load_apis
|> set_api_filenames
|> write_api_files
|> write_connection
|> write_metadata
|> write_mix_exs
|> write_readme
|> write_license
|> write_gitignore
|> write_config_exs
|> write_test_helper_exs
end
end
:ok
end
Expand Down
54 changes: 27 additions & 27 deletions lib/google_apis/generator/elixir_generator/token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,33 @@ defmodule GoogleApis.Generator.ElixirGenerator.Token do
String.downcase(ApiConfig.module_version(api_config))
])

rest_description =
api_config
|> ApiConfig.google_spec_file()
|> File.read!()
|> Poison.decode!(as: %RestDescription{})

{base_url, base_path} = determine_base_paths(rest_description)

resource_context =
ResourceContext.empty()
|> ResourceContext.with_namespace(namespace)
|> ResourceContext.with_base_path(base_path)

data_wrapped = has_data_wrapper_feature?(rest_description)

%__MODULE__{
filename: filename,
library_name: library_name,
namespace: namespace,
root_namespace: root_namespace,
root_dir: root_dir,
base_dir: base_dir,
base_url: base_url,
rest_description: rest_description,
resource_context: resource_context,
data_wrapped: data_wrapped
}
case api_config |> ApiConfig.google_spec_file() |> File.read() do
{:ok, content} ->
rest_description = Poison.decode!(content, as: %RestDescription{})
{base_url, base_path} = determine_base_paths(rest_description)

resource_context =
ResourceContext.empty()
|> ResourceContext.with_namespace(namespace)
|> ResourceContext.with_base_path(base_path)

data_wrapped = has_data_wrapper_feature?(rest_description)

%__MODULE__{
filename: filename,
library_name: library_name,
namespace: namespace,
root_namespace: root_namespace,
root_dir: root_dir,
base_dir: base_dir,
base_url: base_url,
rest_description: rest_description,
resource_context: resource_context,
data_wrapped: data_wrapped
}
_ ->
nil
end
end

defp determine_base_paths(rest_description) do
Expand Down

0 comments on commit ce433a5

Please sign in to comment.