ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
139 stars 86 forks source link

Generated Elixir module names clash #229

Open paulbalomiri opened 1 year ago

paulbalomiri commented 1 year ago

Preflight checklist

Bug Description

Generated Elixir module names such as Ory.Connection clash. Elixir dependencies cannot override each other's Modules, but the generated code does contain the same module name in different dependencies:

Examples:

https://github.com/ory/sdk/blob/2324e5c13c45d43c7e7b3cdc5ebc86b86b627867/clients/client/elixir/lib/ory/connection.ex#L5

https://github.com/ory/sdk/blob/2324e5c13c45d43c7e7b3cdc5ebc86b86b627867/clients/hydra/elixir/lib/ory/connection.ex#L5

https://github.com/ory/sdk/blob/2324e5c13c45d43c7e7b3cdc5ebc86b86b627867/clients/keto/elixir/lib/ory/connection.ex#L5

https://github.com/ory/sdk/blob/2324e5c13c45d43c7e7b3cdc5ebc86b86b627867/clients/oathkeeper/elixir/lib/ory/connection.ex#L5

https://github.com/ory/sdk/blob/2324e5c13c45d43c7e7b3cdc5ebc86b86b627867/clients/kratos/elixir/lib/ory/connection.ex#L5

https://github.com/ory/sdk/blob/2324e5c13c45d43c7e7b3cdc5ebc86b86b627867/clients/client/elixir/lib/ory/connection.ex#L5 This is a follwup to this comment https://github.com/ory/sdk/issues/194#issuecomment-1318133766

Reproducing the bug

Create any library importing e.g. at least 2 packages: Example snippet from mix.exs:

defp deps do
    [
     ...
      {:ory_client, github: "ory/sdk", sparse: "clients/client/elixir/"},
      {:ory_hydra, github: "ory/sdk", sparse: "clients/hydra/elixir/"}
     ]
  end

Relevant log output

when building/running lots of warnings such as this one is logged:

warning: redefining module Ory.Connection (current version loaded from /workspace/cantex_umbrella/_build/dev/lib/ory_client/ebin/Elixir.Ory.Connection.beam)
  lib/ory/connection.ex:5

Relevant configuration

Here is the Variable setting, to which I propose to add this line:

export ELIXIR_INVOKER_MODULE="Ory.${PROJECT^}"

https://github.com/ory/sdk/blob/2324e5c13c45d43c7e7b3cdc5ebc86b86b627867/scripts/prep.sh#L85 And here the line 3 should be changed to

invokerPackage: ${ELIXIR_INVOKER_MODULE}

https://github.com/ory/sdk/blob/2324e5c13c45d43c7e7b3cdc5ebc86b86b627867/config/client/elixir.yml#L1-L3

This results in package names such as Ory.Hydra.Connection

Version

latest stable versions

Additional Context

@aeneasr I'm putting here the questions I have for understanding & documentation, These are mostly issues to get the PR right.

I'll come back with a PR on this, I've already forked the sdk. The bug is easy to solve, but perhaps a followup documentation issue would benefit from those questions.

It's a rather long post, so feel free to only discuss in context of the upcoming PR.

paulbalomiri commented 1 year ago

I have created this upstream PR to Openapi-generator

I might transform the changes, or do a complete rewrite of the generator into a custom generator for this project if the pain pressure gets too high, as i'm planning to use all apis from elixir in a self-deployed setup.

aeneasr commented 1 year ago

Awesome, thank you so much for your work @paulbalomiri :) Please let me know how it goes :)

paulbalomiri commented 1 year ago

I have some personal urgency until thursday. In the meantime i'll find out whether this will be a custom generator or i can formulate an upstream PR to openapi-generator. I think i'll know this week.