Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): Formal Schemas for Signed Docs #208

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bf256dd
docs(docs): Add wip files for formal signed document schemas
stevenj Feb 13, 2025
21f8bb3
Merge branch 'main' into wip/document-schemas
stevenj Feb 13, 2025
011b6f1
docs: wip
stevenj Feb 16, 2025
4292ad1
feat: wip
stevenj Feb 27, 2025
03edade
feat: Signed Docs formal specs WIP
stevenj Mar 1, 2025
0b748b9
feat: Add draft7 jsonschema to meta templates schema definitions
stevenj Mar 1, 2025
68ca7a5
Merge branch 'main' into wip/document-schemas
stevenj Mar 2, 2025
d312830
feat: Add CI actions to check generated data matches schema
stevenj Mar 2, 2025
faf4663
Merge branch 'wip/document-schemas' of github.com:input-output-hk/cat…
stevenj Mar 2, 2025
532cc92
fix: try and fix project name for CI
stevenj Mar 2, 2025
f38eca8
fix: remove obsolete files
stevenj Mar 2, 2025
79ca3e0
fix: fix markdown
stevenj Mar 2, 2025
577417e
fix: spelling
stevenj Mar 2, 2025
018cb4e
fix: Make sure json version of document specifications is sorted to m…
stevenj Mar 2, 2025
38798aa
feat: Add base types information to the json version of the document …
stevenj Mar 2, 2025
b3a93a2
fix: add recommended justfile extension for vscode
stevenj Mar 2, 2025
7bed21c
feat: Example of building docs directly from specification data
stevenj Mar 2, 2025
4b9f6da
fix: spelling
stevenj Mar 2, 2025
39bbe30
fix: Spelling and Markdown
stevenj Mar 2, 2025
044878d
feat: Add documentation auto generation for new signed documents
stevenj Mar 5, 2025
2191d7f
feat: Add status which allows a reference to define one or multiple r…
stevenj Mar 5, 2025
a103636
feat: Add three states to document submission and change the names to…
stevenj Mar 5, 2025
d7f7cbd
feat: Rationalize ref/ref_hash and collation into a single `ref` meta…
stevenj Mar 5, 2025
e95ad7d
feat: Fix validation issues
stevenj Mar 5, 2025
e2363f0
feat: Signed Doc defintion improvements WIP
stevenj Mar 7, 2025
0167244
feat: Signed docs Docs generation WIP
stevenj Mar 7, 2025
3820bad
feat(docs): Formal signed doc specs auto markdown generation WIP
stevenj Mar 12, 2025
52cf095
feat(docs): Add start of individual documentation pages for each sign…
stevenj Mar 18, 2025
654cd6d
Merge branch 'main' into wip/document-schemas
stevenj Mar 18, 2025
8ed52f8
Merge branch 'main' into wip/document-schemas
stevenj Mar 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ crontabs
crontagged
csprng
cstring
cuelang
dalek
dashmap
Datelike
Expand Down Expand Up @@ -123,6 +124,7 @@ jorm
jormungandr
Jörmungandr
jsonschema
Justfile
kiduri
lcov
Leay
Expand Down Expand Up @@ -200,6 +202,7 @@ pubkey
publickey
pubspec
pwrite
pytest
qpsg
quic
rapidoc
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ $RECYCLE.BIN/
# Dart stuff
/pubspec.lock
/.dart_tool/**/*

# Python stuff
.pytest_cache
__pycache__
3 changes: 2 additions & 1 deletion .markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ignores": [
".config/dictionaries/**",
"**/target/**",
"**/.dart_tool/**"
"**/.dart_tool/**",
"**/.pytest_cache/**"
],
// Set standard config options in `/.markdownlint.jsonc`
"config": {
Expand Down
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
"dtsvet.vscode-wasm",
"terrastruct.d2",
"fill-labs.dependi",
"nefrob.vscode-just-syntax",
"charliermarsh.ruff",
"ms-python.python",
]
}
15 changes: 14 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ check-spelling:
earthly +check-spelling


# Fix and Check Markdown files
format-python-code:
ruff check --select I --fix .
ruff format .

# Fix and Check Markdown files
lint-python:
ruff check .

# generates specifications data
gen_specs:
just specs/pre-push

# Pre Push Checks - intended to be run by a git pre-push hook.
pre-push: check-markdown check-spelling
pre-push: gen_specs check-markdown check-spelling format-python-code lint-python
just rust/pre-push
4 changes: 4 additions & 0 deletions docs/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ IMPORT github.com/input-output-hk/catalyst-ci/earthly/docs:v3.3.0 AS docs-ci


IMPORT .. AS repo
IMPORT ../specs AS specs

# Copy all the source we need to build the docs
src:
Expand All @@ -13,6 +14,9 @@ src:
# Now copy into that any artifacts we pull from the builds.
COPY --dir repo+repo-docs/repo /docs/includes

# Copy our generated Signed Document Specification data.
COPY specs+src/signed_doc.json /docs/includes


# Build the docs here.
docs:
Expand Down
54 changes: 54 additions & 0 deletions docs/macros/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from .include import inc_file
from .signed_docs import (
cose_header_parameters,
doc_type_details,
doc_type_summary,
external_links,
signed_doc_details,
)


def define_env(env):
"""
This is the hook for defining variables, macros and filters
"""

@env.macro
def include_file(filename, start_line=0, end_line=None, indent=None):
# Provided by the base mkdocs config.
return inc_file(env, filename, start_line, end_line, indent)

@env.macro
def insert_doc_type_summary():
try:
return doc_type_summary(env)
except Exception as exc:
return f"Macro Expansion Error: {exc}"

@env.macro
def insert_doc_type_details():
try:
return doc_type_details(env)
except Exception as exc:
return f"Macro Expansion Error: {exc}"

@env.macro
def insert_cose_header_parameters():
try:
return cose_header_parameters(env)
except Exception as exc:
return f"Macro Expansion Error: {exc}"

@env.macro
def insert_signed_doc_details(name):
try:
return signed_doc_details(env, name)
except Exception as exc:
return f"Macro Expansion Error: {exc}"

@env.macro
def insert_external_links():
try:
return external_links(env)
except Exception as exc:
return f"Macro Expansion Error: {exc}"
201 changes: 201 additions & 0 deletions docs/macros/signed_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import json
import os

# import re
# import textwrap

if __name__ == "__main__":
SIGNED_DOCS_SPECS = "signed_doc.json"
else:
SIGNED_DOCS_SPECS = "includes/signed_doc.json"


def uuid_as_cbor(uuid):
return f"37(h'{uuid.replace('-', '')}')"


def get_signed_doc_data(env):
"""
Load the Signed Document Data from its json file.
"""
full_filename = os.path.join(env.project_dir, SIGNED_DOCS_SPECS)

with open(full_filename, "r") as f:
return json.load(f)


def doc_type_summary(env):
"""
Generate a Document Base Type Summary from the Document Specifications Data
"""

doc_data = get_signed_doc_data(env)
doc_types = doc_data["base_types"]

doc_type_summary = """
| Base Type | [UUID] | [CBOR] |
| :--- | :--- | :--- |
"""

for k in doc_types:
doc_type_summary += (
f"| {k} | `{doc_types[k]}` | `{uuid_as_cbor(doc_types[k])}` |\n"
)

return doc_type_summary


def name_for_uuid(doc_types, uuid):
"""
Get the name for a document base type, given its uuid
"""
for k in doc_types:
if doc_types[k] == uuid:
return k
return "Unknown"


def name_to_spec_link(name, ref=None):
"""
Create a link to a document type, and an optional ref inside the document.
"""
link = "./../catalyst_docs/" + name.lower().replace(" ", "_") + ".md"
if ref is not None:
link += f"#{ref}"
return link


def base_types(docs, doc_types, name):
types = docs[name]["type"]
type_names = ""
for sub_type in types:
type_names += name_for_uuid(doc_types, sub_type) + "/"
return type_names[:-1]


def types_as_cbor(docs, name):
types = docs[name]["type"]
type_names = "["
for sub_type in types:
type_names += uuid_as_cbor(sub_type) + ",<br/>"
return type_names[:-6] + "]"


def doc_type_details(env):
"""
Generate a Document Type Detailed Summary from the Document Specifications Data
"""

doc_data = get_signed_doc_data(env)
doc_types = doc_data["base_types"]
docs = doc_data["docs"]

doc_type_details = """
| Document Type | Base Types | [CBOR] | Specification |
| :--- | :--- | :--- | :--- |
"""

for k in docs:
doc_type_details += f"| {k} | {base_types(docs, doc_types, k)} | {types_as_cbor(docs, k)} | [Specification]({name_to_spec_link(k)}) | \n"

return doc_type_details


def external_links(env):
"""
Insert External Links we might have used in descriptions.
"""
doc_data = get_signed_doc_data(env)
links = doc_data["documentationLinks"]

link_display = ""
for name in links:
link_display += f"[{name}]: {links[name]}\n"

return link_display


def metadata_fields(env, doc_name=None):
"""
Display Metadata fields for the default set, or a specific document.
"""
doc_data = get_signed_doc_data(env)
if doc_name is not None:
fields = doc_data["docs"][doc_name]["metadata"]
field_title_level = "###"
else:
fields = doc_data["metadata"]
field_title_level = "##"

order = doc_data["metadata_order"]

# make sure every field is listed in the ordering
for field_name in fields:
if field_name not in order:
order += field_name

field_display = ""
for field_name in order:
field = fields[field_name]
field_display += f"""
{field_title_level} `{field_name}`

| Parameter | Value |
| --- | --- |
| Required | {field["required"]} |
"""
if field["required"] != "excluded":
field_display += f"| Format | {field['format']} |\n"
if "multiple" in field:
field_display += f"| Multiple References | {field['multiple']} |\n"
if "type" in field:
ref_heading = "Valid References"
ref_doc_names = field["type"]
if isinstance(ref_doc_names, str):
ref_doc_names = [ref_doc_names]
for ref_doc in ref_doc_names:
field_display += f"| {ref_heading} | {ref_doc} |\n"
ref_heading = ""

field_display += f"""
{field["description"]}

{field_title_level}# Validation

{field["validation"]}
"""
return field_display


def signed_doc_details(env, name):
"""
Generate Signed Document Detailed Documentation Page.
"""
return name + "\n" + "test\n"


# run as a program to debug the macros
if __name__ == "__main__":

class env:
project_dir = "/home/steven/Development/iohk/catalyst-libs/specs"

print()
print("### DOC TYPE DETAILS ###")
print(doc_type_details(env))

print()
print("### DOC TYPE SUMMARY ###")
print(doc_type_summary(env))

print()
print("### COSE HEADER PARAMETERS ###")
print(cose_header_parameters(env))

print()
print("### EXTERNAL LINKS ###")
print(external_links(env))

print()
print("### GLOBAL METADATA ###")
print(metadata_fields(env))
4 changes: 0 additions & 4 deletions docs/src/architecture/08_concepts/catalyst_docs/.pages
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
title: Catalyst Documents
arrange:
- proposal.md
- review.md
- comment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# {{ insert_signed_doc_details( "Brand Parameters" ) }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# {{ insert_signed_doc_details( "Campaign Parameters" ) }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# {{ insert_signed_doc_details( "Category Parameters" ) }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# {{ insert_signed_doc_details( "Comment Action Document" ) }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# {{ insert_signed_doc_details( "Election Parameters" ) }}
Loading
Loading