Skip to content

Commit

Permalink
feat: support yaml extension (#2217)
Browse files Browse the repository at this point in the history
## Description

Support yaml extension in lint following these rules
https://docs.docker.com/compose/compose-file/11-extension/

## Related Issue

Relates to #2064 

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed

---------

Co-authored-by: Wayne Starr <[email protected]>
  • Loading branch information
AustinAbro321 and Racer159 authored Jan 10, 2024
1 parent 98a19b4 commit 0866000
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 61 deletions.
20 changes: 0 additions & 20 deletions docs/3-create-a-zarf-package/4-zarf-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,26 +441,6 @@ Must be one of:
| **Type** | `object` |
| **Additional properties** | [![Any type: allowed](https://img.shields.io/badge/Any%20type-allowed-green)](# "Additional Properties of any type are allowed.") |

<details>
<summary>
<strong> <a name="build_registryOverrides_pattern1"></a>Pattern Property .*</strong>
</summary>
&nbsp;
<blockquote>

:::note
All properties whose name matches the regular expression
```.*``` ([Test](https://regex101.com/?regex=.%2A))
must respect the following conditions
:::

| | |
| -------- | -------- |
| **Type** | `string` |

</blockquote>
</details>

</blockquote>
</details>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% for sub_property in schema.iterate_properties %}
{%- if sub_property.is_additional_properties and not sub_property.is_additional_properties_schema -%}
{%- if sub_property.is_additional_properties and not sub_property.is_additional_properties_schema or sub_property.is_pattern_property -%}
{% continue %}
{% endif %}

Expand All @@ -19,7 +19,7 @@
<summary>
{% filter md_heading(1, html_id, True) -%}
{%- filter replace('\n', '') -%}
{%- if sub_property.is_pattern_property %} Pattern Property{% endif %} {% with schema=sub_property %}{%- include "breadcrumbs.md" %} {% endwith %}
{% with schema=sub_property %}{%- include "breadcrumbs.md" %} {% endwith %}
{%- if not skip_required and sub_property.property_name -%}
{{ "*" if sub_property.is_required_property else "" -}}
{%- endif -%}
Expand All @@ -40,13 +40,6 @@
{% endif %}

{% with schema=sub_property, skip_headers=False %}
{% if sub_property.is_pattern_property %}
:::note
All properties whose name matches the regular expression
```{{ sub_property.property_name }}``` ([Test](https://regex101.com/?regex={{ sub_property.property_name | urlencode }}))
must respect the following conditions
:::
{% endif %}
{%- if not skip_required and sub_property.property_name -%}
{{ md_badge("Required", "red", show_text=False) if sub_property.is_required_property else "" -}}
{%- endif -%}
Expand Down
2 changes: 1 addition & 1 deletion hack/.templates/jsonschemaforhumans/tabbed_section.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<blockquote>

{% filter md_heading(2, node.html_id) -%}
{% if node.is_pattern_property %}Pattern{% endif %} Property `{% with schema=node %}{%- include "breadcrumbs.md" %}{% endwith %}`
Property `{% with schema=node %}{%- include "breadcrumbs.md" %}{% endwith %}`
{%- endfilter %}

{% with schema=node, skip_headers=False %}
Expand Down
4 changes: 4 additions & 0 deletions hack/create-zarf-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
# Create the json schema for the zarf.yaml
go run main.go internal gen-config-schema > zarf.schema.json

# Adds pattern properties to all definitions to allow for yaml extensions
jq '.definitions |= map_values(. + {"patternProperties": {"^x-": {}}})' zarf.schema.json > temp_zarf.schema.json
mv temp_zarf.schema.json zarf.schema.json

# Create docs from the zarf.yaml JSON schema
docker run -v $(pwd):/app -w /app --rm python:3.8-alpine /bin/sh -c "pip install json-schema-for-humans && generate-schema-doc --config-file hack/.templates/jsfh-config.json zarf.schema.json docs/3-create-a-zarf-package/4-zarf-schema.md"
7 changes: 6 additions & 1 deletion src/pkg/packager/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ components:
`

const goodZarfPackage = `
x-name: &name good-zarf-package
kind: ZarfPackageConfig
metadata:
name: good-zarf-package
name: *name
x-description: Testing good yaml with yaml extension
components:
- name: baseline
required: true
x-foo: bar
`

func readAndUnmarshalYaml[T interface{}](t *testing.T, yamlString string) T {
Expand Down
Loading

0 comments on commit 0866000

Please sign in to comment.