Skip to content

Commit b14a79e

Browse files
committed
fix: faulty free-form object type spec
1 parent 4c08ff8 commit b14a79e

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,11 @@ public String toOperationId(String operationId) {
570570
*/
571571
@Override
572572
public String getTypeDeclaration(Schema p) {
573-
if (ModelUtils.isArraySchema(p)) {
573+
if (ModelUtils.isAnyType(p)) {
574+
return "any()";
575+
} else if(ModelUtils.isFreeFormObject(p, null)) {
576+
return "%{optional(String.t) => any()}";
577+
} else if (ModelUtils.isArraySchema(p)) {
574578
Schema inner = ModelUtils.getSchemaItems(p);
575579
return "[" + getTypeDeclaration(inner) + "]";
576580
} else if (ModelUtils.isMapSchema(p)) {
@@ -856,6 +860,10 @@ private String normalizeTypeName(String baseType, boolean isPrimitive) {
856860
private void buildTypespec(CodegenParameter param, StringBuilder sb) {
857861
if (param.dataType == null) {
858862
sb.append("nil");
863+
} else if (param.isAnyType) {
864+
sb.append("any()");
865+
} else if(param.isFreeFormObject) {
866+
sb.append("%{optional(String.t) => any()}");
859867
} else if (param.isArray) {
860868
// list(<subtype>)
861869
sb.append("list(");
@@ -875,6 +883,10 @@ private void buildTypespec(CodegenProperty property, StringBuilder sb) {
875883
if (property == null) {
876884
LOGGER.error(
877885
"CodegenProperty cannot be null. Please report the issue to https://github.com/openapitools/openapi-generator with the spec");
886+
} else if (property.isAnyType) {
887+
sb.append("any()");
888+
} else if(property.isFreeFormObject) {
889+
sb.append("%{optional(String.t) => any()}");
878890
} else if (property.isArray) {
879891
sb.append("list(");
880892
buildTypespec(property.items, sb);

samples/client/petstore/elixir/lib/openapi_petstore/model/nullable_class.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ defmodule OpenapiPetstore.Model.NullableClass do
2929
:string_prop => String.t | nil,
3030
:date_prop => Date.t | nil,
3131
:datetime_prop => DateTime.t | nil,
32-
:array_nullable_prop => [map()] | nil,
33-
:array_and_items_nullable_prop => [map()] | nil,
34-
:array_items_nullable => [map()] | nil,
35-
:object_nullable_prop => %{optional(String.t) => map()} | nil,
36-
:object_and_items_nullable_prop => %{optional(String.t) => map()} | nil,
37-
:object_items_nullable => %{optional(String.t) => map()} | nil
32+
:array_nullable_prop => [%{optional(String.t) => any()}] | nil,
33+
:array_and_items_nullable_prop => [%{optional(String.t) => any()}] | nil,
34+
:array_items_nullable => [%{optional(String.t) => any()}] | nil,
35+
:object_nullable_prop => %{optional(String.t) => any()} | nil,
36+
:object_and_items_nullable_prop => %{optional(String.t) => any()} | nil,
37+
:object_items_nullable => %{optional(String.t) => any()} | nil
3838
}
3939

4040
alias OpenapiPetstore.Deserializer

0 commit comments

Comments
 (0)