Skip to content

Commit

Permalink
feat: initial commit (#1)
Browse files Browse the repository at this point in the history
* feat: initial commit

* fix: rebuild lockfile

* chore: delete unused file oops

* Update __tests__/.eslintrc

Co-authored-by: Jon Ursenbach <[email protected]>

---------

Co-authored-by: Jon Ursenbach <[email protected]>
  • Loading branch information
kanadgupta and erunion authored Jan 19, 2024
1 parent 2a7f144 commit 09178a0
Show file tree
Hide file tree
Showing 21 changed files with 10,099 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
dist/
node_modules/
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"],
"root": true
}
33 changes: 33 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: '/'
schedule:
interval: monthly
reviewers:
- erunion
labels:
- dependencies
commit-message:
prefix: chore(deps)
prefix-development: chore(deps-dev)

- package-ecosystem: npm
directory: '/'
schedule:
interval: monthly
open-pull-requests-limit: 10
reviewers:
- erunion
- kanadgupta
labels:
- dependencies
groups:
minor-development-deps:
dependency-type: 'development'
update-types:
- minor
- patch
commit-message:
prefix: chore(deps)
prefix-development: chore(deps-dev)
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version:
- 18
- 20

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- run: npm cit
35 changes: 35 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'CodeQL'

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 0 1 * *'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ['javascript']

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
dist/
node_modules/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lockfile-version=3
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
dist/
node_modules/
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright © 2024 ReadMe

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions __tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@readme/eslint-config/testing/vitest"]
}
112 changes: 112 additions & 0 deletions __tests__/__fixtures__/invalid-oas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"description": "A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "Swagger API Team",
"email": "[email protected]",
"url": "http://swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"servers": [
{
"url": "http://petstore.swagger.io/api"
}
],
"paths": {
"/pets": {
"get": {
"description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
"operationId": "findPets",
"parameters": [
{
"name": "tags",
"in": "query",
"description": "tags to filter by",
"required": false,
"style": "form",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
{
"name": "limit",
"in": "query",
"description": "maximum number of results to return",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "pet response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Pet": {
"allOf": [
{
"$ref": "#/components/schemas/NewPet"
},
{
"required": ["id"],
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
}
}
]
},
"NewPet": {
"required": ["name"],
"properties": {
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
}
}
}
61 changes: 61 additions & 0 deletions __tests__/__fixtures__/valid-oas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Single Path",
"description": "This is a slimmed down single path version of the Petstore definition."
},
"servers": [
{
"url": "https://httpbin.org"
}
],
"paths": {
"/pet/{id}": {
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer"
}
}
],
"put": {
"tags": ["pet"],
"summary": "Update a pet",
"description": "This operation will update a pet in the database.",
"responses": {
"400": {
"description": "Invalid id value"
}
},
"security": [
{
"apiKey": []
}
]
},
"get": {
"tags": ["pet"],
"summary": "Find a pet",
"description": "This operation will find a pet in the database.",
"responses": {
"400": {
"description": "Invalid status value"
}
},
"security": []
}
}
},
"components": {
"securitySchemes": {
"apiKey": {
"type": "http",
"scheme": "basic"
}
}
}
}
26 changes: 26 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import toBeAValidOpenAPIDefinition from '../src';

import invalid from './__fixtures__/invalid-oas.json';
import valid from './__fixtures__/valid-oas.json';

expect.extend({ toBeAValidOpenAPIDefinition });

test('should accept a valid OpenAPI', async () => {
await expect(valid).toBeAValidOpenAPIDefinition();
});

test('should accept a valid OpenAPI with transformer', async () => {
await expect(valid).toBeAValidOpenAPIDefinition((spec: Record<string, string>) => {
// eslint-disable-next-line no-param-reassign
spec.openapi = '3.1.0';
return spec;
});
});

test('should reject an invalid OpenAPI', async () => {
await expect(invalid).not.toBeAValidOpenAPIDefinition();
});

test('should reject yet another invalid OpenAPI', async () => {
await expect({}).not.toBeAValidOpenAPIDefinition();
});
9 changes: 9 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "es6",
"moduleResolution": "node",
"strict": false,
},
"include": ["../src/**/*", "*.ts", "**/*"],
}
6 changes: 6 additions & 0 deletions __tests__/tsconfig.vitest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["vitest/globals"]
}
}
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('jest').Config} */
module.exports = {
coveragePathIgnorePatterns: ['__tests__/__fixtures__/'],
preset: 'ts-jest/presets/js-with-ts',
testPathIgnorePatterns: ['__tests__/__fixtures__/'],
testRegex: '\\/__tests__/[A-z]+\\.test\\.(js?|ts?)$',
transform: {
'\\.ts$': ['ts-jest', { tsconfig: '__tests__/tsconfig.json' }],
},
};
Loading

0 comments on commit 09178a0

Please sign in to comment.