OpenApiSpex.SchemaResolver (open_api_spex v3.21.3)

View Source

Internal module used to resolve OpenApiSpex.Schema structs from atoms.

Summary

Functions

Adds schemas to the api spec from the modules specified in the Operations.

Functions

resolve_schema_modules(spec)

@spec resolve_schema_modules(OpenApiSpex.OpenApi.t()) :: OpenApiSpex.OpenApi.t()

Adds schemas to the api spec from the modules specified in the Operations.

Eg, if the response schema for an operation is defined with:

responses: %{
  200 => Operation.response("User", "application/json", UserResponse)
}

Then the UserResponse.schema() function will be called to load the schema, and a Reference to the loaded schema will be used in the operation response.

See OpenApiSpex.schema/2 macro for a convenient syntax for defining schema modules.

Known Issues

Resolving schemas expects the schema title to be unique for the generated references to be unique.

For schemas defined with the OpenApiSpex.schema/2 macro, the title is automatically set to the last part of module name. For example MyAppWeb.Schemas.User will have the title "User", and MyAppWeb.OtherSchemas.User will also have the title "User" which can lead to conflicts.

The recommendation is to set the title explicitly in the schema definition.