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 ¶
- Variables
- type Adherence
- type AdherenceLevel
- type Chapter
- type Component
- type ComponentName
- type Contact
- type Criterion
- type Option
- func WithAuthor(name, email string) Option
- func WithAuthorCompany(name, email, companyName string) Option
- func WithCatalog(catalogID string) Option
- func WithEvaluationMethods(methods string) Option
- func WithFeedback(feedback string) Option
- func WithLegalDisclaimer(disclaimer string) Option
- func WithLicense(license string) Option
- func WithNotes(notes string) Option
- func WithProduct(name, version string) Option
- func WithProductDescription(name, version, description string) Option
- func WithReportDate(date string) Option
- func WithReportDateNow() Option
- func WithRepository(url string) Option
- func WithTitle(title string) Option
- func WithVendor(name, email string) Option
- func WithVersion(version int) Option
- type Product
- type RelatedOpenACR
- type Report
- func (r *Report) JSON() ([]byte, error)
- func (r *Report) Save(path string) error
- func (r *Report) Validate() []ValidationError
- func (r *Report) ValidateAgainstCatalog(cat *catalog.Catalog) []ValidationError
- func (r *Report) WriteJSON(w io.Writer) error
- func (r *Report) WriteYAML(w io.Writer) error
- func (r *Report) YAML() ([]byte, error)
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
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 ¶
WithAuthor sets the author name and email.
func WithAuthorCompany ¶
WithAuthorCompany sets the author with company information.
func WithCatalog ¶
WithCatalog sets the catalog ID for the report.
func WithEvaluationMethods ¶
WithEvaluationMethods sets the evaluation methods used.
func WithFeedback ¶
WithFeedback sets the feedback information.
func WithLegalDisclaimer ¶
WithLegalDisclaimer sets the legal disclaimer.
func WithProduct ¶
WithProduct sets the product name and version.
func WithProductDescription ¶
WithProductDescription sets the product with name, version, and description.
func WithReportDateNow ¶
func WithReportDateNow() Option
WithReportDateNow sets the report date to today.
func WithRepository ¶
WithRepository sets the repository URL.
func WithVendor ¶
WithVendor sets the vendor contact information.
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 ¶
Load reads an OpenACR report from a file. The file format is determined by the file extension (.yaml, .yml, or .json).
func LoadJSONBytes ¶
LoadJSONBytes reads an OpenACR report from JSON bytes.
func LoadYAMLBytes ¶
LoadYAMLBytes reads an OpenACR report from YAML bytes.
func (*Report) Save ¶
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.
type ValidationError ¶
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.
Source Files
¶
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. |