-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
#16061 appears to have introduced a bug when attempting to deserialize a string into an enum model.
** (FunctionClauseError) no function clause matching in Ory.Deserializer.to_struct/2
(ory_client 1.1.50) lib/ory/deserializer.ex:97: Ory.Deserializer.to_struct("aal1", Ory.Model.AuthenticatorAssuranceLevel)
Here we see to_struct/2 being called on the value of "aal1", to be decoded into the Ory.Model.AuthenticatorAssuranceLevel model. However there is no implementation from this.
This is a regression from the prior generators, and the expected output is to be able to deserialize into these modules/structs.
openapi-generator version
v7.0.0
OpenAPI declaration file content or url
Any string-typed enum field, for example this from the Ory SDK
"authenticatorAssuranceLevel": {
"description": "The authenticator assurance level can be one of \"aal1\", \"aal2\", or \"aal3\". A higher number means that it is harder\nfor an attacker to compromise the account.\n\nGenerally, \"aal1\" implies that one authentication factor was used while AAL2 implies that two factors (e.g.\npassword + TOTP) have been used.\n\nTo learn more about these levels please head over to: https://www.ory.sh/kratos/docs/concepts/credentials",
"enum": [
"aal0",
"aal1",
"aal2",
"aal3"
],
"title": "Authenticator Assurance Level (AAL)",
"type": "string"
},
Generation Details
The above spec will output the following model module.
# NOTE: This file is auto generated by OpenAPI Generator 7.0.0 (https://openapi-generator.tech).
# Do not edit this file manually.
defmodule Ory.Model.AuthenticatorAssuranceLevel do
@moduledoc """
The authenticator assurance level can be one of \"aal1\", \"aal2\", or \"aal3\". A higher number means that it is harder for an attacker to compromise the account. Generally, \"aal1\" implies that one authentication factor was used while AAL2 implies that two factors (e.g. password + TOTP) have been used. To learn more about these levels please head over to: https://www.ory.sh/kratos/docs/concepts/credentials
"""
@derive Jason.Encoder
defstruct [
]
@type t :: %__MODULE__{
}
def decode(value) do
value
end
end
Steps to reproduce
Generate any OpenAPI schema with an enum string model and you will get this. For further testing using the Ory SDK, you can checkout my fork and generate the elixir client by commenting out lines 235-333 in scripts/generate.sh and running $ FORCE_PROJECT=client FORCE_VERSION=(cat spec/client/latest) ./scripts/generate.sh to invoke the openapi-generator-cli to generate the client at clients/client/elixir/.
Related issues/PRs
#16061 Introduced this regression
Suggest a fix.
Implement a way to deserialize enum modules. Ideally this would go further and implement a word list to validate whether a string value is a valid enum when trying to deserialize into the