-
Notifications
You must be signed in to change notification settings - Fork 123
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: Allow writting to subdirectories #276
base: master
Are you sure you want to change the base?
Conversation
Verify that the target filename (templates from `FILENAME_FORMAT`) is in the current working directory and allow writting to arbitrary subdirectories if this is the case
Hi @peschmae ! I'm not sure about adding this, It is opinionated (can only create subdirectories in the current working directory) and also can not create subdirectories of subdirectories. Would it not be easy to create the repository just before running this script if needed? |
Hi @yannh
The current implementation, doesn't allow writting to any subdirectory, even if they already exists (due to the usage of I then came across #197 which tried to write the files into the directory structure used for the CRD Catalog (
While it's possible to create a single subdirectory before running the script, the approach for |
I ran into this as well recently (also while preparing stuff for My pain point was that I had to process a CRD definition that contained many different Groups, so manually creating them, AND then having to move all the generated files around would certainly be possible with a couple of lines of bash script, but certainly not worth my time :-) So I went for a simple 2-line change: @@ -102,7 +102,9 @@ def write_schema_file(schema, filename):
schemaJSON = json.dumps(schema, indent=2)
# Dealing with user input here..
- filename = os.path.basename(filename)
+ dirname = os.path.dirname(filename)
+ os.makedirs(dirname, exist_ok=True)
+
f = open(filename, "w")
print(schemaJSON, file=f)
f.close() I then ran the script like this: FILENAME_FORMAT='{fullgroup}/{kind}_{version}' ./openapi2jsonschema.py path/to/crds.yaml Yes of course if you set |
@yannh seconding I manually updated the script locally to dynamically create directories based on the I think it's worth allowing users to choose to add a subdirectory, even if there are some drawbacks. The alternative is now it 'fails' silently and just drops the directories. |
This pull requests extends the
openapi2jsonschema.py
allowing to write to a subdirectory of the current working directory.The filename templated from
FILENAME_FORMAT
is verified to be a child of the working directory, and if the subdirectory doesn't exist yet, it's created.