Apicurio / apicurio-studio

Open Source API Design
https://www.apicur.io/studio/
Apache License 2.0
983 stars 493 forks source link

[Question] Using spectral ruleset files #1850

Open gayanper opened 2 years ago

gayanper commented 2 years ago

I would like to reuse the spectral rule set files that we use in our CI pipeline for validation of schema files in studio as well. I see that in the apicurito-data-models define a Validate extension. i would like to integrate spectral with studio as an extension. Could you provide how to do that ?

If needed i can also help with a PR for the required changes.

EricWittmann commented 2 years ago

We're actively working on this right now. @craicoverflow can provide more details on status. Integrating what we have in data models with Studio is likely the next step. We aren't quite there yet - I'm sure help in this area would be greatly appreciated!

gayanper commented 2 years ago

Glad to help out, let me know how i can help.

craicoverflow commented 2 years ago

Our next step was to provide a Spectral extension as our first officially supported validation extension. If this is something you would be interested in contributing that would be great!

I would like to reuse the spectral rule set files that we use in our CI pipeline for validation of schema files in studio as well.

If you are looking to add an extension which uses the Spectral JavaScript APIs it is pretty straightforward. I did it here as a demo: https://github.com/craicoverflow/apicurio-datamodels-spectral-demo/blob/main/SpectralApicurioValidatorPlugin.ts#L6

Getting the extension to load rules from a Spectral file will take more effort as we need to port some stuff from the Spectral code but hope to get this done soon! Once this is complete we can get your help with the Studio integration.

gayanper commented 2 years ago

Our next step was to provide a Spectral extension as our first officially supported validation extension. If this is something you would be interested in contributing that would be great!

I would like to reuse the spectral rule set files that we use in our CI pipeline for validation of schema files in studio as well.

If you are looking to add an extension which uses the Spectral JavaScript APIs it is pretty straightforward. I did it here as a demo: https://github.com/craicoverflow/apicurio-datamodels-spectral-demo/blob/main/SpectralApicurioValidatorPlugin.ts#L6

Getting the extension to load rules from a Spectral file will take more effort as we need to port some stuff from the Spectral code but hope to get this done soon! Once this is complete we can get your help with the Studio integration.

I checked the plugin, i found some questions. The spectral API expect a Document according to https://meta.stoplight.io/docs/spectral/ZG9jOjI1MTg3-spectral-in-java-script. How do you pass in a node which is a apicurito-data-model type into it ?

craicoverflow commented 2 years ago

The Spectral API also allows a string, so we can do something like this:

const results = await this.spectral.run(Library.writeDocumentToJSONString(node as Document));
gayanper commented 2 years ago

The Spectral API also allows a string, so we can do something like this:

const results = await this.spectral.run(Library.writeDocumentToJSONString(node as Document));

Thanks i will try it. I create a PR for studio as well adding support to pass in the extensions into validation and use the new validateDocument method.

craicoverflow commented 2 years ago

Adding an official Spectral extension is underway in https://github.com/Apicurio/apicurio-data-models-validation-extensions/pull/1

Usage feedback is welcome!

gayanper commented 2 years ago

Adding an official Spectral extension is underway in Apicurio/apicurio-data-models-validation-extensions#1

Usage feedback is welcome!

Nice may be this might be used with this new extension https://github.com/Apicurio/apicurio-studio/pull/1862

gayanper commented 2 years ago

Adding an official Spectral extension is underway in Apicurio/apicurio-data-models-validation-extensions#1

Usage feedback is welcome!

I was working on integrating the spectral my self by writing a validation extension which i could get it to work. But one thing i found was the spectral doesn't work under webview, so i ended up running spectral inside extension host and communicate via sendMessage, have you found a away to get around it in the above extension ?

If its handled i can try to integrate this first by hardcoding to see if it work and then improve it work as a side car extension for the main apicurito extension.

EricWittmann commented 2 years ago

Interesting approach with sendMessage. @craicoverflow is off on PTO for a couple of weeks. But I can say that he has been looking at implementing this via a microservice. I'm intrigued by your approach, but I think it would only work in the context of Apicurito (and I guess specifically the PWA version?). Am I right about that? This same technology (the openapi editor) really needs to be functional in a variety of deployment scenarios, not just Apicurito....

legas117 commented 11 months ago

Hello, I recently tried to implement the solution presented here and I encountered quite a few problem while following the read-me. Is this solution still being developed or has this been abandonned ?