@dryv/http-contract-casesv0.1.0
Portable JSON contract cases for cross-language backend and client test harnesses.
dryv pack add @dryv/http-contract-cases{%- macro scalar_example(value) -%}
{%- if value is none -%}null
{%- elif value.is.enum and value.property.enum.values -%}{{ value.property.enum.values[0].value_json }}
{%- elif value.is.boolean -%}false
{%- elif value.is.integer -%}1
{%- elif value.is.number -%}1
{%- elif value.is.uuid -%}"00000000-0000-4000-8000-000000000001"
{%- elif value.is.email -%}"[email protected]"
{%- elif value.is.url or value.is.uri -%}"https://example.com"
{%- elif value.is.date -%}"2026-01-01"
{%- elif value.is.time -%}"12:00:00"
{%- elif value.is.temporal -%}"2026-01-01T12:00:00Z"
{%- elif value.is.record -%}{}
{%- else -%}"example"
{%- endif -%}
{%- endmacro -%}
{%- macro field_example(field) -%}
{%- if field.default is not none and field.default.kind == 'value' -%}{{ field.default.value_json }}
{%- elif field.array is not none -%}[{{ scalar_example(field.value) }}]
{%- else -%}{{ scalar_example(field.value) }}
{%- endif -%}
{%- endmacro -%}
{%- macro binding_kind(binding) -%}
{%- if binding.is.path -%}path
{%- elif binding.is.query -%}query
{%- elif binding.is.query_object -%}query-object
{%- elif binding.is.header -%}header
{%- elif binding.is.cookie -%}cookie
{%- elif binding.is.body -%}body
{%- elif binding.is.form -%}form
{%- elif binding.is.multipart -%}multipart
{%- else -%}unknown
{%- endif -%}
{%- endmacro -%}
{%- macro field_optional(operation, binding) -%}
{%- set result = namespace(value=false) -%}
{%- if binding.port.field is not none -%}
{%- for field in operation.input.fields -%}
{%- if field.name.raw == binding.port.field.raw -%}{%- set result.value = field.optional -%}{%- endif -%}
{%- endfor -%}
{%- endif -%}
{{- result.value | lower -}}
{%- endmacro -%}
{%- macro field_value(operation, binding) -%}
{%- set result = namespace(value='null') -%}
{%- if binding.port.field is not none -%}
{%- for field in operation.input.fields -%}
{%- if field.name.raw == binding.port.field.raw -%}{%- set result.value = field_example(field) | trim -%}{%- endif -%}
{%- endfor -%}
{%- endif -%}
{{- result.value -}}
{%- endmacro -%}
{
"kind": "dryv-http-contract-case",
"semantic_operation_id": {{ operation.id | tojson }},
"operation_name": {{ operation.name.qualified | tojson }},
"method": {{ operation.facets.http.method | tojson }},
"effective_path": {{ operation.facets.http.path.effective | tojson }},
"placeholder_values_are_synthesized": true,
"success_statuses": [{% for output in operation.facets.http.outputs %}{{ output.status }}{% if not loop.last %}, {% endif %}{% else %}200{% endfor %}],
"bindings": [
{%- for binding in operation.facets.http.inputs %}
{
"location": {{ binding_kind(binding) | trim | tojson }},
"wire_name": {{ (binding.name or binding.port.name.raw) | tojson }},
"semantic_field": {% if binding.port.field %}{{ binding.port.field.raw | tojson }}{% else %}null{% endif %},
"whole_input": {% if binding.port.field is none %}true{% else %}false{% endif %},
"optional": {% if binding.port.field is none %}false{% else %}{{ field_optional(operation, binding) }}{% endif %},
"example": {% if binding.port.field is none %}null{% else %}{{ field_value(operation, binding) }}{% endif %}
}{% if not loop.last %},{% endif %}
{%- endfor %}
],
"multipart_semantics_complete": {% if operation.facets.http.input_groups.multipart %}false{% else %}true{% endif %}
}