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(@xen-orchestra/rest-api): expose get vms and get vm #8356

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

MathieuRA
Copy link
Member

@MathieuRA MathieuRA commented Feb 18, 2025

Description

Wait for #8327

  • @vates/types Added an export to the root of the lib because TSOA requires importing the type from the root library to generate the OpenAPI specification
  • @vates/types Tuples ([number, number]) throw errors when generating the OpenAPI specification. They have been updated to number[]
  • @vates/types Created a XapiXoRecord to be able to differentiate between XO types that come from xapi-object-to-xo and XO types that come from XO collections
  • xo-server Added getObjectsByType to avoid iterating over all XAPI objects when we know what type of object we want
  • Branded is not a valid type for the OpenAPI spec. I created a Unbrand type, that convert all Branded to string . (Use Unbrand only for OpenAPI specification definition to maintain Branded type safety)
  • Added another error middleware to catch TSOA errors and throw XO errors
  • Added a README.md to have consistency of order in the use of decorators

Checklist

  • Commit
    • Title follows commit conventions
    • Reference the relevant issue (Fixes #007, See xoa-support#42, See https://...)
    • If bug fix, add Introduced by
  • Changelog
    • If visible by XOA users, add changelog entry
    • Update "Packages to release" in CHANGELOG.unreleased.md
  • PR
    • If UI changes, add screenshots
    • If not finished or not tested, open as Draft

Review process

This 2-passes review process aims to:

  • develop skills of junior reviewers
  • limit the workload for senior reviewers
  • limit the number of unnecessary changes by the author
  1. The author creates a PR.
  2. Review process:
    1. The author assigns the junior reviewer.
    2. The junior reviewer conducts their review:
      • Resolves their comments if they are addressed.
      • Adds comments if necessary or approves the PR.
    3. The junior reviewer assigns the senior reviewer.
    4. The senior reviewer conducts their review:
      • If there are no unresolved comments on the PR → merge.
      • Otherwise, we continue with 3.
  3. The author responds to comments and/or makes corrections, and we go back to 2.

Notes:

  1. The author can request a review at any time, even if the PR is still a Draft.
  2. In theory, there should not be more than one reviewer at a time.
  3. The author should not make any changes:
    • When a reviewer is assigned.
    • Between the junior and senior reviews.

@MathieuRA MathieuRA changed the title Swagger vms feat(@xen-orchestra/rest-api): expose get vms and get vm Feb 18, 2025
@MathieuRA MathieuRA self-assigned this Feb 18, 2025
@MathieuRA MathieuRA requested a review from b-Nollet February 18, 2025 14:24
@MathieuRA MathieuRA requested a review from fbeauchamp February 19, 2025 13:06
Comment on lines 11 to 12
this.getObject = (id, type) => xoApp.getObject(id, type)
this.getObjectsByType = (type, opts) => xoApp.getObjectsByType(type, opts)
Copy link
Collaborator

Choose a reason for hiding this comment

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

would it work with real methods defined on the class and setting xoa as a private member of Rest Api ?

Comment on lines 5 to 11
export default function tsoaToXoErrorHandler(error: unknown, _req: Request, _res: Response, next: NextFunction) {
if (!(error instanceof ValidateError)) {
return next(error)
}

invalidParameters(error.fields)
}
Copy link
Collaborator

@fbeauchamp fbeauchamp Feb 20, 2025

Choose a reason for hiding this comment

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

Suggested change
export default function tsoaToXoErrorHandler(error: unknown, _req: Request, _res: Response, next: NextFunction) {
if (!(error instanceof ValidateError)) {
return next(error)
}
invalidParameters(error.fields)
}
export default function tsoaToXoErrorHandler(error: unknown, _req: Request, _res: Response, next: NextFunction) {
if (error instanceof ValidateError) {
return invalidParameters(error.fields)
}
return next(error)
}

Base automatically changed from setup-auth-openapi to master February 20, 2025 15:07
@MathieuRA MathieuRA marked this pull request as ready for review February 20, 2025 15:58
@MathieuRA MathieuRA requested a review from fbeauchamp February 20, 2025 16:46
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