Skip to content

Clash of different schemas with the same title  #587

@juise

Description

@juise

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions