at https://hexdocs.pm/open_api_spex/3.2.0/readme.html there’s a definition of a module User
defmodule MyApp.Schemas do
alias OpenApiSpex.Schema
defmodule User do
@behaviour OpenApiSpex.Schema
@derive [Jason.Encoder]
@schema %Schema{
title: "User",
description: "A user of the app",
type: :object,
properties: %{
id: %Schema{type: :integer, description: "User ID"},
name: %Schema{type: :string, description: "User name"},
email: %Schema{type: :string, description: "Email address", format: :email},
inserted_at: %Schema{type: :string, description: "Creation timestamp", format: :datetime},
updated_at: %Schema{type: :string, description: "Update timestamp", format: :datetime}
},
required: [:name, :email],
example: %{
"id" => 123,
"name" => "Joe",
"email" => "[email protected]"
}
"x-struct": __MODULE__
}
def schema, do: @schema
defstruct Map.keys(@schema.properties)
end
In order to avoid re-describing it like that for Open API Specs whilst having already done so for Ecto, is it possible to combine the two definitions in a single module somehow? That is, my Ecto schema User would serve its purpose for Open API Specs too. With some required tweaks.
And if I do combine them, won’t this mess up with the methods of the 2 modules and other things?
You must log in or register to comment.