Skip to content

Commit

Permalink
[#79] adding a new script to generate markdown files for metadata mod…
Browse files Browse the repository at this point in the history
…els in hsmodels
  • Loading branch information
pkdash committed Nov 18, 2024
1 parent b30fa56 commit 369a55a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/metadata/generate_hsmodels_aggregations_metadata_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import jsonschema2md
import json

from hsmodels.schemas.resource import ResourceMetadata
from hsmodels.schemas.aggregations import (
FileSetMetadata,
GeographicRasterMetadata,
GeographicFeatureMetadata,
MultidimensionalMetadata,
ReferencedTimeSeriesMetadata,
SingleFileMetadata,
TimeSeriesMetadata,
ModelInstanceMetadata,
ModelProgramMetadata,
CSVFileMetadata
)

aggregation_models = [
ResourceMetadata,
FileSetMetadata,
GeographicRasterMetadata,
GeographicFeatureMetadata,
MultidimensionalMetadata,
ReferencedTimeSeriesMetadata,
SingleFileMetadata,
TimeSeriesMetadata,
ModelInstanceMetadata,
ModelProgramMetadata,
CSVFileMetadata
]


def write_md(model):
sj_rm = model.schema_json(indent=4)
sj_rm = sj_rm.replace("$defs", "definitions")
parser = jsonschema2md.Parser()
parser.tab_size = 4
md_lines = parser.parse_schema(json.loads(sj_rm))

filename = model.__name__ + ".md"
with open(os.path.join(filename), "w") as f:
f.writelines(md_lines)


for aggr_model in aggregation_models:
write_md(aggr_model)

0 comments on commit 369a55a

Please sign in to comment.