Skip to content

Commit 7aa3290

Browse files
authored
Generate JSON docs statically (#112)
* Generate JSON docs statically * Ensure example domains are FQDNs
1 parent 738b7ec commit 7aa3290

File tree

6 files changed

+1604
-34
lines changed

6 files changed

+1604
-34
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ asngen
88
src/dns_zone_lexer.erl
99
src/dns_zone_parser.erl
1010

11-
# Generated documentation
12-
src/JSON_FORMAT.md
13-
1411
# local setup
1512
.tool-versions
1613

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ rfc-list-print:
5050
./scripts/generate_rfc_list.escript
5151

5252
.PHONY: check-no-change-action
53-
check-no-change-action: rfc-list
53+
check-no-change-action: rfc-list json-docs
54+
git diff --quiet --exit-code src/JSON_FORMAT.md
5455
git diff --quiet --exit-code SUPPORTED_RFCS.md

rebar.config

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
{test, [
3737
{deps, [{proper, "~> 1.5"}]},
3838
{erl_opts, [nowarn_export_all, nowarn_missing_spec, nowarn_missing_doc]},
39-
{eunit_opts, [verbose]},
40-
{covertool, [{coverdata_files, ["eunit.coverdata", "ct.coverdata"]}]},
39+
{covertool, [{coverdata_files, ["ct.coverdata"]}]},
4140
{cover_excl_mods, [dns_zone_lexer, dns_zone_parser]},
4241
{cover_opts, [verbose, {min_coverage, 80}]},
4342
{cover_export_enabled, true},
@@ -50,12 +49,6 @@
5049
{post, [{clean, {asn, clean}}]}
5150
]}.
5251

53-
{pre_hooks, [
54-
%% Generate JSON_FORMAT.md before ex_doc
55-
{compile, "escript scripts/generate_json_docs.escript --output src/JSON_FORMAT.md || true"},
56-
{edoc, "escript scripts/generate_json_docs.escript --output src/JSON_FORMAT.md || true"}
57-
]}.
58-
5952
{dialyzer, [
6053
{warnings, [
6154
no_return,

scripts/generate_json_docs.escript

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,19 @@ extract_binary_key_regex(Expr) ->
408408
generate_documentation(Records, EncodingRules, KeyMappings) ->
409409
InitAcc =
410410
~"""
411+
# JSON format
412+
411413
This document describes the JSON encoding format for all DNS record types.
412414
413415
## Format Structure
414416
415417
### Resource Records (RR)
416418
417419
Resource records (`dns_rr`) are encoded as follows:
420+
418421
```json
419422
{
420-
"name": "example.com",
423+
"name": "example.com.",
421424
"type": "A",
422425
"class": "in",
423426
"ttl": 3600,
@@ -428,6 +431,7 @@ generate_documentation(Records, EncodingRules, KeyMappings) ->
428431
```
429432
430433
The format includes:
434+
431435
- `name`: Domain name (binary)
432436
- `type`: DNS type name as uppercase string (e.g., "A", "AAAA", "MX")
433437
- `ttl`: Time to live (integer)
@@ -437,6 +441,7 @@ generate_documentation(Records, EncodingRules, KeyMappings) ->
437441
### Other Records
438442
439443
Non-RR records (message, query, OPT records) use a two-level nested map format:
444+
440445
- Outer key: Record type identifier (descriptive name)
441446
- Inner map: Record fields with binary keys
442447
@@ -662,7 +667,7 @@ encoding_description(direct, FieldName, TypeStr) ->
662667
ip ->
663668
~"IP address as string";
664669
svc_params when HasSvcbParams ->
665-
~"Map of SVCB service parameters (see [SVCB Service Parameters below](#module-svcb-service-parameters))";
670+
~"Map of SVCB service parameters (see [SVCB Service Parameters below](#svcb-service-parameters))";
666671
_ when HasDname orelse HasBinary -> ~"Binary data (dname format)";
667672
_ ->
668673
~"Direct value"
@@ -694,6 +699,7 @@ generate_example(RecordName, Fields, KeyBin, Acc, EncodingRules) ->
694699
),
695700
<<
696701
Acc/binary,
702+
"\n",
697703
"**Example:**\n\n",
698704
"```json\n",
699705
"{\n",
@@ -717,10 +723,11 @@ generate_example_rr_format(_Fields, Acc) ->
717723
%% showing the structure with common fields
718724
<<
719725
Acc/binary,
726+
"\n",
720727
"**Example:**\n\n",
721728
"```json\n",
722729
"{\n",
723-
" \"name\": \"example.com\",\n",
730+
" \"name\": \"example.com.\",\n",
724731
" \"type\": \"A\",\n",
725732
" \"class\": \"IN\",\n",
726733
" \"ttl\": 3600,\n",
@@ -729,6 +736,7 @@ generate_example_rr_format(_Fields, Acc) ->
729736
" }\n",
730737
"}\n",
731738
"```\n\n",
739+
"\n",
732740
"**Note:** The `data` field contains the RRDATA-specific fields. ",
733741
"The `class` field is optional and defaults to `\"IN\"` if omitted. ",
734742
"See individual RRDATA record types below for complete field documentation.\n\n"
@@ -743,13 +751,15 @@ generate_example_rrdata_format(RecordName, Fields, Acc, EncodingRules) ->
743751
ExampleFieldsStr = format_example_fields(Fields, FieldNameFun, RecordName, EncodingRules),
744752
<<
745753
Acc/binary,
754+
"\n",
746755
"**Example:**\n\n",
747756
"```json\n",
748757
"{\n",
749758
ExampleFieldsStr/binary,
750759
"\n",
751760
"}\n",
752761
"```\n\n",
762+
"\n",
753763
"**Note:** This format is used within the `data` field of `dns_rr` records.\n\n"
754764
>>.
755765

@@ -814,13 +824,14 @@ example_category_map() ->
814824
example_value_map() ->
815825
#{
816826
ip => ~"\"192.168.1.1\"",
817-
name => ~"\"example.com\"",
818-
dname => ~"\"example.com\"",
819-
hostname => ~"\"example.com\"",
820-
exchange => ~"\"mail.example.com\"",
821-
target => ~"\"target.example.com\"",
822-
mname => ~"\"ns1.example.com\"",
823-
rname => ~"\"admin.example.com\"",
827+
name => ~"\"example.com.\"",
828+
dname => ~"\"example.com.\"",
829+
hostname => ~"\"example.com.\"",
830+
exchange => ~"\"mail.example.com.\"",
831+
target => ~"\"target.example.com.\"",
832+
target_name => ~"\"target.example.com.\"",
833+
mname => ~"\"ns1.example.com.\"",
834+
rname => ~"\"admin.example.com.\"",
824835
ttl => ~"3600",
825836
svc_params => ~"{\"alpn\": [\"h2\", \"h3\"], \"port\": 443}"
826837
}.
@@ -914,7 +925,7 @@ generate_svcb_params_section() ->
914925
```json
915926
{
916927
"svc_priority": 1,
917-
"target_name": "target.example.com",
928+
"target_name": "target.example.com.",
918929
"svc_params": {
919930
"mandatory": ["alpn", "port"],
920931
"alpn": ["h2", "h3"],

0 commit comments

Comments
 (0)