Skip to content

Validate generated fiscal XML against versioned official XSD bundles #48

Description

@vitormattos

Parent epic: #47

Context

The library has a reference schema snapshot, but schema validation must become an explicit compatibility contract rather than a set of string assertions. Other NFS-e implementations validate generated XML against the official XSD in tests, which catches element order, optionality, enums and version drift.

Current production documentation publishes NFS-e XSD v1.01 and related DPS/NFS-e/event layouts.

Goal

Create a versioned schema subsystem and CI tests that validate every generated DPS/event XML against the exact official schema release the library claims to support.

Scope

  • keep official XSD snapshots under a versioned path with source URL, publication date and checksum metadata
  • expose an internal/schema-test helper that validates XML with libxml using local files only
  • validate representative DPS scenarios: taxable, retained ISS, immunity, export, suspended enforceability, IBS/CBS, foreign taker, alphanumeric CNPJ
  • validate cancellation and future event payloads
  • fail with useful schema diagnostics
  • add a documented update procedure for a new official schema release

Constraints

  • never download schemas during tests or runtime
  • preserve exact official files; do not hand-edit XSD contents
  • XML parsing must disable network/external entity resolution
  • supporting a new schema version must be an explicit change

Tests

  • valid fixtures pass
  • wrong element order fails
  • invalid enum fails
  • unsupported schema version fails clearly
  • XXE/network resolution remains disabled

Definition of done

  • all generated fiscal XML classes covered by XSD tests
  • schema source/checksum/version documented
  • CI executes validation on supported PHP versions
  • no network dependency in test execution

Implementation status (2026-10-04)

Already present on main:

  • official NFS-e/DPS 1.01 XSD bundle under references/schemas/nfse/1.01;
  • local-only DpsSchemaValidator using libxml schema validation;
  • representative DPS XSD contract tests, including newer fiscal groups;
  • schema source/version documentation in the bundled README.

Remaining work for this issue:

  • extend versioned schema coverage to generated event XML and any other generated fiscal XML classes, not only DPS;
  • make checksum/source metadata mechanically verifiable rather than descriptive only;
  • document/rehearse the update procedure for a new official schema release;
  • add explicit unsupported-version and XXE/network-resolution regression coverage if not already equivalent.

Do not duplicate the existing DPS validator/bundle.

Activity

  1. vitormattos commented on Oct 4, 2026

    @vitormattos
    MemberAuthor

    Implementation status after #81:

    • the versioned 1.01 bundle now also contains the production NFSe_v1.01.xsd
    • representative signed complete NFS-e generated for the decision flow is schema-validated
    • schema/manual contradiction around nDFSe=0 is captured explicitly by regression coverage

    This advances but does not complete #48. Event XML coverage, unsupported-version/XXE regressions, and full mechanically verified schema metadata/update coverage still need to be checked.

  2. vitormattos commented on Oct 4, 2026

    @vitormattos
    MemberAuthor

    Completed after #81 and #83.

    Coverage now includes:

    • versioned official 1.01 DPS, event, and complete NFS-e schemas
    • local-only libxml validation for generated DPS/event/NFS-e documents
    • representative valid fiscal scenarios including decision-flow complete NFS-e
    • wrong element/order and unsupported-version regressions
    • external-entity/network-resolution regressions
    • mechanically verified Git-blob integrity manifest for the vendored official bundle
    • documented source/package/publication metadata and new-version update procedure

    #83 completed the remaining complete-NFS-e schema guard coverage and passed all repository gates before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions