Skip to content

Bump GOBL to v0.508.0 and add conversions via the convert register - #63

Open
samlown wants to merge 2 commits into
mainfrom
convert
Open

samlown wants to merge 2 commits into
mainfrom
convert

Conversation

@samlown

@samlown samlown commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Upgrades GOBL to v0.508.0 and adds conversions between GOBL and external formats, built on GOBL's new convert register. This supersedes #22: rather than a hand-maintained list of formats, gobl.dev offers exactly the formats that the bundled converters register.

Conversions

  • Bundle — gobl.ubl v0.86.0 and gobl.cii v0.69.0 are blank-imported next to the addons. Together they register ubl+en16931-v2017, ubl+peppol+bis-v3, cii+en16931-v2017 and cii+peppol+bis-v3. They also register import-only fallbacks (ubl, cii) for detection.

  • internal/ops — Formats, Import and Export wrap the register. Export wraps documents in an envelope and calculates unsigned envelopes first, so drafts export directly.

  • CLI — gobl convert:

    gobl convert invoice.json invoice.xml --to ubl+en16931-v2017   # export; --to takes keys in order of preference
    gobl convert -i invoice.xml                                    # import, format detected (--from limits it)
    gobl convert --list -i                                         # registered formats
  • API — GET /v0/formats, POST /v0/import and POST /v0/export?format=… (repeated or comma-separated). The body is raw, so XML can be posted directly. The format used comes back in the GOBL-Format header, which CORS exposes. + in keys can be left unescaped in the query. The OpenAPI spec is updated.

  • Editor — three modes:

    • Build: unchanged. The source is replaced with the built document.
    • Export: the source is left untouched. The server builds it and converts it, and the result shows in a read-only viewer. A format is offered only if it exports the document's schema and every addon it needs is declared by the document (including addons pulled in by requires, which GOBL expands on build).
    • Import: a separate XML input is converted through /v0/import, and the resulting envelope shows in the viewer.

    The mode, example and format choices persist across reloads.

  • Examples — editor/examples/*.json, a bare-minimum document per region: US, UK, Spain (plain and VERI*FACTU), Germany (EN 16931 and XRechnung), France and the Netherlands (EN 16931), Italy (SDI), Portugal (SAF-T) and Mexico (CFDI). Labels come from the regime and addon registries. Each example has only the fields its build needs, plus series/code where a format requires an invoice number. In import mode, an example is loaded as the output of its first export format.

Changes from #22

  • The HTML preview is gone: gobl.html doesn't register with the convert register, and it still targets GOBL 0.504. FatturaPA is out for the same reason.
  • XRechnung, Factur-X/ZUGFeRD and the French CTC formats aren't offered yet. They'll appear automatically once the regional packages release with RegisterFormats.
  • The examples are reduced to the bare minimum and picked by region, without the Accept-Language default.
  • No addons are injected during export. As the convert README recommends, documents must already include the addons a format requires (e.g. eu-en16931-v2017). Otherwise the export fails with not-supported.

GOBL v0.508.0 and module updates

Module Version
gobl v0.507.0 → v0.508.0
gobl.ar.arca new, v0.0.3 (ar-arca-v4 moved out of core)
gobl.co.dian new, v0.0.3 (co-dian-v2 moved out of core)
gobl.fi.finvoice v0.0.2 → v0.0.6
gobl.it.sdi v0.81.0 → v0.83.0
gobl.mx.cfdi v0.64.0 → v0.68.0
gobl.pl.ksef v0.45.0 → v0.47.0

Changes needed for 0.508.0:

  • data/addons was removed upstream. Addon definitions were already served from the registry, so only a TestListDataDir subtest is dropped.
  • The schema descriptions were shortened and a new tax/filter schema added, so the correction-options snapshots and bulk schema expectations are refreshed.

Testing

  • go test -race ./... passes. There are new tests for ops, CLI, API and editor, including UBL/CII export → import round trips, preference order, unknown and unsupported formats, and restricted detection.
  • I smoke-tested the gobl.dev server with curl: the page renders the picker, and /v0/formats, /v0/export and /v0/import work end to end.
  • I drove the editor in headless Chromium through every mode: build, export with format filtering and requirement expansion (XRechnung → EN 16931), switching formats, an unsupported document, and import with an invalid input. I also checked dark mode and that preferences persist across a reload.
  • Every example builds and exports into every format the editor would offer it, except the known gap below.

⚠️ Known gap: ubl+peppol+bis-v3

This format also exports bill/status, so in the convert register it declares no addons. The EN 16931 requirement for invoices is checked only in gobl.ubl's Accepts. Matching on addons therefore offers UBL Peppol for any invoice, including the US example, and the export then fails with not-supported. Fixing this needs the register to expose per-schema addon requirements (or an "accepts" check) upstream in GOBL's convert.

🤖 Generated with Claude Code

Upgrade GOBL to v0.508.0 and offer conversions between GOBL and external
formats through its new convert package. Only formats registered with the
register are offered, replacing the hand-maintained format list of #22.

Modules:

  gobl             v0.507.0 -> v0.508.0
  gobl.ar.arca     new      v0.0.3   (ar-arca-v4 moved out of core)
  gobl.co.dian     new      v0.0.3   (co-dian-v2 moved out of core)
  gobl.ubl         new      v0.86.0  (registers ubl+ formats)
  gobl.cii         new      v0.69.0  (registers cii+ formats)
  gobl.fi.finvoice v0.0.2  -> v0.0.6
  gobl.it.sdi      v0.81.0 -> v0.83.0
  gobl.mx.cfdi     v0.64.0 -> v0.68.0
  gobl.pl.ksef     v0.45.0 -> v0.47.0

GOBL 0.508.0 changes handled:

- The ARCA and DIAN addons now live in their own modules; blank-import
  both in the bundle so the approved addon test passes.
- data/addons was removed. Addon definitions are already served from the
  registry, so only the TestListDataDir subtest reading it is dropped.
- Shortened schema descriptions and the new tax/filter schema: refresh
  the correction options snapshots and the bulk schema expectations.

Conversions:

- internal/ops: Formats, Import and Export wrap the convert register.
  Export envelops documents and calculates unsigned envelopes first, so
  drafts can be exported directly.
- CLI: `gobl convert` exports with --to (keys in order of preference),
  imports with format detection otherwise (--from limits it), and lists
  the formats with --list.
- API: GET /v0/formats, POST /v0/import and POST /v0/export?format=,
  taking raw bodies. The format used is returned in a GOBL-Format header,
  exposed through CORS. Unescaped "+" in keys is accepted.
- Editor: an Export picker lists the registered export formats and shows
  the result in a read-only XML pane beside the editor, via /v0/export.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.01835% with 231 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.98%. Comparing base (215e9b7) to head (cd41f81).

Files with missing lines Patch % Lines
editor/editor_templ.go 0.00% 193 Missing ⚠️
editor/formats.go 80.76% 9 Missing and 1 partial ⚠️
internal/ops/convert.go 68.75% 5 Missing and 5 partials ⚠️
cmd/gobl/convert.go 88.23% 4 Missing and 4 partials ⚠️
editor/examples.go 84.61% 4 Missing and 4 partials ⚠️
api/convert.go 94.11% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
- Coverage   72.56%   68.98%   -3.59%     
==========================================
  Files          48       53       +5     
  Lines        1994     2399     +405     
==========================================
+ Hits         1447     1655     +208     
- Misses        467      649     +182     
- Partials       80       95      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Rework the editor around three modes:

- Build: as before, the GOBL source is replaced with the built document.
- Export: the source is left untouched; /v0/export builds it internally
  and the result is shown in a read-only viewer. The formats offered are
  those registered with the convert package whose export schemas include
  the document's schema and whose addons are all declared by it, after
  expanding addon requirements as GOBL does when building.
- Import: a separate XML input is converted through /v0/import, and the
  resulting envelope is shown in the viewer.

Add bare-minimum example documents for the US, UK, Spain (with and without
VERI*FACTU), Germany (EN 16931 and XRechnung), France and the Netherlands
(EN 16931), Italy (SDI), Portugal (SAF-T) and Mexico (CFDI). Their region
and label are derived from the regime and addon registries, loaded lazily
so externally implemented addons are registered first. In import mode an
example is offered as the output of its first export format.

Tests build every example and export it into every format the editor
would offer it. ubl+peppol+bis-v3 is recorded as a known gap: it also
exports bill/status, so the EN 16931 addon it needs for invoices is only
checked in Accepts and is missing from the register's metadata.

The mode, example and format are remembered in localStorage.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants