edh_phoenix_swagger v0.1.3 PhoenixSwagger.JsonApi

This module defines a DSL for defining swagger definitions in a JSON-API conformant format.s

Examples

import PhoenixSwagger

swagger_definitions do
  JsonApi.resource(:User, :Users) do
    description "A user that may have one or more supporter pages."
    attributes do
      user_updated_at :string, "Last update timestamp UTC", format: "ISO-8601"
      user_created_at :string, "First created timestamp UTC"
      street_address :string, "Street address"
    end
  end
end

Summary

Functions

Defines an attribute of a JSON-API model having the given schema

Defines an attribute in a JSON-API schema

Defines a link with name and description

Defines a schema for a top level json-api document with an array of resources as primary data. This is used automatically from the JsonApi.resource macro is used

Defines a relationship

Defines a schema for a top level json-api document with a single primary data resource. This is used automatically from the JsonApi.resource macro is used

Macros

Defines a block of attributes for a JSON-API resource. Within this block, each function call will be translated into a call to the PhoenixSwagger.JsonApi.attribute function

Defines schemas for a JSON-API resource, without a pluralized paginated version

Defines schemas for a JSON-API resource, with a pluralized paginated version

Functions

attribute(schema, name, attr_schema)

Defines an attribute of a JSON-API model having the given schema.

attribute(schema, name, type, description, opts \\ [])

Defines an attribute in a JSON-API schema.

Name, type and description are accepted as positional arguments, but any other schema properties can be set through the trailing keyword arguments list. As a convenience, required: true can be passed in the keyword args, causing the name of this attribute to be added to the “required” list of the attributes schema.

link(schema, name, description)

Defines a link with name and description

page(resource)

Defines a schema for a top level json-api document with an array of resources as primary data. This is used automatically from the JsonApi.resource macro is used.

relationship(schema, name)

Defines a relationship

single(resource)

Defines a schema for a top level json-api document with a single primary data resource. This is used automatically from the JsonApi.resource macro is used.

Macros

attributes(model, list)

Defines a block of attributes for a JSON-API resource. Within this block, each function call will be translated into a call to the PhoenixSwagger.JsonApi.attribute function.

Example

description("A User")
attributes do
  name :string, "Full name of the user", required: true
  dateOfBirth :string, "Date of Birth", format: "ISO-8601", required: false
end

translates to:

description("A User")
|> attribute(:name, :string, "Full name of the user", required: true)
|> attribute(:dateOfBirth, :string, "Date of Birth", format: "ISO-8601", required: false)
resource(name, expr)

Defines schemas for a JSON-API resource, without a pluralized paginated version.

resource(name, plural, expr)

Defines schemas for a JSON-API resource, with a pluralized paginated version.