Created by: mrmstn
Fixes #14070 (closed)
This PR will handle AnyType
as primitives to prevent the generator from generating specific classes, since in elixir structs cannot have any extra undefined files. This will also result in AnyType
parameters not be serialized in any other way than Poison interprets it.
Since the Pet Store doesn't have some good examples to see the results of this change, here's a Dummy Spec:
openapi: 3.0.3
info:
title: Dummy Spec
version: 1.0.11
servers:
- url: https://dummy.example.com/api
paths:
/quotas:
get:
operationId: GetQuotas
responses:
"200":
$ref: '#/components/responses/GetQuotasResponse'
tags:
- Enterprise
/dummy:
get:
operationId: GetQuotas
responses:
"200":
$ref: '#/components/responses/GetJobScaleStatusResponse'
tags:
- Enterprise
components:
schemas:
ConsulGateway:
properties:
Mesh: {}
type: object
responses:
GetJobScaleStatusResponse:
description: ""
content:
application/json:
schema:
$ref: '#/components/schemas/ConsulGateway'
GetQuotasResponse:
content:
application/json:
schema:
items: {}
type: array
description: ""
The Spec contains two interesting parts. First, there is the ConsulGateway
with the Mesh
properties, with no further definition.
Secondly, there is the GetQuotasResponse
with an array of AnyType
objects.
--- a/lib/nomad_client/api/enterprise.ex
+++ b/lib/nomad_client/api/enterprise.ex
@@ -21,7 +21,7 @@ defmodule NomadClient.Api.Enterprise do
- `{:ok, [%AnyType{}, ...]}` on success
- `{:error, Tesla.Env.t}` on failure
"""
- @spec get_quotas(Tesla.Env.client, keyword()) :: {:ok, list(NomadClient.Model.AnyType.t)} | {:error, Tesla.Env.t}
+ @spec get_quotas(Tesla.Env.client, keyword()) :: {:ok, list(any())} | {:error, Tesla.Env.t}
def get_quotas(connection, _opts \\ []) do
request =
%{}
@@ -32,7 +32,7 @@ defmodule NomadClient.Api.Enterprise do
connection
|> Connection.request(request)
|> evaluate_response([
- {200, [%NomadClient.Model.AnyType{}]}
+ {200, []}
])
end
As you can see in the upper diff. The generator won't interpret the undefined list as %NomadClient.Model.AnyType{}
anymore, but uses []
instead.
--- a/lib/nomad_client/model/consul_gateway.ex
+++ b/lib/nomad_client/model/consul_gateway.ex
@@ -12,15 +12,13 @@ defmodule NomadClient.Model.ConsulGateway do
]
@type t :: %__MODULE__{
- :Mesh => AnyType | nil
+ :Mesh => any() | nil
}
end
defimpl Poison.Decoder, for: NomadClient.Model.ConsulGateway do
- import NomadClient.Deserializer
- def decode(value, options) do
+ def decode(value, _options) do
value
- |> deserialize(:Mesh, :struct, NomadClient.Model.AnyType, options)
end
end
In the upper diff, you can see that Mesh
will not be decoded to the not existing NomadClient.Model.AnyType
anymore. Mesh
will not be serialized to a struct and will be left as is from Poison
@halostatue or @wing328 I would be honored if you could review my changes.
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
(6.3.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks) -
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.