forked from loafle/openapi-generator-original
Fix the function name starting with numbers (#1513)
* update elixir samples * fix function name starting with numbers * add new files
This commit is contained in:
parent
5aa1da7c2e
commit
cf04ba30db
@ -431,7 +431,19 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId));
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)));
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId));
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ defmodule {{moduleName}}.Api.{{classname}} do
|
||||
{:error, info} on failure
|
||||
"""
|
||||
{{{typespec}}}
|
||||
def {{#underscored}}{{{operationId}}}{{/underscored}}(connection, {{#requiredParams}}{{#underscored}}{{{paramName}}}{{/underscored}}, {{/requiredParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do
|
||||
def {{{operationId}}}(connection, {{#requiredParams}}{{#underscored}}{{{paramName}}}{{/underscored}}, {{/requiredParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do
|
||||
{{#optionalParams}}
|
||||
{{#-first}}
|
||||
optional_params = %{
|
||||
|
23
samples/client/petstore/elixir/.openapi-generator-ignore
Normal file
23
samples/client/petstore/elixir/.openapi-generator-ignore
Normal file
@ -0,0 +1,23 @@
|
||||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
@ -1 +1 @@
|
||||
3.0.0-SNAPSHOT
|
||||
3.3.4-SNAPSHOT
|
@ -10,11 +10,11 @@ use Mix.Config
|
||||
|
||||
# You can configure for your application as:
|
||||
#
|
||||
# config :swagger_petstore, key: :value
|
||||
# config :open_api_petstore, key: :value
|
||||
#
|
||||
# And access this configuration in your application as:
|
||||
#
|
||||
# Application.get_env(:swagger_petstore, :key)
|
||||
# Application.get_env(:open_api_petstore, :key)
|
||||
#
|
||||
# Or configure a 3rd-party app:
|
||||
#
|
||||
|
@ -13,7 +13,7 @@ defmodule OpenapiPetstore.Api.AnotherFake do
|
||||
|
||||
@doc """
|
||||
To test special tags
|
||||
To test special tags
|
||||
To test special tags and operation ID starting with number
|
||||
|
||||
## Parameters
|
||||
|
||||
@ -25,8 +25,8 @@ defmodule OpenapiPetstore.Api.AnotherFake do
|
||||
{:ok, %OpenapiPetstore.Model.Client{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec test_special_tags(Tesla.Env.client, OpenapiPetstore.Model.Client.t, keyword()) :: {:ok, OpenapiPetstore.Model.Client.t} | {:error, Tesla.Env.t}
|
||||
def test_special_tags(connection, client, _opts \\ []) do
|
||||
@spec call_123_test_special_tags(Tesla.Env.client, OpenapiPetstore.Model.Client.t, keyword()) :: {:ok, OpenapiPetstore.Model.Client.t} | {:error, Tesla.Env.t}
|
||||
def call_123_test_special_tags(connection, client, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:patch)
|
||||
|> url("/another-fake/dummy")
|
||||
|
@ -21,7 +21,7 @@ defmodule OpenapiPetstore.Api.Fake do
|
||||
- :body (boolean()): Input boolean as post body
|
||||
## Returns
|
||||
|
||||
{:ok, %OpenapiPetstore.Model.Boolean{}} on success
|
||||
{:ok, %OpenapiPetstore.Model.boolean(){}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec fake_outer_boolean_serialize(Tesla.Env.client, keyword()) :: {:ok, Boolean.t} | {:error, Tesla.Env.t}
|
||||
@ -75,7 +75,7 @@ defmodule OpenapiPetstore.Api.Fake do
|
||||
- :body (float()): Input number as post body
|
||||
## Returns
|
||||
|
||||
{:ok, %OpenapiPetstore.Model.Float{}} on success
|
||||
{:ok, %OpenapiPetstore.Model.float(){}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec fake_outer_number_serialize(Tesla.Env.client, keyword()) :: {:ok, Float.t} | {:error, Tesla.Env.t}
|
||||
@ -102,7 +102,7 @@ defmodule OpenapiPetstore.Api.Fake do
|
||||
- :body (String.t): Input string as post body
|
||||
## Returns
|
||||
|
||||
{:ok, %OpenapiPetstore.Model.String{}} on success
|
||||
{:ok, %OpenapiPetstore.Model.String.t{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec fake_outer_string_serialize(Tesla.Env.client, keyword()) :: {:ok, String.t} | {:error, Tesla.Env.t}
|
||||
@ -119,6 +119,30 @@ defmodule OpenapiPetstore.Api.Fake do
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
For this test, the body for this request much reference a schema named `File`.
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (OpenapiPetstore.Connection): Connection to server
|
||||
- file_schema_test_class (FileSchemaTestClass):
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec test_body_with_file_schema(Tesla.Env.client, OpenapiPetstore.Model.FileSchemaTestClass.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def test_body_with_file_schema(connection, file_schema_test_class, _opts \\ []) do
|
||||
%{}
|
||||
|> method(:put)
|
||||
|> url("/fake/body-with-file-schema")
|
||||
|> add_param(:body, :"FileSchemaTestClass", file_schema_test_class)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
## Parameters
|
||||
@ -265,13 +289,51 @@ defmodule OpenapiPetstore.Api.Fake do
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Fake endpoint to test group parameters (optional)
|
||||
Fake endpoint to test group parameters (optional)
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (OpenapiPetstore.Connection): Connection to server
|
||||
- required_string_group (integer()): Required String in group parameters
|
||||
- required_boolean_group (boolean()): Required Boolean in group parameters
|
||||
- required_int64_group (integer()): Required Integer in group parameters
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :string_group (integer()): String in group parameters
|
||||
- :boolean_group (boolean()): Boolean in group parameters
|
||||
- :int64_group (integer()): Integer in group parameters
|
||||
## Returns
|
||||
|
||||
{:ok, %{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec test_group_parameters(Tesla.Env.client, integer(), boolean(), integer(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||
def test_group_parameters(connection, required_string_group, required_boolean_group, required_int64_group, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"string_group" => :query,
|
||||
:"boolean_group" => :headers,
|
||||
:"int64_group" => :query
|
||||
}
|
||||
%{}
|
||||
|> method(:delete)
|
||||
|> url("/fake")
|
||||
|> add_param(:query, :"required_string_group", required_string_group)
|
||||
|> add_param(:headers, :"required_boolean_group", required_boolean_group)
|
||||
|> add_param(:query, :"required_int64_group", required_int64_group)
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(false)
|
||||
end
|
||||
|
||||
@doc """
|
||||
test inline additionalProperties
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (OpenapiPetstore.Connection): Connection to server
|
||||
- request_body (String.t): request body
|
||||
- request_body (%{optional(String.t) => String.t}): request body
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
## Returns
|
||||
|
||||
|
@ -220,4 +220,34 @@ defmodule OpenapiPetstore.Api.Pet do
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%OpenapiPetstore.Model.ApiResponse{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
uploads an image (required)
|
||||
|
||||
## Parameters
|
||||
|
||||
- connection (OpenapiPetstore.Connection): Connection to server
|
||||
- pet_id (integer()): ID of pet to update
|
||||
- required_file (String.t): file to upload
|
||||
- opts (KeywordList): [optional] Optional parameters
|
||||
- :additional_metadata (String.t): Additional data to pass to server
|
||||
## Returns
|
||||
|
||||
{:ok, %OpenapiPetstore.Model.ApiResponse{}} on success
|
||||
{:error, info} on failure
|
||||
"""
|
||||
@spec upload_file_with_required_file(Tesla.Env.client, integer(), String.t, keyword()) :: {:ok, OpenapiPetstore.Model.ApiResponse.t} | {:error, Tesla.Env.t}
|
||||
def upload_file_with_required_file(connection, pet_id, required_file, opts \\ []) do
|
||||
optional_params = %{
|
||||
:"additionalMetadata" => :form
|
||||
}
|
||||
%{}
|
||||
|> method(:post)
|
||||
|> url("/fake/#{pet_id}/uploadImageWithRequiredFile")
|
||||
|> add_param(:file, :"requiredFile", required_file)
|
||||
|> add_optional_params(optional_params, opts)
|
||||
|> Enum.into([])
|
||||
|> (&Connection.request(connection, &1)).()
|
||||
|> decode(%OpenapiPetstore.Model.ApiResponse{})
|
||||
end
|
||||
end
|
||||
|
@ -15,7 +15,7 @@ defmodule OpenapiPetstore.Connection do
|
||||
plug Tesla.Middleware.EncodeJson
|
||||
|
||||
@doc """
|
||||
Configure an client connection using Basic authentication.
|
||||
Configure a client connection using Basic authentication.
|
||||
|
||||
## Parameters
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
# https://openapi-generator.tech
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule OpenapiPetstore.Model.FileSchemaTestClass do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"file",
|
||||
:"files"
|
||||
]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
:"file" => File,
|
||||
:"files" => [File]
|
||||
}
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: OpenapiPetstore.Model.FileSchemaTestClass do
|
||||
import OpenapiPetstore.Deserializer
|
||||
def decode(value, options) do
|
||||
value
|
||||
|> deserialize(:"file", :struct, OpenapiPetstore.Model.File, options)
|
||||
|> deserialize(:"files", :list, OpenapiPetstore.Model.File, options)
|
||||
end
|
||||
end
|
||||
|
@ -10,12 +10,16 @@ defmodule OpenapiPetstore.Model.MapTest do
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
:"map_map_of_string",
|
||||
:"map_of_enum_string"
|
||||
:"map_of_enum_string",
|
||||
:"direct_map",
|
||||
:"indirect_map"
|
||||
]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
:"map_map_of_string" => %{optional(String.t) => %{optional(String.t) => String.t}},
|
||||
:"map_of_enum_string" => %{optional(String.t) => String.t}
|
||||
:"map_of_enum_string" => %{optional(String.t) => String.t},
|
||||
:"direct_map" => %{optional(String.t) => boolean()},
|
||||
:"indirect_map" => %{optional(String.t) => boolean()}
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -15,9 +15,9 @@ defmodule OpenapiPetstore.Model.OuterComposite do
|
||||
]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
:"my_number" => Float,
|
||||
:"my_string" => String,
|
||||
:"my_boolean" => Boolean
|
||||
:"my_number" => float(),
|
||||
:"my_string" => String.t,
|
||||
:"my_boolean" => boolean()
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
# https://openapi-generator.tech
|
||||
# Do not edit the class manually.
|
||||
|
||||
defmodule OpenapiPetstore.Model.StringBooleanMap do
|
||||
@moduledoc """
|
||||
|
||||
"""
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [
|
||||
|
||||
]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
|
||||
}
|
||||
end
|
||||
|
||||
defimpl Poison.Decoder, for: OpenapiPetstore.Model.StringBooleanMap do
|
||||
def decode(value, _options) do
|
||||
value
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user