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

Add metadata to data being sent to API endpoint in json dump registration backend #5053

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def as_json_schema(self):
return {
"title": "Authentication type",
"type": "string",
"enum": AuthAttribute.values,
"enum": [*AuthAttribute.values, ""],
}


Expand Down
22 changes: 19 additions & 3 deletions src/openforms/forms/json_schema.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,52 @@
from typing import Iterator, Sequence

from openforms.plugins.registry import BaseRegistry
from openforms.typing import JSONObject
from openforms.variables.base import BaseStaticVariable
from openforms.variables.service import get_static_variables

from .models import Form, FormVariable


def _iter_form_variables(form: Form) -> Iterator[FormVariable]:
def _iter_form_variables(
form: Form,
additional_variables_registry: BaseRegistry[BaseStaticVariable] | None = None,
) -> Iterator[FormVariable]:
"""Iterate over static variables and all form variables.

:param form: Form
:param additional_variables_registry: Optional registry of static variables.
"""
# Static variables are always available
yield from get_static_variables()
# If the optional variables registry is passed
if additional_variables_registry is not None:
yield from get_static_variables(
variables_registry=additional_variables_registry
)
# Handle from variables holding dynamic data (component and user defined)
yield from form.formvariable_set.all()


def generate_json_schema(form: Form, limit_to_variables: Sequence[str]) -> JSONObject:
def generate_json_schema(
form: Form,
limit_to_variables: Sequence[str],
additional_variables_registry: BaseRegistry[BaseStaticVariable] | None = None,
) -> JSONObject:
"""Generate a JSON schema from a form, for the specified variables.

Note: this schema is an informative description of the variables and should not be
used as validation.

:param form: The form to generate JSON schema for.
:param limit_to_variables: Variables that will be included in the schema.
:param additional_variables_registry: Optional extra registry of static variables.

:returns: A JSON schema representing the form variables.
"""
requested_variables_schema = {
key: variable.as_json_schema()
for variable in _iter_form_variables(form)
for variable in _iter_form_variables(form, additional_variables_registry)
if (key := variable.key) in limit_to_variables
}

Expand Down
120 changes: 102 additions & 18 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@
"value": "The maximum length requirement this field must meet."
}
],
"5EOSwM": [
{
"type": 0,
"value": "Additional"
}
],
"5JNnFB": [
{
"type": 0,
Expand Down Expand Up @@ -1377,6 +1383,12 @@
"value": "Boolean"
}
],
"BiKRJT": [
{
"type": 0,
"value": "Key"
}
],
"Bin/vM": [
{
"type": 0,
Expand Down Expand Up @@ -1541,12 +1553,6 @@
"value": "length"
}
],
"CZ774U": [
{
"type": 0,
"value": "Which variables to include in the data to be sent"
}
],
"Cf5zSF": [
{
"type": 0,
Expand All @@ -1571,6 +1577,12 @@
"value": "Submission allowed"
}
],
"Cz+O0n": [
{
"type": 0,
"value": "Source"
}
],
"D0hDzV": [
{
"type": 1,
Expand Down Expand Up @@ -2275,12 +2287,6 @@
"value": " is unknown. We can only display the JSON definition."
}
],
"Ibejpf": [
{
"type": 0,
"value": "Path relative to the Service API root"
}
],
"Igt0Rc": [
{
"type": 0,
Expand Down Expand Up @@ -2431,6 +2437,12 @@
"value": "Override the minimum Level of Assurance. This is not supported by all authentication plugins."
}
],
"JfgATN": [
{
"type": 0,
"value": "Additional variables to include."
}
],
"JhdlEg": [
{
"type": 0,
Expand Down Expand Up @@ -2493,6 +2505,12 @@
"value": "Content"
}
],
"KMTsJc": [
{
"type": 0,
"value": "Static"
}
],
"KMbfsU": [
{
"type": 0,
Expand Down Expand Up @@ -2869,6 +2887,12 @@
"value": ". Extend your session if you wish to continue."
}
],
"Od+jm6": [
{
"type": 0,
"value": "Values:"
}
],
"Oi+DV0": [
{
"children": [
Expand Down Expand Up @@ -3779,6 +3803,12 @@
"value": "Active"
}
],
"X+NeMd": [
{
"type": 0,
"value": "Include variable in metadata"
}
],
"X18/UP": [
{
"type": 0,
Expand Down Expand Up @@ -3863,6 +3893,12 @@
"value": "Remove"
}
],
"Xpw7Gk": [
{
"type": 0,
"value": "Whether to include this variable in the metadata to be sent."
}
],
"XyDeaD": [
{
"type": 0,
Expand Down Expand Up @@ -4263,6 +4299,12 @@
"value": "Objecttype"
}
],
"bmUuAH": [
{
"type": 0,
"value": "Fixed"
}
],
"bmlODS": [
{
"type": 0,
Expand Down Expand Up @@ -5059,6 +5101,12 @@
"value": "Are you sure you want to delete this variable?"
}
],
"hfeO2r": [
{
"type": 0,
"value": "Registration"
}
],
"hhoWxC": [
{
"type": 0,
Expand Down Expand Up @@ -5119,6 +5167,12 @@
"value": "Description"
}
],
"iQblZd": [
{
"type": 0,
"value": "Variables that are already included."
}
],
"iX0YPY": [
{
"options": {
Expand Down Expand Up @@ -5679,6 +5733,12 @@
"value": "House number"
}
],
"mfD7J5": [
{
"type": 0,
"value": "Name"
}
],
"mpzdoT": [
{
"type": 0,
Expand Down Expand Up @@ -5709,6 +5769,12 @@
"value": "Whether to add children information to the component."
}
],
"nEg4dr": [
{
"type": 0,
"value": "Metadata:"
}
],
"nFXYHB": [
{
"type": 0,
Expand Down Expand Up @@ -5871,6 +5937,12 @@
"value": "The regular expression pattern test that the city field value must pass before the form can be submitted."
}
],
"ow5LZk": [
{
"type": 0,
"value": "Variables to include in the data to be sent."
}
],
"oxYXJX": [
{
"type": 0,
Expand Down Expand Up @@ -6075,12 +6147,6 @@
"value": "This template is evaluated with the submission data when the payment is received. The resulting JSON is sent to the objects API to update (the payment fields of) the earlier created object."
}
],
"qPiUic": [
{
"type": 0,
"value": "Which service to send the data to"
}
],
"qUYLVg": [
{
"type": 0,
Expand Down Expand Up @@ -6247,6 +6313,12 @@
"value": "(not configured yet)"
}
],
"sAfROS": [
{
"type": 0,
"value": "Metadata variables"
}
],
"sCkGL9": [
{
"type": 0,
Expand Down Expand Up @@ -6293,6 +6365,12 @@
"value": " 3"
}
],
"sokfvf": [
{
"type": 0,
"value": "The service to send the data to."
}
],
"sptpzv": [
{
"type": 0,
Expand Down Expand Up @@ -6467,6 +6545,12 @@
"value": "Amount of days successful submissions of this form will remain before being removed. Leave blank to use value in General Configuration."
}
],
"uUf7cu": [
{
"type": 0,
"value": "Path relative to the Service API root."
}
],
"uVVO4b": [
{
"type": 0,
Expand Down
Loading
Loading