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

feat: add script to generate OAI models #27

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

aaravm
Copy link
Collaborator

@aaravm aaravm commented Jul 15, 2024

Introduced a script to automate the generation of Rust models from OpenAPI specifications, ensuring the necessary structs are built for the main functions.

Summary by Sourcery

This pull request adds a new script, build-models.sh, which automates the generation of Rust models from OpenAPI specifications. The script ensures the necessary structs are built for the main functions by downloading the OpenAPI Generator JAR and processing the OpenAPI specifications.

  • New Features:
    • Introduced a script to automate the generation of Rust models from OpenAPI specifications.
  • Build:
    • Added build-models.sh script to download OpenAPI Generator JAR and generate Rust models.

Copy link
Contributor

sourcery-ai bot commented Jul 15, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new script, build-models.sh, which automates the generation of Rust models from OpenAPI specifications. The script ensures the necessary OpenAPI Generator JAR file is set up, extracts the repository name, generates the models, modifies import statements, and copies the generated models to the appropriate destination directories.

File-Level Changes

Files Changes
build-models.sh Introduced a new script to automate the generation of Rust models from OpenAPI specifications, including setup, generation, and post-processing steps.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@aaravm aaravm changed the title added build-models.sh feat: OpenAPI models auto-generation Jul 15, 2024
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aaravm - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
aaravm and others added 2 commits July 16, 2024 17:19
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Copy link
Collaborator

@pavelnikonorov pavelnikonorov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more general comments:

  • Consider creating section headers for better structuring, e.g., "Parameter definitions", "Function definitions", "Main"
  • The script sometimes mixes up definitions, setup, business logic and cleanup code. Look at each function and consider reordering so that each function starts with parameter definitions, followed by additional setup code (e.g., creating or deleting files and dirs), business logic (e.g., calling the OpenAPI generator to create the models) and, finally, cleanup code (copy results, remove temporary files and other artifacts).
  • Not a huge fan of pulling the OpenAPI generator JAR to ~/bin/openapitools/. For one, the user may already have it in a different location. Might be better to make this configurable. Also consider writing a separate install script here (would need to run only once before executing the script several times as discussed elsewhere in the comments).

build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
build-models.sh Outdated Show resolved Hide resolved
@aaravm
Copy link
Collaborator Author

aaravm commented Jul 31, 2024

@uniqueg I have added all of your suggestions. Please mention if you want me to change something else too

Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure what's the relevance/utility of this script. We cannot generate the APIs on the fly, because we know that the results are generally not good enough and need manual edits. So that means that we will commit the models. Which in turn means that after they have been committed, the script becomes useless.

IMO, it would make more sense if it was parameterized, i.e., if the arguments (which models to generate and where to put them) would be passed via the CLI. That way it could be used to get a first draft of any new specs we add - without redoing what we already have.

But still it would be just a wrapper script, essentially writing several lines of code just to replace what is probably just a single line of code.

So instead of all this, I think just documenting the necessary steps, together with concrete code examples, somewhere in a markdown file (maybe in docs/autogenerate_OAI_models.md, linked to README.md) would be good enough for us and others to contribute models for new APIs (or API versions) in the future, no?

If you disagree, at the very least, this PR should contain:

  • ./script.sh
  • Documentation on how/when to run this

And it probably would make sense to put the scripts in some subdirectory (e.g., utils/) rather than just dumping them in the repository root directory.

Please tell me what you think, @aaravm and @pavelnikonorov. I guess not merging this for now doesn't block anything, because as far as I can tell, this is not code that is called when building or executing the project and the artifacts the script produces are merged in other PRs (please correct me if I'm wrong).

build-models.sh Outdated Show resolved Hide resolved
@aaravm
Copy link
Collaborator Author

aaravm commented Aug 7, 2024

I'm not quite sure what's the relevance/utility of this script. We cannot generate the APIs on the fly, because we know that the results are generally not good enough and need manual edits. So that means that we will commit the models. Which in turn means that after they have been committed, the script becomes useless.

IMO, it would make more sense if it was parameterized, i.e., if the arguments (which models to generate and where to put them) would be passed via the CLI. That way it could be used to get a first draft of any new specs we add - without redoing what we already have.

But still it would be just a wrapper script, essentially writing several lines of code just to replace what is probably just a single line of code.

So instead of all this, I think just documenting the necessary steps, together with concrete code examples, somewhere in a markdown file (maybe in docs/autogenerate_OAI_models.md, linked to README.md) would be good enough for us and others to contribute models for new APIs (or API versions) in the future, no?

If you disagree, at the very least, this PR should contain:

  • ./script.sh
  • Documentation on how/when to run this

And it probably would make sense to put the scripts in some subdirectory (e.g., utils/) rather than just dumping them in the repository root directory.

Please tell me what you think, @aaravm and @pavelnikonorov. I guess not merging this for now doesn't block anything, because as far as I can tell, this is not code that is called when building or executing the project and the artifacts the script produces are merged in other PRs (please correct me if I'm wrong).

@uniqueg, Thanks for the review!
I agree with you, and I have made documentation on how and when to run this script, and have put the script in a utils folder, and added the missing .script.sh. However, the models generated not currently saved or pushed in any PR yet, and I will make a new PR with all the auto-generated files once this PR is merged.
Please mention if you think I should make any other changes

README.md Outdated Show resolved Hide resolved
docs/autogenerate_OAI_models.md Outdated Show resolved Hide resolved
utils/build-models.sh Outdated Show resolved Hide resolved
utils/build-models.sh Outdated Show resolved Hide resolved
utils/script.sh Outdated Show resolved Hide resolved
utils/script.sh Outdated Show resolved Hide resolved
utils/script.sh Outdated Show resolved Hide resolved
@uniqueg uniqueg changed the title feat: OpenAPI models auto-generation feat: add script to generate OAI models Aug 8, 2024
Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few comments to open conversations

utils/build-models.sh Outdated Show resolved Hide resolved
docs/autogenerate_OAI_models.md Outdated Show resolved Hide resolved
utils/script.sh Outdated Show resolved Hide resolved
@pavelnikonorov pavelnikonorov self-requested a review August 18, 2024 18:45
Copy link
Collaborator

@pavelnikonorov pavelnikonorov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add documentation for an OpenAPI generator installation and rely on it in the script (instead of automated installation)

utils/script.sh Outdated Show resolved Hide resolved
utils/script.sh Outdated Show resolved Hide resolved
docs/autogenerate_OAI_models.md Outdated Show resolved Hide resolved
docs/autogenerate_OAI_models.md Outdated Show resolved Hide resolved
@aaravm
Copy link
Collaborator Author

aaravm commented Aug 19, 2024

@pavelnikonorov @uniqueg, you both had pretty valid concerns about the installation of OpenAPI in the script, so I have moved it outside the script, and provided documentation to see alternate ways to install OpenAPI.
I think that while it should address the concerns, we could also make an issue for #27 (comment)

@uniqueg
Copy link
Member

uniqueg commented Aug 21, 2024

@pavelnikonorov @uniqueg, you both had pretty valid concerns about the installation of OpenAPI in the script, so I have moved it outside the script, and provided documentation to see alternate ways to install OpenAPI. I think that while it should address the concerns, we could also make an issue for #27 (comment)

Yes, please create an issue for using the Docker image as an alternative to manual installation.

Copy link
Member

@uniqueg uniqueg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using npm for the OpenAPI generator CLI installation - or otherwise please let me know why not.

Rest is fine

Comment on lines 5 to 11
1. OpenAPI Generator CLI: Make sure the directory `~/bin/openapitools` is empty, as OpenAPI is being installed in this script, which might conflict with your existing directory. Then run the following script to install OpenAPI generator CLI.
```sh
sudo chmod +x ./utils/script.sh
mkdir -p ~/bin/openapitools
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > ~/bin/openapitools/openapi-generator-cli
chmod u+x ~/bin/openapitools/openapi-generator-cli
export PATH=$PATH:~/bin/openapitools/
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you don't wanna use npm? https://openapi-generator.tech/docs/installation/. No need to manually deal with setting the dir, downloading, making executable etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, you would of course need to install JDK first (which anyway makes sense).

utils/build_models.sh Show resolved Hide resolved
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 this pull request may close these issues.

3 participants