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

docs: ajout d'une doc static pour le schéma #37

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

hlecuyer
Copy link
Contributor

Pour tester:

pip install 'mkdocs-material==9.*'
mkdocs serve

Liste des features:

- Titre
 - Type
- Option 'Requis'
- Option 'Deprecie'
- Enum en list
- Description
- Format (possibilite d'en mettre plusieurs)
- Pattern (Possibilite d'en mettre plusieurs)
- Examples (possibilite d'en mettre plusieurs)

Les champs interessant a regarder:

- addresse (requis, deprecie, description, plusieurs exampleexamples)
- zone_type (plusieurs pattern)
- dat_maj (plusieurs format)
- types (enum)

Niveau du fichier jinja vous pouvez faire la review, si vous avez des tips je suis preneur (djlint m'a bien servi par exemple)

Je vais retoucher la partie en python sur main et l'ecrire en objet pour simplifier mais il va me faloir une demi journee de plus.

@hlecuyer hlecuyer marked this pull request as draft January 23, 2025 16:05
@vmttn vmttn changed the title wip docs: ajout d'un site static pour documenter le schéma Jan 24, 2025
@vmttn vmttn changed the title docs: ajout d'un site static pour documenter le schéma docs: ajout d'une doc static pour le schéma Jan 24, 2025
code_insee: Optional[common.CodeCommune] = None
adresse: Optional[str] = None
code_insee: Optional[common.CodeCommune] = Field(
description="[Deprecated]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description="[Deprecated]",

model_name = model.__name__.lower()
with (docs_dir / f"{model_name}.md").open("w") as file:
file.write(
jinja2.Template(open(docs_dir / "model.md.j2").read()).render(

Check warning

Code scanning / CodeQL

Jinja2 templating with autoescape=False Medium

Using jinja2 templates with autoescape=False can potentially allow XSS attacks.

Copilot Autofix AI about 18 hours ago

To fix the problem, we need to ensure that Jinja2's autoescape feature is enabled when creating the template environment. This can be done by using the select_autoescape function, which will automatically enable escaping for specific file extensions such as HTML and XML.

The best way to fix this without changing existing functionality is to create a Jinja2 Environment with autoescape set to select_autoescape(['html', 'xml']) and then use this environment to get the template. This ensures that any HTML or XML content is properly escaped, preventing XSS attacks.

Suggested changeset 1
src/data_inclusion/schema/__main__.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/data_inclusion/schema/__main__.py b/src/data_inclusion/schema/__main__.py
--- a/src/data_inclusion/schema/__main__.py
+++ b/src/data_inclusion/schema/__main__.py
@@ -85,5 +85,10 @@
         model_name = model.__name__.lower()
+        env = jinja2.Environment(
+            loader=jinja2.FileSystemLoader(docs_dir),
+            autoescape=jinja2.select_autoescape(['html', 'xml'])
+        )
+        template = env.get_template("model.md.j2")
         with (docs_dir / f"{model_name}.md").open("w") as file:
             file.write(
-                jinja2.Template(open(docs_dir / "model.md.j2").read()).render(
+                template.render(
                     schema=model.model_json_schema(),
EOF
@@ -85,5 +85,10 @@
model_name = model.__name__.lower()
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(docs_dir),
autoescape=jinja2.select_autoescape(['html', 'xml'])
)
template = env.get_template("model.md.j2")
with (docs_dir / f"{model_name}.md").open("w") as file:
file.write(
jinja2.Template(open(docs_dir / "model.md.j2").read()).render(
template.render(
schema=model.model_json_schema(),
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
ref_dir.mkdir(exist_ok=True)
with (ref_dir / f"{referential_name}.md").open("w") as file:
file.write(
jinja2.Template(open(docs_dir / "referentiel.md.j2").read()).render(

Check warning

Code scanning / CodeQL

Jinja2 templating with autoescape=False Medium

Using jinja2 templates with autoescape=False can potentially allow XSS attacks.
@hlecuyer hlecuyer force-pushed the hlecuyer/feat/generate-automatic-documentation branch from d2adc35 to 7cbef1f Compare January 29, 2025 15:09
{% for referential_item in referential %}
### `{{ referential_item.value }}`

Label: {{ referential_item.label }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Label: {{ referential_item.label }}
Label : {{ referential_item.label }}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

la petite règle en français : espace avant et après les deux points :

https://www.blogdumoderateur.com/regles-ponctuation-typographie/

Label: {{ referential_item.label }}

{% if referential_item.description %}
Description: {{ referential_item.description }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: {{ referential_item.description }}
Description : {{ referential_item.description }}

@hlecuyer hlecuyer force-pushed the hlecuyer/feat/generate-automatic-documentation branch 2 times, most recently from ff00162 to 997b04e Compare January 29, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants