Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,11 @@ public String toOperationId(String operationId) {
*/
@Override
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);
return "[" + getTypeDeclaration(inner) + "]";
} else if (ModelUtils.isMapSchema(p)) {
Expand Down Expand Up @@ -856,6 +860,10 @@ private String normalizeTypeName(String baseType, boolean isPrimitive) {
private void buildTypespec(CodegenParameter param, StringBuilder sb) {
if (param.dataType == null) {
sb.append("nil");
} else if (param.isAnyType) {
sb.append("any()");
} else if(param.isFreeFormObject) {
sb.append("%{optional(String.t) => any()}");
} else if (param.isArray) {
// list(<subtype>)
sb.append("list(");
Expand All @@ -875,6 +883,10 @@ private void buildTypespec(CodegenProperty property, StringBuilder sb) {
if (property == null) {
LOGGER.error(
"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) {
sb.append("list(");
buildTypespec(property.items, sb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,40 @@ paths:
$ref: "#/components/schemas/FreeFormObject"
description: request body
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:
post:
tags:
Expand Down Expand Up @@ -1859,6 +1893,19 @@ components:
type: object
description: A schema consisting only of additional properties
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:
type: object
description: A schema consisting only of additional properties of type string
Expand Down
62 changes: 62 additions & 0 deletions samples/client/petstore/elixir/lib/openapi_petstore/api/fake.ex
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,37 @@ defmodule OpenapiPetstore.Api.Fake do
])
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 """
For this test, the body has to be a binary file.

Expand Down Expand Up @@ -585,6 +616,37 @@ defmodule OpenapiPetstore.Api.Fake do
])
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 """
test inline additionalProperties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ defmodule OpenapiPetstore.Model.NullableClass do
:string_prop => String.t | nil,
:date_prop => Date.t | nil,
:datetime_prop => DateTime.t | nil,
:array_nullable_prop => [map()] | nil,
:array_and_items_nullable_prop => [map()] | nil,
:array_items_nullable => [map()] | nil,
:object_nullable_prop => %{optional(String.t) => map()} | nil,
:object_and_items_nullable_prop => %{optional(String.t) => map()} | nil,
:object_items_nullable => %{optional(String.t) => map()} | nil
:array_nullable_prop => [%{optional(String.t) => any()}] | nil,
:array_and_items_nullable_prop => [%{optional(String.t) => any()}] | nil,
:array_items_nullable => [%{optional(String.t) => any()}] | nil,
:object_nullable_prop => %{optional(String.t) => any()} | nil,
:object_and_items_nullable_prop => %{optional(String.t) => any()} | nil,
:object_items_nullable => %{optional(String.t) => any()} | nil
}

alias OpenapiPetstore.Deserializer
Expand Down
Loading