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

openapi2jsonschema.py strips group to first subdomain #130

Closed
james-callahan opened this issue Oct 12, 2022 · 3 comments · Fixed by #219
Closed

openapi2jsonschema.py strips group to first subdomain #130

james-callahan opened this issue Oct 12, 2022 · 3 comments · Fixed by #219

Comments

@james-callahan
Copy link

I'm trying to use FILENAME_FORMAT='{group}-{version}-{kind}'. I would have expected this to work with -schema-location './crd-schemas/{{ .Group }}-{{ .ResourceAPIVersion }}-{{ .ResourceKind }}.json'. However for some reason openapi2jsonschema.py splits the group on . and only uses the first component:

group=y["spec"]["group"].split(".")[0],

This means that it ends up creating monitoring-v1-prometheus.json, but kubeconform looks for monitoring.coreos.com-v1-prometheus.json

@yannh
Copy link
Owner

yannh commented Jan 25, 2023

Apologies if I am slow to reply to requests with regards to this script - I do not understand it well enough and would need to have a number of unit tests to be sure changes do not break existing workflows. I actively rely on this script which is why I am conservative with changes. Thanks for your patience 🙇

@rgarcia89
Copy link

Same happens to me. When I run the crd-extractor.sh script the CRD admissionreports.kyverno.io.yaml is converted by the openapi2jsonschema to kyverno.io-v1alpha2.json. Since there are multiple kyverno CRDs only the last one remains in the json schema. However, if I go and run python3 $TMP_CRD_DIR/openapi2jsonschema.py $TMP_CRD_DIR/*.yaml manually everything works fine.

./crd-extractor.sh
JSON schema written to kyverno.io-v1alpha2.json
JSON schema written to monitoring.coreos.com-v1alpha1.json
JSON schema written to monitoring.coreos.com-v1.json
...
python3 $TMP_CRD_DIR/openapi2jsonschema.py $TMP_CRD_DIR/*.yaml
JSON schema written to admissionreport_v1alpha2.json
JSON schema written to alertmanagerconfig_v1alpha1.json
JSON schema written to alertmanager_v1.json
...

@rgarcia89
Copy link

nevermind... I just noticed that I somehow had

env |grep FILENAME_FORMAT
FILENAME_FORMAT={group}-{version}

configured...

@yannh yannh closed this as completed in #219 Jul 9, 2023
yannh pushed a commit that referenced this issue Jul 9, 2023
This is an alternative way to fix #130.
Instead of changing the `group` variable content, this commit adds
a new variable `fullgroup` that does not split the group components.

With this, users can specify the filename format like:

    FILENAME_FORMAT='{fullgroup}-{version}-{kind}'
yannh pushed a commit to levenleven/kubeconform that referenced this issue Jul 9, 2023
This is an alternative way to fix yannh#130.
Instead of changing the `group` variable content, this commit adds
a new variable `fullgroup` that does not split the group components.

With this, users can specify the filename format like:

    FILENAME_FORMAT='{fullgroup}-{version}-{kind}'
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 a pull request may close this issue.

3 participants