OpenAPITools / OpenAPITools/openapi-generator

[BUG] v7.0.0 Elixir Deserialization Regression

Open
#16,412 11 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the regression with the string enum example and inspect the generated lib/ory/deserializer.ex and Ory.Model.AuthenticatorAssuranceLevel output. The reproduction path is documented through scripts/generate.sh and clients/client/elixir/. Compare the behavior introduced by #16061; done means generated enum modules deserialize valid values without the FunctionClauseError.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.