-
Notifications
You must be signed in to change notification settings - Fork 205
Open
Labels
Description
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 (
open_api_spex/lib/open_api_spex/schema_resolver.ex
Lines 200 to 249 in e4deef5
| 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 |
Reactions are currently unavailable