forked from loafle/openapi-generator-original
[fix][elixir] faulty free-form object type spec (#21113)
* fix: faulty free-form object type spec * add implicit free-form object example
This commit is contained in:
parent
64d9719d39
commit
3233eff187
@ -570,7 +570,11 @@ public class ElixirClientCodegen extends DefaultCodegen {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (ModelUtils.isAnyType(p)) {
|
||||||
|
return "any()";
|
||||||
|
} else if(ModelUtils.isFreeFormObject(p, null)) {
|
||||||
|
return "%{optional(String.t) => any()}";
|
||||||
|
} else if (ModelUtils.isArraySchema(p)) {
|
||||||
Schema inner = ModelUtils.getSchemaItems(p);
|
Schema inner = ModelUtils.getSchemaItems(p);
|
||||||
return "[" + getTypeDeclaration(inner) + "]";
|
return "[" + getTypeDeclaration(inner) + "]";
|
||||||
} else if (ModelUtils.isMapSchema(p)) {
|
} else if (ModelUtils.isMapSchema(p)) {
|
||||||
@ -856,6 +860,10 @@ public class ElixirClientCodegen extends DefaultCodegen {
|
|||||||
private void buildTypespec(CodegenParameter param, StringBuilder sb) {
|
private void buildTypespec(CodegenParameter param, StringBuilder sb) {
|
||||||
if (param.dataType == null) {
|
if (param.dataType == null) {
|
||||||
sb.append("nil");
|
sb.append("nil");
|
||||||
|
} else if (param.isAnyType) {
|
||||||
|
sb.append("any()");
|
||||||
|
} else if(param.isFreeFormObject) {
|
||||||
|
sb.append("%{optional(String.t) => any()}");
|
||||||
} else if (param.isArray) {
|
} else if (param.isArray) {
|
||||||
// list(<subtype>)
|
// list(<subtype>)
|
||||||
sb.append("list(");
|
sb.append("list(");
|
||||||
@ -875,6 +883,10 @@ public class ElixirClientCodegen extends DefaultCodegen {
|
|||||||
if (property == null) {
|
if (property == null) {
|
||||||
LOGGER.error(
|
LOGGER.error(
|
||||||
"CodegenProperty cannot be null. Please report the issue to https://github.com/openapitools/openapi-generator with the spec");
|
"CodegenProperty cannot be null. Please report the issue to https://github.com/openapitools/openapi-generator with the spec");
|
||||||
|
} else if (property.isAnyType) {
|
||||||
|
sb.append("any()");
|
||||||
|
} else if(property.isFreeFormObject) {
|
||||||
|
sb.append("%{optional(String.t) => any()}");
|
||||||
} else if (property.isArray) {
|
} else if (property.isArray) {
|
||||||
sb.append("list(");
|
sb.append("list(");
|
||||||
buildTypespec(property.items, sb);
|
buildTypespec(property.items, sb);
|
||||||
|
@ -1012,6 +1012,40 @@ paths:
|
|||||||
$ref: "#/components/schemas/FreeFormObject"
|
$ref: "#/components/schemas/FreeFormObject"
|
||||||
description: request body
|
description: request body
|
||||||
required: true
|
required: true
|
||||||
|
/fake/implicitFreeFormObject:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- fake
|
||||||
|
summary: test free form object with implicit additionalProperties
|
||||||
|
description: ""
|
||||||
|
operationId: testImplicitFreeFormObject
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: successful operation
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/ImplicitFreeFormObject"
|
||||||
|
description: request body
|
||||||
|
required: true
|
||||||
|
/fake/anyTypeObject:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- fake
|
||||||
|
summary: test any type object
|
||||||
|
description: ""
|
||||||
|
operationId: testAnyTypeObject
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: successful operation
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/AnyTypeObject"
|
||||||
|
description: request body
|
||||||
|
required: true
|
||||||
/fake/stringMap-reference:
|
/fake/stringMap-reference:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
@ -1859,6 +1893,19 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
description: A schema consisting only of additional properties
|
description: A schema consisting only of additional properties
|
||||||
additionalProperties: true
|
additionalProperties: true
|
||||||
|
ImplicitFreeFormObject:
|
||||||
|
type: object
|
||||||
|
description: A schema consisting only of additional properties (implicit)
|
||||||
|
AnyTypeObject:
|
||||||
|
oneOf:
|
||||||
|
- type: string
|
||||||
|
- type: number
|
||||||
|
- type: integer
|
||||||
|
- type: boolean
|
||||||
|
- type: object
|
||||||
|
- type: array
|
||||||
|
items: {}
|
||||||
|
nullable: true
|
||||||
MapOfString:
|
MapOfString:
|
||||||
type: object
|
type: object
|
||||||
description: A schema consisting only of additional properties of type string
|
description: A schema consisting only of additional properties of type string
|
||||||
|
@ -304,6 +304,37 @@ defmodule OpenapiPetstore.Api.Fake do
|
|||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
test any type object
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
- `connection` (OpenapiPetstore.Connection): Connection to server
|
||||||
|
- `body` (any()): request body
|
||||||
|
- `opts` (keyword): Optional parameters
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
- `{:ok, nil}` on success
|
||||||
|
- `{:error, Tesla.Env.t}` on failure
|
||||||
|
"""
|
||||||
|
@spec test_any_type_object(Tesla.Env.client, any(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||||
|
def test_any_type_object(connection, body, _opts \\ []) do
|
||||||
|
request =
|
||||||
|
%{}
|
||||||
|
|> method(:post)
|
||||||
|
|> url("/fake/anyTypeObject")
|
||||||
|
|> add_param(:body, :body, body)
|
||||||
|
|> Enum.into([])
|
||||||
|
|
||||||
|
connection
|
||||||
|
|> Connection.request(request)
|
||||||
|
|> evaluate_response([
|
||||||
|
{200, false}
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
For this test, the body has to be a binary file.
|
For this test, the body has to be a binary file.
|
||||||
|
|
||||||
@ -585,6 +616,37 @@ defmodule OpenapiPetstore.Api.Fake do
|
|||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
test free form object with implicit additionalProperties
|
||||||
|
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
- `connection` (OpenapiPetstore.Connection): Connection to server
|
||||||
|
- `body` (%{optional(String.t) => any()}): request body
|
||||||
|
- `opts` (keyword): Optional parameters
|
||||||
|
|
||||||
|
### Returns
|
||||||
|
|
||||||
|
- `{:ok, nil}` on success
|
||||||
|
- `{:error, Tesla.Env.t}` on failure
|
||||||
|
"""
|
||||||
|
@spec test_implicit_free_form_object(Tesla.Env.client, %{optional(String.t) => any()}, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
|
||||||
|
def test_implicit_free_form_object(connection, body, _opts \\ []) do
|
||||||
|
request =
|
||||||
|
%{}
|
||||||
|
|> method(:post)
|
||||||
|
|> url("/fake/implicitFreeFormObject")
|
||||||
|
|> add_param(:body, :body, body)
|
||||||
|
|> Enum.into([])
|
||||||
|
|
||||||
|
connection
|
||||||
|
|> Connection.request(request)
|
||||||
|
|> evaluate_response([
|
||||||
|
{200, false}
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
test inline additionalProperties
|
test inline additionalProperties
|
||||||
|
|
||||||
|
@ -29,12 +29,12 @@ defmodule OpenapiPetstore.Model.NullableClass do
|
|||||||
:string_prop => String.t | nil,
|
:string_prop => String.t | nil,
|
||||||
:date_prop => Date.t | nil,
|
:date_prop => Date.t | nil,
|
||||||
:datetime_prop => DateTime.t | nil,
|
:datetime_prop => DateTime.t | nil,
|
||||||
:array_nullable_prop => [map()] | nil,
|
:array_nullable_prop => [%{optional(String.t) => any()}] | nil,
|
||||||
:array_and_items_nullable_prop => [map()] | nil,
|
:array_and_items_nullable_prop => [%{optional(String.t) => any()}] | nil,
|
||||||
:array_items_nullable => [map()] | nil,
|
:array_items_nullable => [%{optional(String.t) => any()}] | nil,
|
||||||
:object_nullable_prop => %{optional(String.t) => map()} | nil,
|
:object_nullable_prop => %{optional(String.t) => any()} | nil,
|
||||||
:object_and_items_nullable_prop => %{optional(String.t) => map()} | nil,
|
:object_and_items_nullable_prop => %{optional(String.t) => any()} | nil,
|
||||||
:object_items_nullable => %{optional(String.t) => map()} | nil
|
:object_items_nullable => %{optional(String.t) => any()} | nil
|
||||||
}
|
}
|
||||||
|
|
||||||
alias OpenapiPetstore.Deserializer
|
alias OpenapiPetstore.Deserializer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user