[Elixir] allow custom packageVersion (#19151)

This commit is contained in:
Val Packett 2024-07-14 09:55:44 -03:00 committed by GitHub
parent 75f4faae0c
commit 3e6c13ede8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 10 deletions

View File

@ -26,6 +26,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true| |legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|licenseHeader|The license header to prepend to the top of all source files.| |null| |licenseHeader|The license header to prepend to the top of all source files.| |null|
|packageName|Elixir package name (convention: lowercase).| |null| |packageName|Elixir package name (convention: lowercase).| |null|
|packageVersion|Elixir package version.| |1.0.0|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| |prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|

View File

@ -50,7 +50,7 @@ public class ElixirClientCodegen extends DefaultCodegen {
private final Pattern simpleAtomPattern = Pattern.compile("\\A(?:(?:[_@\\p{Alpha}][_@\\p{Alnum}]*[?!]?)|-)\\z"); private final Pattern simpleAtomPattern = Pattern.compile("\\A(?:(?:[_@\\p{Alpha}][_@\\p{Alnum}]*[?!]?)|-)\\z");
protected String apiVersion = "1.0.0"; @Setter protected String packageVersion = "1.0.0";
@Setter protected String moduleName; @Setter protected String moduleName;
protected static final String defaultModuleName = "OpenAPI.Client"; protected static final String defaultModuleName = "OpenAPI.Client";
@ -147,12 +147,6 @@ public class ElixirClientCodegen extends DefaultCodegen {
"__ENV__", "__ENV__",
"__CALLER__")); "__CALLER__"));
/**
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
*/
additionalProperties.put("apiVersion", apiVersion);
/** /**
* Supporting Files. You can write single files for the generator with the * Supporting Files. You can write single files for the generator with the
* entire object tree available. If the input file has a suffix of `.mustache * entire object tree available. If the input file has a suffix of `.mustache
@ -301,6 +295,10 @@ public class ElixirClientCodegen extends DefaultCodegen {
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) { if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
setModuleName((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE)); setModuleName((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
} }
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
}
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
} }
@Override @Override

View File

@ -18,7 +18,7 @@ your list of dependencies in `mix.exs`:
```elixir ```elixir
{{=<% %>=}}def deps do {{=<% %>=}}def deps do
[{<%#atom%><%#underscored%><%packageName%><%/underscored%><%/atom%>, "~> <%appVersion%>"}] [{<%#atom%><%#underscored%><%packageName%><%/underscored%><%/atom%>, "~> <%packageVersion%>"}]
end<%={{ }}=%> end<%={{ }}=%>
``` ```

View File

@ -225,7 +225,7 @@ defmodule {{moduleName}}.Connection do
Keyword.get( Keyword.get(
tesla_options, tesla_options,
:user_agent, :user_agent,
"openapi-generator - {{moduleName}} {{appVersion}} - elixir" "openapi-generator - {{moduleName}} {{packageVersion}} - elixir"
) )
) )

View File

@ -4,7 +4,7 @@ defmodule {{moduleName}}.Mixfile do
def project do def project do
[ [
app: {{#atom}}{{#underscored}}{{packageName}}{{/underscored}}{{/atom}}, app: {{#atom}}{{#underscored}}{{packageName}}{{/underscored}}{{/atom}},
version: "{{appVersion}}", version: "{{packageVersion}}",
elixir: "~> {{supportedElixirVersion}}", elixir: "~> {{supportedElixirVersion}}",
build_embedded: Mix.env() == :prod, build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod, start_permanent: Mix.env() == :prod,