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: validate API requests and responses according to the OpenApi spec #1579

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

feloy
Copy link
Contributor

@feloy feloy commented Aug 21, 2024

What does this PR do?

Validate API requests and responses according to the OpenApi spec

Using the express-openapi-validator needs to patch the ono dependency with JS-DevTools/ono#20

We use the @rollup/replace plugin for this (another solution would be to use yarn patch to patch the node_modules directly, but the project is currently using yarn v1.22, which does not include this command, available only starting from v3)

What issues does this PR fix or reference?

Fixes #1578

How to test this PR?

@feloy feloy requested review from benoitf, jeffmaury and a team as code owners August 21, 2024 20:32
@feloy feloy requested review from cdrage and gastoner August 21, 2024 20:32
@feloy feloy force-pushed the feat/openapi-validator branch 2 times, most recently from 10ed66d to 701d192 Compare August 21, 2024 20:35
Comment on lines 37 to 38
'@jsdevtools/ono': '@jsdevtools/ono/cjs/index.js',
'ono': '@jsdevtools/ono/cjs/index.js',
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious why we need that ? these one are usually just for the local source code new links

Copy link
Contributor Author

@feloy feloy Aug 21, 2024

Choose a reason for hiding this comment

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

Ono (a dependency of express-openapi-validator) provides both versions, cjs and esm, and vite includes the esm one by default.

But the esm version includes this code, which fails because module.exports.default is not defined:

// CommonJS default export hack
if (typeof module === "object" && typeof module.exports === "object") {
    module.exports = Object.assign(module.exports.default, module.exports);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't the extension be set as a module ?

type: "module" ?

I did that for the podman extension
https://github.com/containers/podman-desktop/blob/main/extensions/podman/package.json#L7

and we say we generate a cjs file
https://github.com/containers/podman-desktop/blob/main/extensions/podman/package.json#L13

Copy link
Collaborator

Choose a reason for hiding this comment

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

the rationale is that we have more and more libraries that are only esm
so instead of trying to grab the commonjs files, we should switch to be esm and allow to use esm easily as well

some libraries are now esm only
podman-desktop/podman-desktop@8e6debf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benoitf I just tested with type: "module" (and removing the aliases), but the error is the same. The hack in the esm version of ono seems not compatible with vite

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that we can't use cjs as for long term it'll be a burden

we may patch the module using JS-DevTools/ono#20 or getting rid of the lines ?

or switch to another library

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'll make changes to patch ono's esm version, so we can use it. Thanks @benoitf

@feloy feloy requested a review from benoitf August 21, 2024 20:45
@benoitf benoitf changed the title Validate API requests and responses according to the OpenApi spec feat: validate API requests and responses according to the OpenApi spec Aug 21, 2024
@feloy feloy marked this pull request as draft August 22, 2024 08:37
@feloy feloy marked this pull request as ready for review August 22, 2024 13:32
@feloy feloy merged commit 4e20f77 into containers:main Aug 26, 2024
4 checks passed
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.

Validate API requests and responses
3 participants