Improved Elixir Atom Generation (#20229)

* Update ElixirClientCodegen.java

* Refine the regular expression for atoms

The original regex incorrectly matched `@atom` (unquoted atoms
cannot begin with @). However, through testing with `iex`, it also turns out that the atom
`:@` is legal.

The following atoms will now be quoted that would have been
incorrectly not quoted:

- `:@type`

* Add model to petstore client to test new atom creation regex pattern
This commit is contained in:
drewble 2024-12-06 00:26:39 -06:00 committed by GitHub
parent 52b5b8fb76
commit ba5ecbccde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 279 additions and 237 deletions

View File

@ -48,7 +48,7 @@ import static org.openapitools.codegen.utils.StringUtils.underscore;
public class ElixirClientCodegen extends DefaultCodegen {
private final Logger LOGGER = LoggerFactory.getLogger(ElixirClientCodegen.class);
private final Pattern simpleAtomPattern = Pattern.compile("\\A(?:(?:[_@\\p{Alpha}][_@\\p{Alnum}]*[?!]?)|-)\\z");
private final Pattern simpleAtomPattern = Pattern.compile("\\A(?:(?:[_\\p{Alpha}][_@\\p{Alnum}]*[?!]?)|-|@)\\z");
@Setter protected String packageVersion = "1.0.0";
@Setter protected String moduleName;

View File

@ -17,6 +17,7 @@ lib/openapi_petstore/model/_special_model_name_.ex
lib/openapi_petstore/model/additional_properties_class.ex
lib/openapi_petstore/model/all_of_with_single_ref.ex
lib/openapi_petstore/model/animal.ex
lib/openapi_petstore/model/any.ex
lib/openapi_petstore/model/api_response.ex
lib/openapi_petstore/model/array_of_array_of_number_only.ex
lib/openapi_petstore/model/array_of_number_only.ex

View File

@ -0,0 +1,22 @@
# NOTE: This file is auto generated by OpenAPI Generator 7.11.0-SNAPSHOT (https://openapi-generator.tech).
# Do not edit this file manually.
defmodule OpenapiPetstore.Model.Any do
@moduledoc """
"""
@derive Jason.Encoder
defstruct [
:"@type"
]
@type t :: %__MODULE__{
:"@type" => String.t | nil
}
def decode(value) do
value
end
end

View File

@ -0,0 +1,14 @@
defmodule AnyTest do
use ExUnit.Case, async: true
alias OpenapiPetstore.Model.Any, as: Model
test "decode all properties (not nil)" do
assert %Model{
"@type": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
|> Model.decode() ==
%Model{
"@type": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
end
end