ExScim.Schema.Builder (ex_scim v0.2.2)

Copy Markdown View Source

DSL for defining SCIM schemas declaratively.

This module provides macros for building RFC 7643-compliant SCIM schema definitions in a clean, readable format.

Example

defmodule MyApp.Schemas.User do
  use ExScim.Schema.Builder

  schema "urn:ietf:params:scim:schemas:core:2.0:User" do
    name "User"
    description "User Account"

    attribute :userName, :string, required: true, uniqueness: :server
    attribute :active, :boolean

    attribute :name, :complex do
      sub_attribute :givenName, :string
      sub_attribute :familyName, :string
    end

    attribute :emails, :complex, multi_valued: true do
      sub_attribute :value, :string
      sub_attribute :type, :string, canonical_values: ["work", "home", "other"]
      sub_attribute :primary, :boolean
    end
  end
end

Generated Functions

Using this module generates the following functions:

  • schema_id/0 - Returns the schema URI
  • to_map/0 - Returns the complete schema as a map
  • __schema__/0 - Returns schema metadata (for internal use)

Summary

Functions

Defines a simple attribute with name and type.

Defines an attribute with options, or a complex attribute with sub-attributes.

Defines a complex attribute with both options and sub-attributes.

Sets the description for the schema.

Sets the human-readable name for the schema.

Defines a SCIM schema with the given URI identifier.

Defines a sub-attribute within a complex attribute block.

Functions

attribute(name, type)

(macro)

Defines a simple attribute with name and type.

Example

attribute :active, :boolean

attribute(name, type, opts_or_block)

(macro)

Defines an attribute with options, or a complex attribute with sub-attributes.

Simple attribute with options

attribute :userName, :string, required: true, uniqueness: :server

Complex attribute with sub-attributes

attribute :name, :complex do
  sub_attribute :givenName, :string
  sub_attribute :familyName, :string
end

Options

  • :required - boolean, default false
  • :multi_valued - boolean, default false
  • :case_exact - boolean, default false (only for string/reference types)
  • :mutability - atom, one of :read_write, :read_only, :write_only, :immutable
  • :returned - atom, one of :default, :always, :never, :request
  • :uniqueness - atom, one of :none, :server, :global
  • :canonical_values - list of strings
  • :reference_types - list of strings (only for reference type)
  • :description - string

attribute(name, type, opts, list)

(macro)

Defines a complex attribute with both options and sub-attributes.

Example

attribute :emails, :complex, multi_valued: true do
  sub_attribute :value, :string
  sub_attribute :type, :string, canonical_values: ["work", "home", "other"]
  sub_attribute :primary, :boolean
end

description(value)

(macro)

Sets the description for the schema.

name(value)

(macro)

Sets the human-readable name for the schema.

schema(schema_id, list)

(macro)

Defines a SCIM schema with the given URI identifier.

The block should contain name/1, description/1, and attribute calls.

Example

schema "urn:ietf:params:scim:schemas:core:2.0:User" do
  name "User"
  description "User Account"
  # attributes...
end

sub_attribute(name, type, opts \\ [])

(macro)

Defines a sub-attribute within a complex attribute block.

Must be called inside an attribute ... do ... end block.

Example

attribute :name, :complex do
  sub_attribute :givenName, :string
  sub_attribute :familyName, :string, description: "The family name"
end

Options

Same options as attribute/3, with the addition of :include_uniqueness which forces uniqueness to be included even for boolean types.