Context
spectra:schema/4 pattern-matches on json_schema as a literal format atom (lines ~421-424), and maybe_codec_schema/2 hardcodes json_schema when calling M:schema/3.
This means adding a second schema format (e.g. OpenAPI 3.1 as a distinct format atom) requires duplicating those clauses.
Proposed change
- Replace hardcoded
json_schema atoms with a dynamic format parameter threaded through schema/4 and maybe_codec_schema.
- Each format module registers or is dispatched to based on the format atom, rather than being baked into
spectra.erl clauses.
Benefit
New schema formats can be added without modifying spectra.erl.
Raised from PR #122 review (comments on lines 423 and 451).
Context
spectra:schema/4pattern-matches onjson_schemaas a literal format atom (lines ~421-424), andmaybe_codec_schema/2hardcodesjson_schemawhen callingM:schema/3.This means adding a second schema format (e.g. OpenAPI 3.1 as a distinct format atom) requires duplicating those clauses.
Proposed change
json_schemaatoms with a dynamic format parameter threaded throughschema/4andmaybe_codec_schema.spectra.erlclauses.Benefit
New schema formats can be added without modifying
spectra.erl.Raised from PR #122 review (comments on lines 423 and 451).