Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
57 changes: 57 additions & 0 deletions .github/scripts/validate-openapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const SwaggerParser = require('@apidevtools/swagger-parser');
const glob = require('glob');

// Define the files we want to validate
const TARGET_FILES = ['transaction.yaml', 'meta.yaml', 'registry.yaml'];

// Function to validate a single OpenAPI file
async function validateOpenApiFile(filePath) {
try {
await SwaggerParser.validate(filePath);
console.log(`✅ Valid: ${filePath}`);
return true;
} catch (error) {
console.error(`❌ Invalid: ${filePath}`);
console.error(` Error: ${error.message}`);

if (error.path) {
console.error(` Location: ${error.path.join('.')}`);
}
return false;
}
}

// Main function
async function main() {
let failures = 0;

// Find all target files in the repository
for (const targetFile of TARGET_FILES) {
const files = glob.sync(`**/${targetFile}`, {
ignore: ['**/node_modules/**', '.github/**']
});

console.log(`Found ${files.length} ${targetFile} files to validate`);

// Validate each file
for (const file of files) {
const isValid = await validateOpenApiFile(file);
if (!isValid) failures++;
}
}

// Exit with appropriate code
if (failures > 0) {
console.error(`\n❌ Validation failed for ${failures} files`);
process.exit(1);
} else {
console.log('\n✅ All OpenAPI specifications are valid!');
process.exit(0);
}
}

// Run the validation
main().catch(error => {
console.error('An unexpected error occurred during validation:', error);
process.exit(1);
});
114 changes: 114 additions & 0 deletions .github/workflows/openapi-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: OpenAPI Validation

on:
pull_request:
branches: [ master, main ]
paths:
- '**/transaction.yaml'
- '**/meta.yaml'
- '**/registry.yaml'
workflow_dispatch:

jobs:
validate-openapi:
name: Validate OpenAPI Specifications
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: |
npm init -y
npm install @apidevtools/swagger-parser glob

- name: Create and run validation script
run: |
mkdir -p .github/scripts
cat > .github/scripts/validate-openapi.js << 'EOF'
const SwaggerParser = require('@apidevtools/swagger-parser');
const glob = require('glob');
const fs = require('fs');

// Files to validate as specified in the requirements
const TARGET_FILES = ['transaction.yaml', 'meta.yaml', 'registry.yaml'];

// Function to validate OpenAPI specification file
async function validateOpenApiFile(filePath) {
console.log(`Validating ${filePath}...`);
try {
// Parse and validate the file
await SwaggerParser.validate(filePath);
console.log(`✅ Valid: ${filePath}`);
return true;
} catch (error) {
console.error(`❌ Invalid: ${filePath}`);
console.error(` Error: ${error.message}`);

// If there's a pointer to the exact location of the error, show it
if (error.path) {
console.error(` Location: ${error.path.join('.')}`);
}
return false;
}
}

// Main function to find and validate all relevant OpenAPI files
async function main() {
let failures = 0;
let validatedFiles = 0;

// Find all target files in the repository
for (const targetFile of TARGET_FILES) {
const files = glob.sync(`**/${targetFile}`, {
ignore: ['**/node_modules/**', '.github/**']
});

console.log(`Found ${files.length} ${targetFile} files to validate`);

// Validate each file
for (const file of files) {
validatedFiles++;
const isValid = await validateOpenApiFile(file);
if (!isValid) failures++;
}
}

console.log(`\nValidation summary: ${validatedFiles} files processed, ${failures} failures found`);

// Exit with appropriate code
if (failures > 0) {
console.error(`\n❌ Validation failed for ${failures} files`);
process.exit(1);
} else {
console.log('\n✅ All OpenAPI specifications are valid!');
process.exit(0);
}
}

// Run the validation
main().catch(error => {
console.error('An unexpected error occurred during validation:', error);
process.exit(1);
});
EOF

node .github/scripts/validate-openapi.js

- name: Report validation status on PR
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `⚠️ **OpenAPI Validation Failed**\n\nThe OpenAPI validation check has failed. Please check the GitHub Actions logs for details on which files failed validation and the specific errors found.`
});
2 changes: 2 additions & 0 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,5 @@ Not all future new features will be introduced in this way. Some new features im
While governance of the specification is the role of the CWG, the evolution of the specification happens through the participation of members of the developer community at large. Any person willing to contribute to the effort is welcome, and contributions may include filing or participating in issues, creating pull requests, or helping others with such activities.

However, during any interaction with the community or its members, there is a code of conduct and a set of community guidelines that everyone is expected to adhere to. Please find the details [here](https://becknprotocol.io/community-guidelines/).


10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ All communication using beckn protocol have the following packet structure

While beckn protocol it designed to be transport agnostic, it is conventional to use HTTP as the default transport protocol. Additional layers like security and trust can be layered on top of this protocol using exisiting standards like HTTPS and SSL. It is recommended that any platform implementing beckn protocol use HTTPS to secure its communication.

## OpenAPI Validation

This repository uses automated validation to ensure all OpenAPI specifications conform to the OpenAPI 3.0 standard. The following files are validated:
- transaction.yaml
- meta.yaml
- registry.yaml

When submitting a pull request, please ensure your changes pass the automated validation checks. The status of these checks is shown below:

![OpenAPI Validation](https://github.com/beckn/protocol-specifications/workflows/OpenAPI%20Validation/badge.svg)

## Communication

Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/glob

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/node-which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading