Skip to content

Standardize Reader/Writer public API naming and return types #20

@StephanMeijer

Description

@StephanMeijer

Problem

Every reader and writer module exposes a different function name and return shape, making the library harder to learn and use consistently.

Module Entry function Returns
DOCX.Reader open!/1convert!/1close!/1 Bare struct (raises)
Tiptap.Reader convert/1 {:ok, spec} | {:error, ...}
HTML.Writer convert/1 String.t() (bare, no error path)
EPUB.Writer convert!/1 / convert!/2 Mixed (see #19)
Tiptap.Writer convert/1 {:ok, element} | {:error, ...}
BlockNote.Writer write/1 {:ok, content} | {:error, ...}
Validation.Writer validate/1 [Finding.t()] (bare list)

Specific inconsistencies

  1. BlockNote.Writer.write/1 uses write while all other writers use convert
  2. HTML.Writer.convert/1 returns a bare string with no error tuple — no way to handle conversion failures
  3. DOCX.Reader requires a 3-step open/convert/close lifecycle; Tiptap.Reader is a single convert/1 call
  4. Validation.Writer — the module is named "Writer" but the public function is validate/1, which is semantically correct but structurally confusing given the module hierarchy

Proposal

Standardize on:

  • convert/1{:ok, result} | {:error, reason} (all readers and writers)
  • convert!/1result or raises (convenience bang variant)
  • DOCX Reader: provide a single-call convert/1 that handles the open/convert/close lifecycle internally, keeping the granular API available for advanced use

Files

  • lib/docspec/core/blocknote/writer.ex
  • lib/docspec/core/html/writer.ex
  • lib/docspec/core/epub/writer.ex
  • lib/docspec/core/tiptap/reader.ex
  • lib/docspec/core/tiptap/writer.ex
  • lib/docspec/core/docx/reader.ex
  • lib/docspec/core/validation/writer.ex

Notes

This is a breaking change. Consider whether Validation.Writer should be renamed to DocSpec.Core.Validation since it doesn't "write" output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions