Skip to content

Sharing common definitions #243

@char0n

Description

@char0n

Is there an idiomatic way how to share Schemas not specific to any controller ? Like Error definition. I found a way how to do it, but not sure if there is a better way/solution.

  @doc false
  def swagger_definitions do
    %{
      ApiToken:
        JsonApi.resource do
          description("Standard pong response")

          attributes do
            revoked(:boolean, "Is the API Token revoked?", default: false)

            revoked_at(:string, "Date and time of API Token revocation",
              format: "date-time",
              default: nil
            )

            description(:string, "Description associated with API Token", default: nil)

            issued_at(:string, "Date and time of API Token issuance",
              format: "date-time",
              default: nil
            )
          end
        end,
      Error: swagger_definitions_common()[:Error]
    }
  end

I have a swagger_definitions_common in different module and I just import the function and call it to give me the Error schema for current controller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions