@@ -2,6 +2,7 @@ defmodule OpenApiSpex.SchemaResolver do
2
2
@ moduledoc """
3
3
Internal module used to resolve `OpenApiSpex.Schema` structs from atoms.
4
4
"""
5
+
5
6
alias OpenApiSpex.Discriminator
6
7
7
8
alias OpenApiSpex . {
@@ -29,7 +30,17 @@ defmodule OpenApiSpex.SchemaResolver do
29
30
Then the `UserResponse.schema()` function will be called to load the schema, and
30
31
a `Reference` to the loaded schema will be used in the operation response.
31
32
32
- See `OpenApiSpex.schema` macro for a convenient syntax for defining schema modules.
33
+ See `OpenApiSpex.schema/2` macro for a convenient syntax for defining schema modules.
34
+
35
+ > #### Known Issues {: .info}
36
+ >
37
+ > Resolving schemas expects the schema title to be unique for the generated references to be unique.
38
+ >
39
+ > For schemas defined with the `OpenApiSpex.schema/2` macro, the title is automatically set
40
+ > to the last part of module name. For example `MyAppWeb.Schemas.User` will have the title `"User"`,
41
+ > and `MyAppWeb.OtherSchemas.User` **will also** have the title `"User"` which can lead to conflicts.
42
+ >
43
+ > The recommendation is to set the title explicitly in the schema definition.
33
44
"""
34
45
@ spec resolve_schema_modules ( OpenApi . t ( ) ) :: OpenApi . t ( )
35
46
def resolve_schema_modules ( spec = % OpenApi { } ) do
@@ -197,14 +208,15 @@ defmodule OpenApiSpex.SchemaResolver do
197
208
Enum . map_reduce ( schema_list , schemas , & resolve_schema_modules_from_schema / 2 )
198
209
end
199
210
200
- defp resolve_schema_modules_from_schema ( schema , schemas ) when is_atom ( schema ) do
201
- title = schema . schema ( ) . title
211
+ defp resolve_schema_modules_from_schema ( schema_module , schemas ) when is_atom ( schema_module ) do
212
+ schema = schema_module . schema ( )
213
+ title = schema . title
202
214
203
215
new_schemas =
204
216
if Map . has_key? ( schemas , title ) do
205
217
schemas
206
218
else
207
- { new_schema , schemas } = resolve_schema_modules_from_schema ( schema . schema ( ) , schemas )
219
+ { new_schema , schemas } = resolve_schema_modules_from_schema ( schema , schemas )
208
220
Map . put ( schemas , title , new_schema )
209
221
end
210
222
0 commit comments