-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: migrate oas libraries of ours into this new monorepo #811
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7291230
refactor(monorepo): moving the library over to a monorepo structure
erunion c0a4e94
refactor(oas-extensions): moving `oas-extensions` into this monorepo
erunion c961ada
refactor(oas-normalize): moving `oas-normalize` into this monorepo
erunion 4d13706
refactor(oas-to-har): moving `oas-to-har` into this monorepo
erunion 4d8908e
fix: adding a test i forgot to commit
erunion f0c03f8
fix: prettier issues
erunion 6d1cd0a
ci: fix build ordering for linting
erunion 4ca177a
fix: out of date dep
erunion c6a5269
Merge branch 'main' into refactor/migrate-oas-libraries
erunion ea24a04
refactor: build cleanup (#812)
kanadgupta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,5 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v4 | ||
- run: npm ci | ||
- run: npm run build | ||
- run: npm run lint |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
coverage/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"], | ||
"root": true, | ||
"rules": { | ||
"@typescript-eslint/consistent-type-imports": "error", | ||
"@typescript-eslint/explicit-module-boundary-types": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
test/ | ||
.eslint* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright © 2023 ReadMe | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose | ||
with or without fee is hereby granted, provided that the above copyright notice | ||
and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | ||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF | ||
THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# @readme/oas-extensions | ||
|
||
A list of extensions that ReadMe has added to extend the OpenAPI Specification. | ||
|
||
https://docs.readme.com/docs/openapi-extensions | ||
|
||
[![Build](https://github.com/readmeio/oas/workflows/CI/badge.svg)](https://github.com/readmeio/oas/tree/main/packages/oas-extensions) | ||
|
||
[![](https://raw.githubusercontent.com/readmeio/.github/main/oss-header.png)](https://readme.io) | ||
|
||
## Installation | ||
|
||
``` | ||
npm install --save @readme/oas-extensions | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "@readme/oas-extensions", | ||
"description": "A list of extensions that ReadMe has added to extend the OpenAPI Specification", | ||
"version": "20.0.1", | ||
"author": "Jon Ursenbach <jon@readme.io>", | ||
"license": "ISC", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.js" | ||
} | ||
}, | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.cts", | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/readmeio/oas.git", | ||
"directory": "packages/oas-extensions" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/readmeio/oas/issues" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"lint": "npm run lint:types && npm run lint:js", | ||
"lint:js": "eslint . --ext .js,.ts", | ||
"lint:types": "tsc --noEmit", | ||
"prebuild": "rm -rf dist/", | ||
"prepack": "npm run build", | ||
"test": "vitest run --coverage" | ||
}, | ||
"peerDependencies": { | ||
"oas": "file:../oas" | ||
}, | ||
"devDependencies": { | ||
"@readme/oas-examples": "^5.12.0", | ||
"@vitest/coverage-v8": "^0.34.3", | ||
"eslint": "^8.48.0", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.3" | ||
}, | ||
"prettier": "@readme/eslint-config/prettier" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import type Oas from 'oas'; | ||
import type Operation from 'oas/operation'; | ||
|
||
export const CODE_SAMPLES = 'code-samples'; | ||
export const EXPLORER_ENABLED = 'explorer-enabled'; | ||
export const HEADERS = 'headers'; | ||
export const METRICS_ENABLED = 'metrics-enabled'; | ||
export const PROXY_ENABLED = 'proxy-enabled'; | ||
export const SAMPLES_ENABLED = 'samples-enabled'; | ||
export const SAMPLES_LANGUAGES = 'samples-languages'; | ||
export const SEND_DEFAULTS = 'send-defaults'; | ||
export const SIMPLE_MODE = 'simple-mode'; | ||
|
||
// Make sure you document any changes on here: | ||
// https://docs.readme.com/docs/openapi-extensions | ||
export interface Extensions { | ||
[CODE_SAMPLES]: { | ||
code: string; | ||
install?: string; | ||
language: string; | ||
name?: string; | ||
}; | ||
[EXPLORER_ENABLED]: boolean; | ||
[HEADERS]: Record<string, string | number>[]; | ||
[METRICS_ENABLED]: boolean; | ||
[PROXY_ENABLED]: boolean; | ||
[SAMPLES_ENABLED]: boolean; // @deprecated | ||
[SAMPLES_LANGUAGES]: string[]; | ||
[SEND_DEFAULTS]: boolean; // @deprecated | ||
[SIMPLE_MODE]: boolean; | ||
} | ||
|
||
export const defaults: Extensions = { | ||
[CODE_SAMPLES]: undefined, | ||
[EXPLORER_ENABLED]: true, | ||
[HEADERS]: undefined, | ||
[METRICS_ENABLED]: true, | ||
[PROXY_ENABLED]: true, | ||
[SAMPLES_ENABLED]: true, | ||
[SAMPLES_LANGUAGES]: ['shell', 'node', 'ruby', 'php', 'python', 'java', 'csharp'], | ||
[SEND_DEFAULTS]: false, | ||
[SIMPLE_MODE]: true, | ||
}; | ||
|
||
/** | ||
* With one of our custom OpenAPI extensions, look for it in either an instance of `oas` or an | ||
* instance of the `Operation` class in `oas`. | ||
* | ||
* Our custom extensions can either be nestled inside of an `x-readme` object or at the root level | ||
* with an `x-` prefix. | ||
* | ||
* @see {@link https://npm.im/oas} | ||
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions} | ||
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions} | ||
* @param extension Specification extension to lookup. | ||
* @param oas An instance of the `oas` library class. | ||
* @param operation An instsance of the `Operation` class from the `oas` library. | ||
* @returns Contents of the extension if found, otherwise the extensions default value. | ||
*/ | ||
export function getExtension(extension: keyof Extensions, oas: Oas, operation?: Operation) { | ||
if (operation) { | ||
if (operation.hasExtension('x-readme')) { | ||
const data = operation.getExtension('x-readme') as Extensions; | ||
if (data && typeof data === 'object' && extension in data) { | ||
return data[extension]; | ||
} | ||
} | ||
|
||
if (operation.hasExtension(`x-${extension}`)) { | ||
return operation.getExtension(`x-${extension}`); | ||
} | ||
} | ||
|
||
// Because our `code-samples` extension is intended for operation-level use, if it's instead | ||
// placed at the OAS-level we should ignore it. | ||
if (extension === CODE_SAMPLES) { | ||
return defaults[extension]; | ||
} | ||
|
||
if (oas.hasExtension('x-readme')) { | ||
const data = oas.getExtension('x-readme') as Extensions; | ||
if (data && typeof data === 'object' && extension in data) { | ||
return data[extension]; | ||
} | ||
} | ||
|
||
if (oas.hasExtension(`x-${extension}`)) { | ||
return oas.getExtension(`x-${extension}`); | ||
} | ||
|
||
return defaults[extension]; | ||
} | ||
|
||
/** | ||
* With one of our custom OpenAPI extensions, determine if it's valid on a given instance of `oas`. | ||
* | ||
* @todo add support for validating on operations. | ||
* | ||
* @see {@link https://npm.im/oas} | ||
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions} | ||
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions} | ||
* @param extension Specification extension to lookup. | ||
* @param oas An instance of the `oas` library class. | ||
*/ | ||
export function validateExtension(extension: keyof Extensions, oas: Oas) { | ||
if (oas.hasExtension('x-readme')) { | ||
const data = oas.getExtension('x-readme') as Extensions; | ||
if (typeof data !== 'object' || Array.isArray(data) || data === null) { | ||
throw new TypeError('"x-readme" must be of type "Object"'); | ||
} | ||
|
||
if (extension in data) { | ||
if ([CODE_SAMPLES, HEADERS, SAMPLES_LANGUAGES].includes(extension)) { | ||
if (!Array.isArray(data[extension])) { | ||
throw new TypeError(`"x-readme.${extension}" must be of type "Array"`); | ||
} | ||
} else if (typeof data[extension] !== 'boolean') { | ||
throw new TypeError(`"x-readme.${extension}" must be of type "Boolean"`); | ||
} | ||
} | ||
} | ||
|
||
// If the extension isn't grouped under `x-readme`, we need to look for them with `x-` prefixes. | ||
if (oas.hasExtension(`x-${extension}`)) { | ||
const data = oas.getExtension(`x-${extension}`); | ||
if ([CODE_SAMPLES, HEADERS, SAMPLES_LANGUAGES].includes(extension)) { | ||
if (!Array.isArray(data)) { | ||
throw new TypeError(`"x-${extension}" must be of type "Array"`); | ||
} | ||
} else if (typeof data !== 'boolean') { | ||
throw new TypeError(`"x-${extension}" must be of type "Boolean"`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@readme/eslint-config/testing/vitest" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh thank you for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i was sick of seeing that cloudfront.net link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an open design request to update this and i was literally thinking of doing this so we can just update the graphic in one fell swoop