-
Notifications
You must be signed in to change notification settings - Fork 8
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
webpack 5+ (including angular) #183
Comments
Hi! There are somepeople that use it in the frontend/browser (see #3) but you'd have to integrate it Angular (i.e. write a service) yourself. Hope that clears things up. |
Thanks, I tried to make it work in an angular interceptor without success. I have always the errors:
I have tried almost every suggestion on the web like:
As I understand from #3 it's essential that fs (which I guess is a core nodejs library) is present to chunck the spec. So it might not work if the There are downside too in implementing such validation in the frontend like exposing the openapi schema. Also I would need opeanpi spec 3. So I think I will orient myself to do the validation in a backend middleware as you suggested in #3 Thanks |
Did you try to solution suggested by webpack you posted, which is polyfilling http?
Lastly, please be advised this library only supports swagger v2, not openapi/swagger v3, see #11 |
Yes I tried to polyfill http with
and providing in webpack.config.js:
referenced in angular.json via But I still have the following errors:
About the openapi v3 not supported I got awared of it yesterday. Thanks |
So with webpack 5, the node.js polyfills were removed, meaning you have to provide them yourself. This is not supported by me as this module is not intended to be used in the frontend. I tried to polyfill all libraries unsuccessfully. The http/https polyfills seem not to do the trick as the promises still depend on "process" which I was unable to polyfill properly. Again, using this as a frontend module is not supported. The only way I was able to run a validation was with: Relevant webpack config: "resolve": {
"fallback": {
"fs": false,
"http": false,
"https": false,
"url": false,
"path": false,
}
} Manual import of the "global" shim (make sure to import 'angular6-global-shim'
import * as SwaggerValidator from 'swagger-object-validator'; then pass a partialsDir (which is not needed anyway) to the validator explicitly and give it a JSON spec directly (i.e. you have to load the swagger yaml spec yourself, because the HTTP/HTTPS shims don't work): let validator = new SwaggerValidator.Handler(undefined, {partialsDir: "."});
// this would be the JSON representation of your swagger V2 spec
let spec = {
type: "array",
items: {
type: "string"
}
}
let model = ['1', '2'];
validator.validateModel(model, spec, (err, result) => {
if (result) {
console.log(result.humanReadable());
}
}); Again, using this module in a frontend app is neither supported nor advised. |
Thanks for your time. I will give it a try just for curiosity |
Is angular supported?
Thanks
The text was updated successfully, but these errors were encountered: