Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clash of different schemas with the same title #587

Open
juise opened this issue Dec 25, 2023 · 0 comments
Open

Clash of different schemas with the same title #587

juise opened this issue Dec 25, 2023 · 0 comments

Comments

@juise
Copy link

juise commented Dec 25, 2023

In case I have two schema definitions with the same title, one schema is overwritten by another:

  defmodule Wallet do
    require OpenApiSpex

    OpenApiSpex.schema(%{
      title: "Wallet",
  ...

and

  defmodule GeneralizedWallet do
    require OpenApiSpex

    OpenApiSpex.schema(%{
      title: "Wallet",
  ...

in this case, I every time got GeneralizedWallet instead of Wallet in places where it's awaited in request_body. It seems like the problem in schema_resolver.resolve_schema_modules_from_schema/2 (

defp resolve_schema_modules_from_schema(schema, schemas) when is_atom(schema) do
title = schema.schema().title
new_schemas =
if Map.has_key?(schemas, title) do
schemas
else
{new_schema, schemas} = resolve_schema_modules_from_schema(schema.schema(), schemas)
Map.put(schemas, title, new_schema)
end
{%Reference{"$ref": "#/components/schemas/#{title}"}, new_schemas}
end
defp resolve_schema_modules_from_schema(schema = %Schema{title: title}, schemas) do
schemas =
if is_nil(title) do
schemas
else
Map.put(schemas, title, schema)
end
{all_of, schemas} = resolve_schema_modules_from_schema(schema.allOf, schemas)
{one_of, schemas} = resolve_schema_modules_from_schema(schema.oneOf, schemas)
{any_of, schemas} = resolve_schema_modules_from_schema(schema.anyOf, schemas)
{not_schema, schemas} = resolve_schema_modules_from_schema(schema.not, schemas)
{items, schemas} = resolve_schema_modules_from_schema(schema.items, schemas)
{additional, schemas} = resolve_schema_modules_from_schema(schema.additionalProperties, schemas)
{properties, schemas} =
resolve_schema_modules_from_schema_properties(schema.properties, schemas)
{discriminator, schemas} =
resolve_schema_modules_from_discriminator(schema.discriminator, schemas)
schema = %{
schema
| allOf: all_of,
oneOf: one_of,
anyOf: any_of,
not: not_schema,
items: items,
additionalProperties: additional,
properties: properties,
discriminator: discriminator
}
{schema, schemas}
end
). It seems like it should be some pre-processing entities in compile time to verify such clash?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant