From 605ba7a6cc7ca40427effddd4d29f4b5ed354080 Mon Sep 17 00:00:00 2001 From: Carson-Shaar <120226019+Carson-Shaar@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:16:57 -0400 Subject: [PATCH] fix: Add workflow for Mintlify documentation updates (#295) * Add workflow for Mintlify documentation updates * Add workflow for Mintlify documentation updates * Create generate_mdx_from_pydantic.py * Update update-docs.yml * Update update-docs.yml * Update generate_mdx_from_pydantic.py * chore: update to chore push on file update --------- Co-authored-by: WorldExplored Co-authored-by: Srreyansh Sethi <107075589+WorldExplored@users.noreply.github.com> --- .github/scripts/generate_mdx_from_pydantic.py | 101 ++++++++++++++++++ .github/workflows/update-docs.yml | 33 ++++++ 2 files changed, 134 insertions(+) create mode 100644 .github/scripts/generate_mdx_from_pydantic.py create mode 100644 .github/workflows/update-docs.yml diff --git a/.github/scripts/generate_mdx_from_pydantic.py b/.github/scripts/generate_mdx_from_pydantic.py new file mode 100644 index 00000000..0fb67160 --- /dev/null +++ b/.github/scripts/generate_mdx_from_pydantic.py @@ -0,0 +1,101 @@ +import os +from pydantic import BaseModel, Field +from typing import Type + +class ExampleModel(BaseModel): + id: int = Field(..., description="The unique identifier for the example") + name: str = Field(..., description="The name of the example") + description: str = Field(..., description="A description of the example") + +def generate_mdx(model: Type[BaseModel], file_path: str): + """Generate an MDX file from a Pydantic model.""" + model_name = model.__name__ + properties = model.schema()["properties"] + required = set(model.schema()["required"]) + + mdx_content = f"""--- +icon: "rectangle-code" +iconType: "solid" +--- + + + ```python +import zero_true as zt + +# Create a {model_name} component +sample_{model_name.lower()} = zt.{model_name}( +""" + + for field_name, field_info in properties.items(): + default = f" = {field_info.get('default')}" if "default" in field_info else "" + mdx_content += f" {field_name}={default}, # {field_info['description']}\n" + + mdx_content += """) + +# Assuming you have a mechanism to render or use this component within a layout +layout = zt.Layout(components=[sample_{model_name.lower()}]) + +``` + + + + + + + + +## Overview + +`pydantic model zero_true.{model_name}` + +The {model_name} component is a fundamental element in user interfaces, offering a simple yet versatile method for user interaction. This standard component can be customized with different attributes to match the design requirements of any application. + + It supports enabling or disabling based on application logic, and its functionality extends to capturing interactions through event triggers that can be connected to backend processes. The straightforward implementation makes it an essential tool for initiating actions, submitting forms, or triggering events within a UI. + + +## JSON Schema + + +```json +{{ + "title": "{model_name}", + "description": "{model.schema().get('description', '')}", + "type": "object", + "properties": {properties}, + "required": {list(required)} +}} +``` + + +Below are the various attributes you can assign to the component. Utilizing them can allow for modifications to the pre-created object. + + + + +""" + + for field_name, field_info in properties.items(): + mdx_content += f""" + **field {field_name}:** {field_info['type']} = {field_info.get('default', 'None')}; + {field_info['description']} + +""" + + mdx_content += """ + + + + + + classmethod *get_value_from_global_state*(value, values) + +""" + + with open(file_path, 'w') as file: + file.write(mdx_content) + +if __name__ == "__main__": + output_dir = 'docs' + os.makedirs(output_dir, exist_ok=True) + generate_mdx(ExampleModel, os.path.join(output_dir, 'example_model.mdx')) +``` diff --git a/.github/workflows/update-docs.yml b/.github/workflows/update-docs.yml new file mode 100644 index 00000000..6ef36f2d --- /dev/null +++ b/.github/workflows/update-docs.yml @@ -0,0 +1,33 @@ +name: Generate MDX Documentation + +on: + workflow_dispatch: + +jobs: + generate-docs: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + pip install pydantic + + - name: Generate MDX files from Pydantic models + run: | + python .github/scripts/generate_mdx_from_pydantic.py + + - name: Commit generated MDX files + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add docs/*.mdx + git commit -m "chore: Generate MDX files from Pydantic models" + git push origin main