Facturx.Validate (Facturx v0.2.0)

Copy Markdown View Source

Optional Schematron validation against the EN 16931 business rules.

The EN 16931 Schematron compiles to XSLT 2.0, which the BEAM cannot run. Like the Python akretion/factur-x library, we delegate to a Saxon server over HTTP (req — declared optional so non-validating callers don't pull an HTTP client). The compiled schematron XSLT ships in priv/schematron/.

Run a Saxon server (e.g. ghcr.io/willemvlh/saxon-server, port 5000) and point :endpoint at its /transform route. The transform is sent the XML and the XSLT as a multipart/form-data body and returns an SVRL report, which we interpret into failed-assert / successful-report violations.

Privacy: a public Saxon endpoint means sending real invoice data to a third party. Self-host the Saxon server in production.

{:ok, :valid} = Facturx.validate(xml, profile: :en16931,
                                 endpoint: "http://localhost:5000/transform")

Only the :en16931 schematron ships today; other profiles return {:error, {:schematron_not_bundled, profile}}.

Summary

Types

A schematron violation.

Functions

Validate xml against the EN 16931 Schematron via a Saxon endpoint.

Types

violation()

@type violation() :: %{
  message: String.t() | nil,
  location: String.t() | nil,
  test: String.t() | nil
}

A schematron violation.

Functions

validate(xml, opts \\ [])

@spec validate(
  binary(),
  keyword()
) :: {:ok, :valid} | {:error, {:invalid, [violation()]}} | {:error, term()}

Validate xml against the EN 16931 Schematron via a Saxon endpoint.

Options:

  • :endpoint — Saxon /transform URL (defaults to the app env config :facturx, Facturx.Validate, endpoint: ..., then "http://localhost:5000/transform")
  • :profile — schematron level (defaults to the profile detected in the XML)
  • :codedb_url — override the code-list DB URL the XSLT resolves
  • :receive_timeout — HTTP receive timeout (ms), default 20_000