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

Automatically generate an OpenApi specification #945

Merged
merged 9 commits into from
Feb 7, 2024

Conversation

agrare
Copy link
Member

@agrare agrare commented Oct 26, 2020

Passes validation https://editor-next.swagger.io/

$ bundle exec rake app:manageiq:api:openapi_generate

TODO

  • Load models to build schema
  • Add descriptions if a column has a comment
  • Detect and build parameters
  • Handle multiple post actions

#717

@agrare agrare added the wip label Oct 26, 2020
@agrare agrare force-pushed the openapi_generator_rake_task branch 3 times, most recently from debca55 to 80710d0 Compare October 26, 2020 18:30
@agrare agrare force-pushed the openapi_generator_rake_task branch 3 times, most recently from 6d5fa89 to d2c8569 Compare October 27, 2020 17:35
@agrare agrare requested a review from Fryguy October 27, 2020 18:07
@agrare
Copy link
Member Author

agrare commented Oct 27, 2020

This mostly just populates the schema from the models, not building out the paths yet

@agrare agrare force-pushed the openapi_generator_rake_task branch from d2c8569 to a4ef7b5 Compare October 27, 2020 19:39
@Fryguy
Copy link
Member

Fryguy commented Oct 28, 2020

@miq-bot miq-bot added the stale label Mar 6, 2023
@miq-bot
Copy link
Member

miq-bot commented Mar 6, 2023

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s)

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation.

@miq-bot miq-bot closed this Jun 12, 2023
@miq-bot
Copy link
Member

miq-bot commented Jun 12, 2023

This pull request has been automatically closed because it has not been updated for at least 3 months.

Feel free to reopen this pull request if these changes are still valid.

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation.

@kbrock kbrock removed the stale label Jun 12, 2023
@kbrock kbrock reopened this Jun 12, 2023
@miq-bot miq-bot added the stale label Sep 18, 2023
@miq-bot
Copy link
Member

miq-bot commented Sep 18, 2023

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s)

Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation.

@miq-bot
Copy link
Member

miq-bot commented Dec 25, 2023

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

@Fryguy Fryguy removed the stale label Jan 31, 2024
@Fryguy Fryguy self-assigned this Jan 31, 2024
@agrare agrare force-pushed the openapi_generator_rake_task branch from a4ef7b5 to f433e0f Compare January 31, 2024 18:32
@agrare agrare force-pushed the openapi_generator_rake_task branch 2 times, most recently from 29f8b8e to cd87acd Compare January 31, 2024 19:13
@agrare agrare force-pushed the openapi_generator_rake_task branch from cd87acd to f4cbd29 Compare January 31, 2024 19:15
Comment on lines 99 to 100
"title" => "API",
"description" => "REST API"
Copy link
Member Author

Choose a reason for hiding this comment

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

This matches what GET /api returns:

{
  "name": "API",
  "description": "REST API",
  "version": "4.4.0-pre",

@agrare agrare force-pushed the openapi_generator_rake_task branch from a294d39 to e178452 Compare January 31, 2024 19:32
@agrare agrare changed the title [WIP] Automatically generate an OpenApi specification Automatically generate an OpenApi specification Jan 31, 2024
@miq-bot miq-bot removed the wip label Jan 31, 2024
@agrare agrare force-pushed the openapi_generator_rake_task branch from 0b31fd2 to c5ffa6e Compare January 31, 2024 20:09
next unless collection.klass

model = collection.klass.constantize
schema_name = model.name.gsub("::", "_")
Copy link
Member Author

@agrare agrare Jan 31, 2024

Choose a reason for hiding this comment

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

This fixes ManageIQ::Providers::CloudManager::Vm, ManageIQ::Providers::CloudManager::Template, and ManageIQ::Providers::CloudManager::AuthKeyPair

I wonder if we should only allow the base class in api.yml though?

image

@agrare agrare force-pushed the openapi_generator_rake_task branch from 7bba8c5 to 72d76c6 Compare January 31, 2024 20:43
properties_value["type"] = "string"
properties_value["format"] = "date-time"
when :integer
if key == model.primary_key || key.ends_with?("_id")
Copy link
Member Author

Choose a reason for hiding this comment

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

I started using model.reflections to get the list of foreign_keys but some of our models define the associations in subclasses so some were being marked not as IDs.

# are ignored
if value.comment.present?
if properties_value.key?("$ref")
properties_value = {"allOf" => [properties_value, {"description" => value.comment}]}
Copy link
Member Author

Choose a reason for hiding this comment

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

If we have a description on a foreign_key we have to use allOf: [] because any other properties with a $ref are ignored

@miq-bot
Copy link
Member

miq-bot commented Feb 2, 2024

Checked commits agrare/manageiq-api@4271664~...c482f83 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
2 files checked, 0 offenses detected
Everything looks fine. 🍰

@agrare
Copy link
Member Author

agrare commented Feb 6, 2024

@Fryguy believe I addressed all existing comments, PTAL

@Fryguy Fryguy merged commit 78301bc into ManageIQ:master Feb 7, 2024
3 checks passed
@agrare agrare deleted the openapi_generator_rake_task branch February 7, 2024 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants