jc21 / cypress-swagger-validation Goto Github PK
View Code? Open in Web Editor NEWValidate your request responses against Swagger JSON Endpoints. AKA Contract Testing.
License: MIT License
Validate your request responses against Swagger JSON Endpoints. AKA Contract Testing.
License: MIT License
Hi and thanks for the nice plugin!
I wanted to share an idea of validating intercepts with the openapi schema.
Kind of like:
beforeEach(() => {
cy.intercept('*', req => {
req.continue(res => {
cy.task('validateSwaggerSchema', {
file: './../swagger.json',
endpoint: req.url,
method: req.method,
statusCode: res.statusCode,
responseSchema: res.body,
verbose: true // optional, default: false
}).should('equal', null);
});
});
});
This example does not work because of cypress-io/cypress#7667
This would ensure fixtures (e.g. cy.intercept('GET', '/api/identity', { fixture: 'identity/sys-admin.json'})
) are still adhering to the schema.
Thanks for the work that you've been doing with this lib. I'm testing out a couple of OAS validator libs to integrate with our Cypress tests and I'm having some troubles integrating yours with Cypress 13.5.0 - was wondering if you can help out.
The format for cypress.config.ts
changed itm and following your example:
import {expect, use} from "chai";
const {SwaggerValidation} = require('@jc21/cypress-swagger-validation');
export default defineConfig({
screenshotOnRunFailure: false,
env: {
hideCredentials: true,
},
e2e: {
baseUrl: 'https://api.stg.thousandeyes.com',
setupNodeEvents(on, config) {
on('task', {
SwaggerValidation(config){
return config;
},
otherTask(){}
simply states that validateSwaggerSchema
does not exist. I also tried putting everything in the test, without success:
describe('API Test', () => {
it.only('should satisfy OpenAPI spec', () => {
MyEndpoint.getAll().then((response) => {
const config = {
file: 'path.to.yaml.file',
endpoint: '/v7/account-groups',
method: 'GET',
statusCode: 200,
responseSchema: response.body,
verbose: true,
}
// cy.task('validateSwaggerSchema', config).should('equal', null);
SwaggerValidation(config).validateSwaggerSchema(config)
});
});
});
Do you have any idea what I'm doing wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.