openacr

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 10 Imported by: 0

README

OpenACR Go SDK

Go CI Go Lint Go SAST Go Report Card Docs Visualization License

Go library for working with OpenACR (Open Accessibility Conformance Report) documents.

OpenACR is a machine-readable format for accessibility conformance reports, based on the VPAT (Voluntary Product Accessibility Template) format. This library supports reading, writing, and validating OpenACR documents in both YAML and JSON formats.

Installation

go get github.com/plexusone/openacr-go

Quick Start

Load an existing report
import "github.com/plexusone/openacr-go"

report, err := openacr.Load("report.yaml")
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Product: %s %s\n", report.Product.Name, report.Product.Version)
Create a new report
report := openacr.NewReport(
    openacr.WithProduct("My Product", "1.0.0"),
    openacr.WithAuthor("Jane Doe", "jane@example.com"),
    openacr.WithCatalog("2.5-edition-wcag-2.2-508-en"),
    openacr.WithReportDateNow(),
)

// Add chapter evaluations
report.Chapters["success_criteria_level_a"] = openacr.Chapter{
    Criteria: []openacr.Criterion{
        {
            Num: "1.1.1",
            Components: []openacr.Component{
                {
                    Name: openacr.ComponentWeb,
                    Adherence: openacr.Adherence{
                        Level: openacr.LevelSupports,
                        Notes: "All images have appropriate alt text.",
                    },
                },
            },
        },
    },
}
Validate a report
// Basic validation
errs := report.Validate()
for _, err := range errs {
    fmt.Printf("Validation error: %s\n", err)
}

// Validate against a catalog
cat, _ := catalog.Get("2.5-edition-wcag-2.2-508-en")
errs = report.ValidateAgainstCatalog(cat)
Save a report
// Save as YAML
err := report.Save("report.yaml")

// Save as JSON
err = report.Save("report.json")

// Get bytes
yamlBytes, _ := report.YAML()
jsonBytes, _ := report.JSON()

Catalogs

The catalog subpackage provides access to embedded accessibility standard catalogs from the GSA OpenACR project:

import "github.com/plexusone/openacr-go/catalog"

// List available catalogs
catalogs := catalog.List()
// ["2.5-edition-wcag-2.2-508-en", "2.5-edition-wcag-2.1-508-en", ...]

// Get a catalog
cat, err := catalog.Get("2.5-edition-wcag-2.2-508-en")
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Catalog: %s\n", cat.Title)

Schema Validation

The schema subpackage provides JSON Schema validation:

import "github.com/plexusone/openacr-go/schema"

validator, err := schema.NewValidator()
if err != nil {
    log.Fatal(err)
}

jsonData, _ := report.JSON()
if err := validator.Validate(jsonData); err != nil {
    log.Printf("Schema validation failed: %v", err)
}

Adherence Levels

The following adherence levels are supported:

Level Description
supports The functionality meets the criterion without known defects
partially-supports Some functionality does not meet the criterion
does-not-support The majority of functionality does not meet the criterion
not-applicable The criterion is not relevant to the product
not-evaluated The product has not been evaluated (WCAG AAA only)

Component Types

The following component types are supported:

Component Description
web Web content
electronic-docs Electronic documents
software Software applications
authoring-tool Authoring tools
none No specific component

Available Catalogs

The following catalogs are embedded:

  • 2.5-edition-wcag-2.2-508-en - WCAG 2.2 with Section 508 (latest)
  • 2.5-edition-wcag-2.2-508-eu-en - WCAG 2.2 with Section 508 and EU standards
  • 2.5-edition-wcag-2.2-en - WCAG 2.2 only
  • 2.5-edition-wcag-2.1-508-en - WCAG 2.1 with Section 508
  • 2.5-edition-wcag-2.0-508-en - WCAG 2.0 with Section 508
  • 2.4-edition-wcag-2.1-508-en - WCAG 2.1 with Section 508 (2.4 edition)
  • 2.4-edition-wcag-2.1-508-eu-en - WCAG 2.1 with Section 508 and EU (2.4 edition)
  • 2.4-edition-wcag-2.1-en - WCAG 2.1 only (2.4 edition)
  • 2.4-edition-wcag-2.0-508-en - WCAG 2.0 with Section 508 (2.4 edition)

License

MIT License - see LICENSE file.

References

  • GSA OpenACR - Original OpenACR specification
  • VPAT - Voluntary Product Accessibility Template
  • WCAG - Web Content Accessibility Guidelines

Documentation

Overview

Package openacr provides types and utilities for working with OpenACR (Open Accessibility Conformance Report) documents.

OpenACR is a machine-readable format for accessibility conformance reports, based on the VPAT (Voluntary Product Accessibility Template) format. This package supports reading, writing, and validating OpenACR documents in both YAML and JSON formats.

Basic Usage

Load an existing OpenACR report:

report, err := openacr.Load("report.yaml")
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Product: %s %s\n", report.Product.Name, report.Product.Version)

Create a new report:

report := openacr.NewReport(
    openacr.WithProduct("My Product", "1.0.0"),
    openacr.WithAuthor("Jane Doe", "jane@example.com"),
    openacr.WithCatalog("2.5-edition-wcag-2.2-508-en"),
)

Validate a report:

errors := report.Validate()
for _, err := range errors {
    fmt.Printf("Validation error: %s\n", err)
}

Catalogs

The catalog subpackage provides access to embedded accessibility standard catalogs from the GSA OpenACR project:

cat, err := catalog.Get("2.5-edition-wcag-2.2-508-en")
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Catalog: %s\n", cat.Title)

Schema Validation

The schema subpackage provides JSON Schema validation:

validator, err := schema.NewValidator()
if err != nil {
    log.Fatal(err)
}
if err := validator.Validate(jsonData); err != nil {
    log.Printf("Schema validation failed: %v", err)
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidFormat is returned when a file has an unsupported format.
	ErrInvalidFormat = errors.New("invalid format: must be .yaml, .yml, or .json")

	// ErrEmptyProductName is returned when the product name is empty.
	ErrEmptyProductName = errors.New("product name is required")

	// ErrEmptyAuthorEmail is returned when the author email is empty.
	ErrEmptyAuthorEmail = errors.New("author email is required")

	// ErrInvalidCatalog is returned when a catalog ID is not found.
	ErrInvalidCatalog = errors.New("catalog not found")

	// ErrInvalidChapter is returned when a chapter ID is not in the catalog.
	ErrInvalidChapter = errors.New("chapter not found in catalog")

	// ErrInvalidCriterion is returned when a criterion is not in the catalog chapter.
	ErrInvalidCriterion = errors.New("criterion not found in catalog chapter")

	// ErrInvalidComponent is returned when a component name is not valid.
	ErrInvalidComponent = errors.New("invalid component name")

	// ErrInvalidAdherenceLevel is returned when an adherence level is not valid.
	ErrInvalidAdherenceLevel = errors.New("invalid adherence level")
)

Common errors returned by openacr functions.

Functions

This section is empty.

Types

type Adherence

type Adherence struct {
	// Level is the conformance level.
	Level AdherenceLevel `json:"level" yaml:"level"`

	// Notes contains additional information about the conformance status.
	Notes string `json:"notes,omitempty" yaml:"notes,omitempty"`
}

Adherence represents the conformance status of a criterion for a component.

type AdherenceLevel

type AdherenceLevel string

AdherenceLevel represents the level of accessibility conformance.

const (
	LevelSupports          AdherenceLevel = "supports"
	LevelPartiallySupports AdherenceLevel = "partially-supports"
	LevelDoesNotSupport    AdherenceLevel = "does-not-support"
	LevelNotApplicable     AdherenceLevel = "not-applicable"
	LevelNotEvaluated      AdherenceLevel = "not-evaluated"
)

Valid adherence levels as defined by OpenACR/VPAT.

func ValidAdherenceLevels

func ValidAdherenceLevels() []AdherenceLevel

ValidAdherenceLevels returns all valid adherence levels.

func (AdherenceLevel) IsValid

func (a AdherenceLevel) IsValid() bool

IsValid returns true if the adherence level is valid.

type Chapter

type Chapter struct {
	// Notes contains chapter-level notes.
	Notes string `json:"notes,omitempty" yaml:"notes,omitempty"`

	// Disabled indicates whether this chapter is disabled/not applicable.
	Disabled bool `json:"disabled,omitempty" yaml:"disabled,omitempty"`

	// Criteria is the list of criteria evaluations in this chapter.
	Criteria []Criterion `json:"criteria,omitempty" yaml:"criteria,omitempty"`
}

Chapter represents a chapter in an OpenACR report containing accessibility evaluation criteria.

type Component

type Component struct {
	// Name is the component type being evaluated.
	Name ComponentName `json:"name" yaml:"name"`

	// Adherence contains the conformance level and notes.
	Adherence Adherence `json:"adherence,omitempty" yaml:"adherence,omitempty"`
}

Component represents an evaluation of a specific component type.

type ComponentName

type ComponentName string

ComponentName represents the type of product component being evaluated.

const (
	ComponentWeb           ComponentName = "web"
	ComponentElectronicDoc ComponentName = "electronic-docs"
	ComponentSoftware      ComponentName = "software"
	ComponentAuthoringTool ComponentName = "authoring-tool"
	ComponentNone          ComponentName = "none"
)

Valid component names as defined by OpenACR.

func ValidComponentNames

func ValidComponentNames() []ComponentName

ValidComponentNames returns all valid component names.

func (ComponentName) IsValid

func (c ComponentName) IsValid() bool

IsValid returns true if the component name is valid.

type Contact

type Contact struct {
	// Name is the name of the contact person.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	// CompanyName is the name of the company or organization.
	CompanyName string `json:"company_name,omitempty" yaml:"company_name,omitempty"`

	// Address is the physical address.
	Address string `json:"address,omitempty" yaml:"address,omitempty"`

	// Email is the email address.
	Email string `json:"email" yaml:"email"`

	// Phone is the phone number.
	Phone string `json:"phone,omitempty" yaml:"phone,omitempty"`

	// Website is the website URL.
	Website string `json:"website,omitempty" yaml:"website,omitempty"`
}

Contact represents contact information for a person or organization.

type Criterion

type Criterion struct {
	// Num is the criterion number/identifier (e.g., "1.1.1").
	Num string `json:"num" yaml:"num"`

	// Components contains the evaluation results for each component type.
	Components []Component `json:"components,omitempty" yaml:"components,omitempty"`
}

Criterion represents an individual accessibility criterion evaluation.

type Option

type Option func(*Report)

Option is a functional option for configuring a Report.

func WithAuthor

func WithAuthor(name, email string) Option

WithAuthor sets the author name and email.

func WithAuthorCompany

func WithAuthorCompany(name, email, companyName string) Option

WithAuthorCompany sets the author with company information.

func WithCatalog

func WithCatalog(catalogID string) Option

WithCatalog sets the catalog ID for the report.

func WithEvaluationMethods

func WithEvaluationMethods(methods string) Option

WithEvaluationMethods sets the evaluation methods used.

func WithFeedback

func WithFeedback(feedback string) Option

WithFeedback sets the feedback information.

func WithLegalDisclaimer

func WithLegalDisclaimer(disclaimer string) Option

WithLegalDisclaimer sets the legal disclaimer.

func WithLicense

func WithLicense(license string) Option

WithLicense sets the license.

func WithNotes

func WithNotes(notes string) Option

WithNotes sets the report notes.

func WithProduct

func WithProduct(name, version string) Option

WithProduct sets the product name and version.

func WithProductDescription

func WithProductDescription(name, version, description string) Option

WithProductDescription sets the product with name, version, and description.

func WithReportDate

func WithReportDate(date string) Option

WithReportDate sets the report date.

func WithReportDateNow

func WithReportDateNow() Option

WithReportDateNow sets the report date to today.

func WithRepository

func WithRepository(url string) Option

WithRepository sets the repository URL.

func WithTitle

func WithTitle(title string) Option

WithTitle sets the report title.

func WithVendor

func WithVendor(name, email string) Option

WithVendor sets the vendor contact information.

func WithVersion

func WithVersion(version int) Option

WithVersion sets the report version number.

type Product

type Product struct {
	// Name is the name of the product.
	Name string `json:"name" yaml:"name"`

	// Version is the version of the product.
	Version string `json:"version,omitempty" yaml:"version,omitempty"`

	// Description is a description of the product.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
}

Product describes the product being evaluated.

type RelatedOpenACR

type RelatedOpenACR struct {
	// URL is the URL of the related report.
	URL string `json:"url,omitempty" yaml:"url,omitempty"`

	// Type describes the relationship type.
	Type string `json:"type,omitempty" yaml:"type,omitempty"`
}

RelatedOpenACR references another OpenACR report.

type Report

type Report struct {
	// Title is the title of the report.
	Title string `json:"title,omitempty" yaml:"title,omitempty"`

	// Product describes the product being evaluated.
	Product Product `json:"product" yaml:"product"`

	// Author is the person or organization that authored the report.
	Author Contact `json:"author" yaml:"author"`

	// Vendor is the product vendor (optional, may differ from author).
	Vendor *Contact `json:"vendor,omitempty" yaml:"vendor,omitempty"`

	// ReportDate is the date the report was created (YYYY-MM-DD format).
	ReportDate string `json:"report_date,omitempty" yaml:"report_date,omitempty"`

	// LastModifiedDate is the date the report was last modified (YYYY-MM-DD format).
	LastModifiedDate string `json:"last_modified_date,omitempty" yaml:"last_modified_date,omitempty"`

	// Version is the version number of the report.
	Version int `json:"version,omitempty" yaml:"version,omitempty"`

	// Notes contains general notes about the report.
	Notes string `json:"notes,omitempty" yaml:"notes,omitempty"`

	// EvaluationMethods describes the evaluation methods used.
	EvaluationMethods string `json:"evaluation_methods_used,omitempty" yaml:"evaluation_methods_used,omitempty"`

	// LegalDisclaimer is the legal disclaimer for the report.
	LegalDisclaimer string `json:"legal_disclaimer,omitempty" yaml:"legal_disclaimer,omitempty"`

	// License is the license under which the report is published.
	License string `json:"license,omitempty" yaml:"license,omitempty"`

	// Repository is the URL of the repository containing the report.
	Repository string `json:"repository,omitempty" yaml:"repository,omitempty"`

	// Feedback is information about how to provide feedback on the report.
	Feedback string `json:"feedback,omitempty" yaml:"feedback,omitempty"`

	// RelatedOpenACRs lists related OpenACR reports.
	RelatedOpenACRs []RelatedOpenACR `json:"related_openacrs,omitempty" yaml:"related_openacrs,omitempty"`

	// Catalog is the ID of the catalog used for this report.
	Catalog string `json:"catalog,omitempty" yaml:"catalog,omitempty"`

	// Chapters contains the accessibility evaluation results by chapter.
	Chapters map[string]Chapter `json:"chapters,omitempty" yaml:"chapters,omitempty"`
}

Report represents an OpenACR accessibility conformance report.

func Load

func Load(path string) (*Report, error)

Load reads an OpenACR report from a file. The file format is determined by the file extension (.yaml, .yml, or .json).

func LoadJSON

func LoadJSON(r io.Reader) (*Report, error)

LoadJSON reads an OpenACR report from a JSON reader.

func LoadJSONBytes

func LoadJSONBytes(data []byte) (*Report, error)

LoadJSONBytes reads an OpenACR report from JSON bytes.

func LoadYAML

func LoadYAML(r io.Reader) (*Report, error)

LoadYAML reads an OpenACR report from a YAML reader.

func LoadYAMLBytes

func LoadYAMLBytes(data []byte) (*Report, error)

LoadYAMLBytes reads an OpenACR report from YAML bytes.

func NewReport

func NewReport(opts ...Option) *Report

NewReport creates a new Report with the given options.

func (*Report) JSON

func (r *Report) JSON() ([]byte, error)

JSON returns the report as JSON bytes.

func (*Report) Save

func (r *Report) Save(path string) error

Save writes the report to a file. The file format is determined by the file extension (.yaml, .yml, or .json).

func (*Report) Validate

func (r *Report) Validate() []ValidationError

Validate performs basic validation on the report and returns any validation errors. This checks required fields and valid values without requiring a catalog.

func (*Report) ValidateAgainstCatalog

func (r *Report) ValidateAgainstCatalog(cat *catalog.Catalog) []ValidationError

ValidateAgainstCatalog validates the report against a specific catalog. This checks that all chapters and criteria exist in the catalog.

func (*Report) WriteJSON

func (r *Report) WriteJSON(w io.Writer) error

WriteJSON writes the report as JSON to the given writer.

func (*Report) WriteYAML

func (r *Report) WriteYAML(w io.Writer) error

WriteYAML writes the report as YAML to the given writer.

func (*Report) YAML

func (r *Report) YAML() ([]byte, error)

YAML returns the report as YAML bytes.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
	Err     error
}

ValidationError represents a validation error with context.

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface.

func (ValidationError) Unwrap

func (e ValidationError) Unwrap() error

Unwrap returns the underlying error.

Directories

Path Synopsis
Package catalog provides access to embedded OpenACR accessibility standard catalogs.
Package catalog provides access to embedded OpenACR accessibility standard catalogs.
examples
basic command
Example demonstrates basic usage of the openacr package.
Example demonstrates basic usage of the openacr package.
Package schema provides JSON Schema validation for OpenACR documents.
Package schema provides JSON Schema validation for OpenACR documents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL