diff --git a/.github/workflows/megalinter.yml b/.github/workflows/megalinter.yml deleted file mode 100644 index 1ab1ab18e0..0000000000 --- a/.github/workflows/megalinter.yml +++ /dev/null @@ -1,65 +0,0 @@ ---- -# MegaLinter GitHub Action configuration file -# More info at https://megalinter.io -name: MegaLinter - -on: # yamllint disable-line rule:truthy - # Pull Requests to main - pull_request: - branches: [master, main] - -env: # Comment env block if you do not want to apply fixes - # Apply linter fixes configuration - APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool) - APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all) - APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request) - -concurrency: - group: ${{ github.ref }}-${{ github.workflow }} - cancel-in-progress: true - -jobs: - build: - name: MegaLinter - runs-on: ubuntu-latest - permissions: - # Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR - # Remove the ones you do not need - contents: write - issues: write - pull-requests: write - steps: - # Git Checkout - - name: Checkout Code - uses: actions/checkout@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - fetch-depth: 0 # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to improve performances - - # MegaLinter - - name: MegaLinter - id: ml - # You can override MegaLinter flavor used to have faster performances - # More info at https://megalinter.io/flavors/ - uses: oxsecurity/megalinter/flavors/java@v7.3.0 - env: - # All available variables are described in documentation - # https://megalinter.io/configuration/ - # VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources - VALIDATE_ALL_CODEBASE: true - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY - DISABLE: COPYPASTE,MARKDOWN - DISABLE_LINTERS: SPELL_CSPELL,SPELL_LYCHEE,YAML_PRETTIER,REPOSITORY_SEMGREP,REPOSITORY_DEVSKIM,REPOSITORY_KICS,REPOSITORY_TRIVY,REPOSITORY_CHECKOV,REPOSITORY_GITLEAKS,JAVA_PMD - YAML_YAMLLINT_CONFIG_FILE: ".yamllint.yaml" - JAVA_CHECKSTYLE_CONFIG_FILE: "javalint.xml" - - # Upload MegaLinter artifacts - - name: Archive production artifacts - if: ${{ success() }} || ${{ failure() }} - uses: actions/upload-artifact@v3 - with: - name: MegaLinter reports - path: | - megalinter-reports - mega-linter.log diff --git a/.github/workflows/spectral-workflow.yml b/.github/workflows/spectral-workflow.yml new file mode 100644 index 0000000000..073c61851e --- /dev/null +++ b/.github/workflows/spectral-workflow.yml @@ -0,0 +1,39 @@ +name: Spectral Lint + +on: + # Pull Requests to main + pull_request: + branches: [master,main] + push: + branches: + - draft/add-java-script-based-testing-by-spectral # You can specify the branch you want to trigger this on + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Spectral + run: npm install -g @stoplight/spectral-cli + + - name: Install 'nspell' Module + run: npm install nspell && npm install dictionary-en + working-directory: ${{ github.workspace }} + + - name: Run Custom Spectral Linting + run: spectral lint code/API_definitions/qod-api.yaml --verbose --ruleset .spectral.yml + # Replace 'openapi.yaml' with the path to your OpenAPI specification file + + - name: Run spectral:oas Spectral Linting + run: spectral lint code/API_definitions/qod-api.yaml --verbose --ruleset .spectral-oas.yml + # Replace 'openapi.yaml' with the path to your OpenAPI specification file + + - name: Upload Spectral Results + if: always() # Always upload the results, even if linting fails + uses: actions/upload-artifact@v2 + with: + name: spectral-results + path: spectral-report.json diff --git a/.spectral-oas.yml b/.spectral-oas.yml new file mode 100644 index 0000000000..72a7fd17bb --- /dev/null +++ b/.spectral-oas.yml @@ -0,0 +1,2 @@ +extends: + - "spectral:oas" diff --git a/.spectral.yml b/.spectral.yml new file mode 100644 index 0000000000..b4ccb74d45 --- /dev/null +++ b/.spectral.yml @@ -0,0 +1,33 @@ +functions: + - check-spelling-code +functionsDir: "./lint_functions" +rules: + language-spelling-names: + message: "{{error}}" + severity: warn + given: + - "$.paths.*~" + - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].name" + - "$..properties.*~" + then: + function: check-spelling-code + + language-spelling-texts: + message: "{{error}}" + severity: warn + given: + - "$.info.title" + - "$.info.summary" + - "$.info.description" + - "$.paths.*.*.parameters[?(@.in==='query' || @.in==='path' || @.in==='cookie')].description" + - "$..properties.*.description" + then: + function: check-spelling-code + + language-spelling-schema-names: + message: "{{error}}" + severity: warn + given: + - "$.components.schemas.*~" + then: + function: check-spelling-code diff --git a/code/API_definitions/qod-api.yaml b/code/API_definitions/qod-api.yaml index 9eb2242e2f..9a3ce36eb3 100644 --- a/code/API_definitions/qod-api.yaml +++ b/code/API_definitions/qod-api.yaml @@ -104,7 +104,7 @@ paths: - Session notifications callback summary: "Session notifications callback" description: | - Important: this endpoint is to be implemented by the API consumer. + Impt: this endpoint is to be implemented by the API consumer. The QoD server will call this endpoint whenever any network related event occurs. Currently only QOS_STATUS_CHANGED event is defined. operationId: postNotification @@ -661,7 +661,7 @@ components: QosProfileName: description: | A unique name for identifying a specific QoS profile. - This may follow different formats depending on the service providers implementation. + This may follow difrent formats depending on the service providers implementation. Some options addresses: - A UUID style string - Support for predefined profiles QOS_S, QOS_M, QOS_L, and QOS_E diff --git a/lint_functions/check-spelling-code.js b/lint_functions/check-spelling-code.js new file mode 100644 index 0000000000..8fc0d7d727 --- /dev/null +++ b/lint_functions/check-spelling-code.js @@ -0,0 +1,36 @@ +var dictionary = require('dictionary-en') +var nspell = require('nspell') +var exceptions = ['eventId', 'eventType', 'eventTime', 'eventSubscriptionId', 'publicAddress', 'subnet', 'privateAddress', 'publicPort', 'sessionId', 'UUID', 'devicePorts', 'QoS', 'qosProfile', 'TCP', 'UDP', 'QOS_S', 'QOS_M', 'QOS_L', 'QOS_E', 'webhook', 'notificationUrl', 'notificationAuthToken', 'startedAt', 'expiresAt', 'qosprofiles', 'minDuration', 'maxDuration', 'packetDelayBudget', 'oneway', 'endtoend', 'jitter', 'roundtrip', 'ITU', 'eg', 'realtime', 'packetErrorLossRate', 'QCI', 'maxDownstreamRate', 'QOS_STATUS_CHANGED', 'qosStatus', 'statusInfo', 'DURATION_EXPIRED', 'Enduser', 'IoT', 'sensorsactuators', 'phoneNumber', 'networkAccessIdentifier', 'MNO', 'invoker', 'MNOs', 'MSISDN', 'GPSI', 'IdentifierDomain', 'DNS', 'ie', 'applicationServerPorts', 'maxDownstreamBurstRate', 'maxUpstreamRate', 'QoD', 'cmunication', 'QualityOnDemand', 'Telco', 'indepth', 'Telecom', 'VRGaming', 'backend', 'OverviewhttpsrawgithubusercontentcomcamaraprojectQualityOnDemandmaindocumentationAPI_documentationresourcesQoD_latency_overviewPNG', 'QOD', 'OAuth', 'andor', 'AppFlow', 'portranges', 'AppFlows', 'portportranges', 'Appflow', 'br', 'APIhttpsrawgithubusercontentcomcamaraprojectQualityOnDemandmaindocumentationAPI_documentationresourcesQoD_detailsPNG', 'CAMARA', 'DRAFThttpsgithubcomcamaraprojectQualityOnDemandblobmaindocumentationAPI_documentationQoSProfile_Mapping_Tablemd', 'IETF', 'addressmask', 'applicationServer', 'dottedquad', 'sessionssessionId', 'createSession', 'targetMinUpstreamRate', 'SessionId', 'SessionInfo', 'EventNotification', 'PhoneNumber', 'QosStatus', 'EventQosStatus', 'ErrorInfo', 'GBR', 'latencysensitive', 'DOCSIS', 'maxUpstreamBurstRate', 'targetMinDownstreamRate', 'qosprofilesname', 'RateUnitEnum', 'CreateSession', 'PortsSpec', 'QosProfile', 'QosProfileName', 'TimeUnitEnum', 'QosProfileStatusEnum', 'EventId', 'EventType', 'EventTime', 'QosStatusChangedEvent', 'eventDetail', 'NETWORK_TERMINATED', 'StatusInfo', 'ApplicationServer', 'NetworkAccessIdentifier']; +var separatorsRegex = /\s/; +var mistakes= []; + +function includesNumber(value) { + return /\d/.test(value); +} +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} +export default async function (input) { + dictionary ((err, dict) => { + if (err) { + throw err; + } + var spell = nspell(dict) + var no_special_characters= input.replace(/[^\w\s]/gi, '') + const words = no_special_characters.split(separatorsRegex); + var errors= words + .filter((word) => !exceptions.includes(word)) + .filter((word) => !spell.correct(word)) + .filter((word) => !word == '') + .filter((word) => !includesNumber(word)); + + if ((errors.length > 0) && (mistakes[mistakes.length-1] != errors[errors.length-1])) { + mistakes.push(errors); + errors = []; + console.log("There was a spelling mistake: " + mistakes); + } + }) + sleep(150000).then(() => {return [{ + message: `Spelling mistakes found: ${mistakes.join(', ')}`, + }];}); +}; diff --git a/spell-check.js b/spell-check.js new file mode 100644 index 0000000000..75095f0b83 --- /dev/null +++ b/spell-check.js @@ -0,0 +1,30 @@ +const fs = require('fs'); +const spellChecker = require('spellchecker'); + +function findSpellingMistakesInYamlFile(filePath) { + // Read the content of the YAML file + const yamlContent = fs.readFileSync(filePath, 'utf8'); + + // Split the content into words (split by spaces, newlines, etc.) + const words = yamlContent.split(/\s+/); + + // Filter out any words that should be excluded from spell checking + const exceptions = ["bic", "datetime", "gt", "gte", "icontains", "iban", "idempotency", "isnull", "lt", "lte", "md5", "mimetype", "oid", "userpic"]; + const filteredWords = words.filter((word) => !exceptions.includes(word.toLowerCase())); + + // Find spelling mistakes + const mistakes = filteredWords.filter((word) => spellChecker.isMisspelled(word)); + + return mistakes; +} + +// Example usage: +const filePath = 'code/API_definitions/qod-api2.yaml'; +const spellingMistakes = findSpellingMistakesInYamlFile(filePath); + +if (spellingMistakes.length > 0) { + console.log('Spelling mistakes found:'); + console.log(spellingMistakes); +} else { + console.log('No spelling mistakes found.'); +}