mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 14:14:56 +03:00
Merge remote-tracking branch 'origin/master' into feat/callbacks-support
This commit is contained in:
commit
71c061f213
|
@ -9,4 +9,4 @@
|
|||
!webpack.config.ts
|
||||
|
||||
!package.json
|
||||
!yarn.lock
|
||||
!package-lock.json
|
||||
|
|
49
.eslintrc.js
Normal file
49
.eslintrc.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
},
|
||||
parser: '@typescript-eslint/parser',
|
||||
extends: ['plugin:react/recommended', 'plugin:@typescript-eslint/recommended'],
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
sourceType: 'module',
|
||||
createDefaultProgram: true,
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
},
|
||||
settings: {
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
plugins: ['@typescript-eslint', 'import'],
|
||||
rules: {
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-use-before-define': 'off',
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/no-inferrable-types': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/ban-ts-ignore': 'off',
|
||||
|
||||
'react/prop-types': 'off',
|
||||
|
||||
'import/no-extraneous-dependencies': 'error',
|
||||
'import/no-internal-modules': [
|
||||
'error',
|
||||
{
|
||||
allow: [
|
||||
'prismjs/**',
|
||||
'perfect-scrollbar/**',
|
||||
'react-dom/*',
|
||||
'core-js/**',
|
||||
'memoize-one/**',
|
||||
'unfetch/**',
|
||||
'raf/polyfill',
|
||||
'**/fixtures/**', // for tests
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
32
.github/CONTRIBUTING.md
vendored
32
.github/CONTRIBUTING.md
vendored
|
@ -15,56 +15,56 @@ Hi! We're really excited that you are interested in contributing to ReDoc. Befor
|
|||
Before submitting a pull request, please make sure the following is done:
|
||||
|
||||
1. Fork the repository and create your branch from master.
|
||||
2. Run `yarn` in the repository root.
|
||||
2. Run `npm install` in the repository root.
|
||||
3. If you’ve fixed a bug or added code that should be tested, add tests!
|
||||
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development.
|
||||
5. Format your code with prettier (`yarn prettier`).
|
||||
4. Ensure the test suite passes (`npm test`). Tip: `npm test -- --watch TestName` is helpful in development.
|
||||
5. Format your code with prettier (`npm run prettier`).
|
||||
|
||||
## Development Setup
|
||||
|
||||
You will need [Node.js](http://nodejs.org) at `v8.0.0+` and [Yarn](https://yarnpkg.com/en/) at `v1.2.0+`
|
||||
You will need [Node.js](http://nodejs.org) at `v12.0.0+`.
|
||||
|
||||
After cloning the repo, run:
|
||||
|
||||
```bash
|
||||
$ yarn install # or npm
|
||||
$ npm install # or npm
|
||||
```
|
||||
|
||||
### Commonly used NPM scripts
|
||||
|
||||
``` bash
|
||||
# dev-server, watch and auto reload playground
|
||||
$ yarn start
|
||||
$ npm start
|
||||
|
||||
# start playground app in production environment
|
||||
$ yarn start:prod
|
||||
$ npm run start:prod
|
||||
|
||||
# runt tslint
|
||||
$ yarn lint
|
||||
$ npm run lint
|
||||
|
||||
# try autofix tslint issues
|
||||
$ yarn lint --fix
|
||||
$ npm run lint -- --fix
|
||||
|
||||
# run unit tests
|
||||
$ yarn unit
|
||||
$ npm run unit
|
||||
|
||||
# run e2e tests
|
||||
$ yarn e2e
|
||||
$ npm run e2e
|
||||
|
||||
# open cypress UI to debug e2e test
|
||||
$ yarn cy:open
|
||||
$ npm run cy:open
|
||||
|
||||
# run the full test suite, include linting / unit / e2e
|
||||
$ yarn test
|
||||
$ npm test
|
||||
|
||||
# prepare bundles
|
||||
$ yarn bundle
|
||||
$ npm run bundle
|
||||
|
||||
# format the code using prettier
|
||||
$ yarn prettier
|
||||
$ npm run prettier
|
||||
|
||||
# auto-generate changelog
|
||||
$ yarn changelog
|
||||
$ npm run changelog
|
||||
```
|
||||
|
||||
There are some other scripts available in the `scripts` section of the `package.json` file.
|
||||
|
|
9
.github/workflows/unit-tests.yml
vendored
9
.github/workflows/unit-tests.yml
vendored
|
@ -13,9 +13,8 @@ jobs:
|
|||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 10.x
|
||||
- name: yarn install, build, and test
|
||||
- name: npm install, build, and test
|
||||
run: |
|
||||
npm install -g yarn
|
||||
yarn install
|
||||
yarn bundle
|
||||
yarn test
|
||||
npm install
|
||||
npm run bundle
|
||||
npm test
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -34,4 +34,4 @@ cli/index.js
|
|||
/coverage
|
||||
.ghpages-tmp
|
||||
stats.json
|
||||
/package-lock.json
|
||||
yarn.lock
|
||||
|
|
|
@ -2,7 +2,6 @@ language: node_js
|
|||
node_js:
|
||||
- '10'
|
||||
cache:
|
||||
yarn: true
|
||||
directories:
|
||||
- "~/.cache"
|
||||
env:
|
||||
|
@ -35,6 +34,6 @@ deploy:
|
|||
tags: true
|
||||
- provider: script
|
||||
skip_cleanup: true
|
||||
script: yarn deploy:demo
|
||||
script: npm run deploy:demo
|
||||
on:
|
||||
tags: true
|
||||
|
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,3 +1,19 @@
|
|||
# [2.0.0-rc.24](https://github.com/Redocly/redoc/compare/v2.0.0-rc.23...v2.0.0-rc.24) (2020-03-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Add debounce for 300 ms when searching ([#1089](https://github.com/Redocly/redoc/issues/1089)) ([373f018](https://github.com/Redocly/redoc/commit/373f018d0c183f83d07a4dbad4a4e2c9ab159f69))
|
||||
* do not load SearchWorker if disableSearch is `true` ([#1191](https://github.com/Redocly/redoc/issues/1191)) ([af415e8](https://github.com/Redocly/redoc/commit/af415e89e8c074a3f7c84f76f24020a7bd545483)), closes [#764](https://github.com/Redocly/redoc/issues/764)
|
||||
* fix major search performance due to wrong marker element ([8c053cc](https://github.com/Redocly/redoc/commit/8c053cc474e88befc3338307317c0702d212d4c3)), closes [#1109](https://github.com/Redocly/redoc/issues/1109)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* new option expandSingleSchemaField ([7608800](https://github.com/Redocly/redoc/commit/7608800d0acaa2fa0099dc840e17cd5aa90b54ca))
|
||||
|
||||
|
||||
|
||||
# [2.0.0-rc.23](https://github.com/Redocly/redoc/compare/v2.0.0-rc.22...v2.0.0-rc.23) (2020-02-09)
|
||||
|
||||
|
||||
|
|
15
README.md
15
README.md
|
@ -64,11 +64,11 @@ Additionally, all the 1.x releases are hosted on our GitHub Pages-based CDN **(d
|
|||
| 1.17.x | 2.0 |
|
||||
|
||||
## Some Real-life usages
|
||||
- [Rebilly](https://rebilly.github.io/RebillyAPI)
|
||||
- [Rebilly](https://rebilly-api.redoc.ly/)
|
||||
- [Docker Engine](https://docs.docker.com/engine/api/v1.25/)
|
||||
- [Zuora](https://www.zuora.com/developer/api-reference/)
|
||||
- [Shopify Draft Orders](https://help.shopify.com/api/draft-orders)
|
||||
- [Discourse](http://docs.discourse.org)
|
||||
- [Commbox](https://www.commbox.io/api/)
|
||||
- [APIs.guru](https://apis.guru/api-doc/)
|
||||
- [FastAPI](https://github.com/tiangolo/fastapi)
|
||||
|
||||
|
@ -107,14 +107,14 @@ That's all folks!
|
|||
**IMPORTANT NOTE:** if you work with untrusted user spec, use `untrusted-spec` [option](#redoc-options-object) to prevent XSS security risks.
|
||||
|
||||
### 1. Install ReDoc (skip this step for CDN)
|
||||
Install using [yarn](https://yarnpkg.com):
|
||||
Install using [npm](https://docs.npmjs.com/getting-started/what-is-npm):
|
||||
|
||||
npm i redoc
|
||||
|
||||
or using [yarn](https://yarnpkg.com):
|
||||
|
||||
yarn add redoc
|
||||
|
||||
or using [npm](https://docs.npmjs.com/getting-started/what-is-npm):
|
||||
|
||||
npm install redoc --save
|
||||
|
||||
### 2. Reference redoc script in HTML
|
||||
For **CDN**:
|
||||
```html
|
||||
|
@ -230,6 +230,7 @@ You can use all of the following options with standalone version on <redoc> tag
|
|||
* `hideHostname` - if set, the protocol and hostname is not shown in the operation definition.
|
||||
* `hideLoading` - do not show loading animation. Useful for small docs.
|
||||
* `hideSingleRequestSampleTab` - do not show the request sample tab for requests with only one sample.
|
||||
* `expandSingleSchemaField` - automatically expand single field in a schema
|
||||
* `jsonSampleExpandLevel` - set the default expand level for JSON payload samples (responses and request body). Special value 'all' expands all levels. The default value is `2`.
|
||||
* `lazyRendering` - _Not implemented yet_ ~~if set, enables lazy rendering mode in ReDoc. This mode is useful for APIs with big number of operations (e.g. > 50). In this mode ReDoc shows initial screen ASAP and then renders the rest operations asynchronously while showing progress bar on the top. Check out the [demo](\\redocly.github.io/redoc) for the example.~~
|
||||
* `menuToggle` - if true clicking second time on expanded menu item will collapse it, default `false`.
|
||||
|
|
|
@ -17,7 +17,7 @@ const localDistDir = './benchmark/revisions/local/bundles';
|
|||
sh.rm('-rf', localDistDir);
|
||||
console.log(`Building local dist: ${localDistDir}`);
|
||||
sh.mkdir('-p', localDistDir);
|
||||
exec(`yarn bundle:lib --output-path ${localDistDir}`);
|
||||
exec(`npm run bundle:lib --output-path ${localDistDir}`);
|
||||
|
||||
const revisions = [];
|
||||
for (const arg of args) {
|
||||
|
@ -119,7 +119,7 @@ function buildRevisionDist(revision) {
|
|||
|
||||
const pwd = sh.pwd();
|
||||
sh.cd(buildDir);
|
||||
exec('yarn remove cypress puppeteer && yarn && yarn bundle:lib');
|
||||
exec('npm uninstall cypress puppeteer && npm install && npm run bundle:lib');
|
||||
sh.cd(pwd);
|
||||
return distDir;
|
||||
}
|
||||
|
|
2246
cli/package-lock.json
generated
Normal file
2246
cli/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "redoc-cli",
|
||||
"version": "0.9.6",
|
||||
"version": "0.9.7",
|
||||
"description": "ReDoc's Command Line Interface",
|
||||
"main": "index.js",
|
||||
"bin": "index.js",
|
||||
|
@ -19,7 +19,7 @@
|
|||
"node-libs-browser": "^2.2.1",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6",
|
||||
"redoc": "2.0.0-rc.23",
|
||||
"redoc": "2.0.0-rc.24",
|
||||
"styled-components": "^4.3.2",
|
||||
"tslib": "^1.10.0",
|
||||
"yargs": "^13.3.0"
|
||||
|
|
2076
cli/yarn.lock
2076
cli/yarn.lock
File diff suppressed because it is too large
Load Diff
|
@ -11,8 +11,8 @@ RUN apk update && apk add --no-cache git
|
|||
|
||||
# Install dependencies
|
||||
WORKDIR /build
|
||||
COPY package.json yarn.lock /build/
|
||||
RUN yarn install --frozen-lockfile --ignore-optional --ignore-scripts
|
||||
COPY package.json package-lock.json /build/
|
||||
RUN npm ci --no-optional --ignore-scripts
|
||||
|
||||
# copy only required for the build files
|
||||
COPY src /build/src
|
||||
|
|
|
@ -27,6 +27,8 @@ describe('Search', () => {
|
|||
it('should support arrow navigation', () => {
|
||||
getSearchInput().type('int', { force: true });
|
||||
|
||||
cy.wait(500);
|
||||
|
||||
getSearchInput().type('{downarrow}', { force: true });
|
||||
getResult(0).should('have.class', 'active');
|
||||
|
||||
|
|
17990
package-lock.json
generated
Normal file
17990
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
98
package.json
98
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "redoc",
|
||||
"version": "2.0.0-rc.23",
|
||||
"version": "2.0.0-rc.24",
|
||||
"description": "ReDoc",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -42,7 +42,7 @@
|
|||
"stats": "webpack --env.standalone --json --profile --mode=production > stats.json",
|
||||
"prettier": "prettier --write \"cli/index.ts\" \"src/**/*.{ts,tsx}\"",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
|
||||
"lint": "tslint --project tsconfig.json",
|
||||
"lint": "eslint 'src/**/*.{js,ts,tsx}'",
|
||||
"benchmark": "node ./benchmark/benchmark.js",
|
||||
"start:demo": "webpack-dev-server --hot --config demo/webpack.config.ts --mode=development",
|
||||
"compile:cli": "tsc custom.d.ts cli/index.ts --target es6 --module commonjs --types yargs",
|
||||
|
@ -52,47 +52,52 @@
|
|||
"docker:build": "docker build -f config/docker/Dockerfile -t redoc ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.7.5",
|
||||
"@babel/plugin-syntax-decorators": "7.7.4",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.7.4",
|
||||
"@babel/plugin-syntax-jsx": "7.7.4",
|
||||
"@babel/plugin-syntax-typescript": "7.7.4",
|
||||
"@cypress/webpack-preprocessor": "4.1.1",
|
||||
"@hot-loader/react-dom": "^16.11.0",
|
||||
"@types/chai": "4.2.7",
|
||||
"@types/dompurify": "^2.0.0",
|
||||
"@types/enzyme": "^3.10.4",
|
||||
"@babel/core": "7.8.7",
|
||||
"@babel/plugin-syntax-decorators": "7.8.3",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
||||
"@babel/plugin-syntax-jsx": "7.8.3",
|
||||
"@babel/plugin-syntax-typescript": "7.8.3",
|
||||
"@cypress/webpack-preprocessor": "4.1.3",
|
||||
"@hot-loader/react-dom": "^16.12.0",
|
||||
"@types/chai": "4.2.10",
|
||||
"@types/dompurify": "^2.0.1",
|
||||
"@types/enzyme": "^3.10.5",
|
||||
"@types/enzyme-to-json": "^1.5.3",
|
||||
"@types/jest": "^24.0.23",
|
||||
"@types/jest": "^25.1.4",
|
||||
"@types/json-pointer": "^1.0.30",
|
||||
"@types/lodash": "^4.14.149",
|
||||
"@types/lunr": "^2.3.2",
|
||||
"@types/mark.js": "^8.11.5",
|
||||
"@types/marked": "^0.7.2",
|
||||
"@types/marked": "^0.7.3",
|
||||
"@types/prismjs": "^1.16.0",
|
||||
"@types/prop-types": "^15.7.3",
|
||||
"@types/react": "^16.9.16",
|
||||
"@types/react-dom": "^16.9.4",
|
||||
"@types/react": "^16.9.23",
|
||||
"@types/react-dom": "^16.9.5",
|
||||
"@types/react-tabs": "^2.3.1",
|
||||
"@types/styled-components": "^4.4.1",
|
||||
"@types/tapable": "1.0.4",
|
||||
"@types/webpack": "^4.41.0",
|
||||
"@types/webpack-env": "^1.14.1",
|
||||
"@types/tapable": "1.0.5",
|
||||
"@types/webpack": "^4.41.7",
|
||||
"@types/webpack-env": "^1.15.1",
|
||||
"@types/yargs": "^13.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^2.24.0",
|
||||
"@typescript-eslint/parser": "^2.24.0",
|
||||
"babel-loader": "8.0.6",
|
||||
"babel-plugin-styled-components": "^1.10.6",
|
||||
"babel-plugin-styled-components": "^1.10.7",
|
||||
"beautify-benchmark": "^0.2.4",
|
||||
"bundlesize": "^0.18.0",
|
||||
"conventional-changelog-cli": "^2.0.28",
|
||||
"conventional-changelog-cli": "^2.0.31",
|
||||
"copy-webpack-plugin": "^5.1.1",
|
||||
"core-js": "^3.5.0",
|
||||
"coveralls": "^3.0.9",
|
||||
"css-loader": "^3.3.0",
|
||||
"css-loader": "^3.4.2",
|
||||
"cypress": "~3.7.0",
|
||||
"deploy-to-gh-pages": "^1.3.7",
|
||||
"enzyme": "^3.10.0",
|
||||
"enzyme-adapter-react-16": "^1.15.1",
|
||||
"enzyme-to-json": "^3.4.3",
|
||||
"enzyme": "^3.11.0",
|
||||
"enzyme-adapter-react-16": "^1.15.2",
|
||||
"enzyme-to-json": "^3.4.4",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-import": "^2.20.1",
|
||||
"eslint-plugin-react": "^7.19.0",
|
||||
"fork-ts-checker-webpack-plugin": "3.1.1",
|
||||
"html-webpack-plugin": "^3.1.0",
|
||||
"jest": "^24.9.0",
|
||||
|
@ -100,27 +105,24 @@
|
|||
"lodash": "^4.17.15",
|
||||
"mobx": "^4.3.1",
|
||||
"prettier": "^1.19.1",
|
||||
"prettier-eslint": "^9.0.1",
|
||||
"raf": "^3.4.1",
|
||||
"react": "^16.12.0",
|
||||
"react-hot-loader": "^4.12.18",
|
||||
"react-dom": "^16.12.0",
|
||||
"rimraf": "^3.0.0",
|
||||
"react": "^16.13.0",
|
||||
"react-dom": "^16.13.0",
|
||||
"react-hot-loader": "^4.12.19",
|
||||
"rimraf": "^3.0.2",
|
||||
"shelljs": "^0.8.3",
|
||||
"source-map-loader": "^0.2.4",
|
||||
"style-loader": "^1.0.1",
|
||||
"style-loader": "^1.1.3",
|
||||
"styled-components": "^4.4.1",
|
||||
"ts-jest": "24.2.0",
|
||||
"ts-loader": "6.2.1",
|
||||
"ts-node": "^8.5.4",
|
||||
"tslint": "^5.20.1",
|
||||
"tslint-react": "^4.1.0",
|
||||
"typescript": "^3.7.3",
|
||||
"ts-node": "^8.6.2",
|
||||
"typescript": "^3.8.3",
|
||||
"unfetch": "^4.1.0",
|
||||
"url-polyfill": "^1.1.7",
|
||||
"webpack": "^4.41.2",
|
||||
"webpack-cli": "^3.3.10",
|
||||
"webpack-dev-server": "^3.9.0",
|
||||
"url-polyfill": "^1.1.8",
|
||||
"webpack": "^4.42.0",
|
||||
"webpack-cli": "^3.3.11",
|
||||
"webpack-dev-server": "^3.10.3",
|
||||
"webpack-node-externals": "^1.6.0",
|
||||
"workerize-loader": "^1.1.0",
|
||||
"yaml-js": "^0.2.3"
|
||||
|
@ -135,7 +137,7 @@
|
|||
"dependencies": {
|
||||
"classnames": "^2.2.6",
|
||||
"decko": "^1.2.0",
|
||||
"dompurify": "^2.0.7",
|
||||
"dompurify": "^2.0.8",
|
||||
"eventemitter3": "^4.0.0",
|
||||
"json-pointer": "^0.6.0",
|
||||
"json-schema-ref-parser": "^6.1.0",
|
||||
|
@ -143,18 +145,18 @@
|
|||
"mark.js": "^8.11.1",
|
||||
"marked": "^0.7.0",
|
||||
"memoize-one": "~5.1.1",
|
||||
"mobx-react": "^6.1.4",
|
||||
"mobx-react": "6.1.5",
|
||||
"openapi-sampler": "1.0.0-beta.15",
|
||||
"perfect-scrollbar": "^1.4.0",
|
||||
"polished": "^3.4.2",
|
||||
"prismjs": "^1.17.1",
|
||||
"polished": "^3.4.4",
|
||||
"prismjs": "^1.19.0",
|
||||
"prop-types": "^15.7.2",
|
||||
"react-dropdown": "^1.6.4",
|
||||
"react-tabs": "^3.0.0",
|
||||
"slugify": "^1.3.6",
|
||||
"react-dropdown": "^1.7.0",
|
||||
"react-tabs": "^3.1.0",
|
||||
"slugify": "^1.4.0",
|
||||
"stickyfill": "^1.1.1",
|
||||
"swagger2openapi": "^5.3.1",
|
||||
"tslib": "^1.10.0",
|
||||
"swagger2openapi": "^5.3.4",
|
||||
"tslib": "^1.11.1",
|
||||
"url-template": "^2.0.8"
|
||||
},
|
||||
"bundlesize": [
|
||||
|
|
|
@ -100,7 +100,7 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
|
|||
)) ||
|
||||
null}
|
||||
</StyledMarkdownBlock>
|
||||
<Markdown source={store.spec.info.description} />
|
||||
<Markdown source={store.spec.info.description} data-role="redoc-description" />
|
||||
{externalDocs && <ExternalDocumentation externalDocs={externalDocs} />}
|
||||
</MiddlePanel>
|
||||
</Row>
|
||||
|
|
|
@ -23,6 +23,7 @@ export interface FieldProps extends SchemaOptions {
|
|||
showExamples?: boolean;
|
||||
|
||||
field: FieldModel;
|
||||
expandByDefault?: boolean;
|
||||
|
||||
renderDiscriminatorSwitch?: (opts: FieldProps) => JSX.Element;
|
||||
}
|
||||
|
@ -30,13 +31,19 @@ export interface FieldProps extends SchemaOptions {
|
|||
@observer
|
||||
export class Field extends React.Component<FieldProps> {
|
||||
toggle = () => {
|
||||
if (this.props.field.expanded === undefined && this.props.expandByDefault) {
|
||||
this.props.field.expanded = false;
|
||||
} else {
|
||||
this.props.field.toggle();
|
||||
}
|
||||
};
|
||||
render() {
|
||||
const { className, field, isLast } = this.props;
|
||||
const { name, expanded, deprecated, required, kind } = field;
|
||||
const { className, field, isLast, expandByDefault } = this.props;
|
||||
const { name, deprecated, required, kind } = field;
|
||||
const withSubSchema = !field.schema.isPrimitive && !field.schema.isCircular;
|
||||
|
||||
const expanded = field.expanded === undefined ? expandByDefault : field.expanded;
|
||||
|
||||
const paramName = withSubSchema ? (
|
||||
<ClickablePropertyNameCell
|
||||
onClick={this.toggle}
|
||||
|
@ -65,7 +72,7 @@ export class Field extends React.Component<FieldProps> {
|
|||
<FieldDetails {...this.props} />
|
||||
</PropertyDetailsCell>
|
||||
</tr>
|
||||
{field.expanded && withSubSchema && (
|
||||
{expanded && withSubSchema && (
|
||||
<tr key={field.name + 'inner'}>
|
||||
<PropertyCellWithInner colSpan={2}>
|
||||
<InnerPropertiesWrap>
|
||||
|
|
|
@ -17,11 +17,12 @@ export type MarkdownProps = BaseMarkdownProps &
|
|||
StylingMarkdownProps & {
|
||||
source: string;
|
||||
className?: string;
|
||||
'data-role'?: string;
|
||||
};
|
||||
|
||||
export class Markdown extends React.Component<MarkdownProps> {
|
||||
render() {
|
||||
const { source, inline, compact, className } = this.props;
|
||||
const { source, inline, compact, className, 'data-role': dataRole } = this.props;
|
||||
const renderer = new MarkdownRenderer();
|
||||
return (
|
||||
<SanitizedMarkdownHTML
|
||||
|
@ -29,6 +30,7 @@ export class Markdown extends React.Component<MarkdownProps> {
|
|||
inline={inline}
|
||||
compact={compact}
|
||||
className={className}
|
||||
data-role={dataRole}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ const StyledMarkdownSpan = StyledMarkdownBlock.withComponent('span');
|
|||
const sanitize = (untrustedSpec, html) => (untrustedSpec ? DOMPurify.sanitize(html) : html);
|
||||
|
||||
export function SanitizedMarkdownHTML(
|
||||
props: StylingMarkdownProps & { html: string; className?: string },
|
||||
props: StylingMarkdownProps & { html: string; className?: string; 'data-role'?: string },
|
||||
) {
|
||||
const Wrap = props.inline ? StyledMarkdownSpan : StyledMarkdownBlock;
|
||||
|
||||
|
@ -22,6 +22,7 @@ export function SanitizedMarkdownHTML(
|
|||
dangerouslySetInnerHTML={{
|
||||
__html: sanitize(options.untrustedSpec, props.html),
|
||||
}}
|
||||
data-role={props['data-role']}
|
||||
{...props}
|
||||
/>
|
||||
)}
|
||||
|
|
|
@ -19,11 +19,13 @@ export const linksCss = css`
|
|||
}
|
||||
`;
|
||||
|
||||
export const StyledMarkdownBlock = styled(PrismDiv as StyledComponent<
|
||||
export const StyledMarkdownBlock = styled(
|
||||
PrismDiv as StyledComponent<
|
||||
'div',
|
||||
ResolvedThemeInterface,
|
||||
{ compact?: boolean; inline?: boolean }
|
||||
>)`
|
||||
>,
|
||||
)`
|
||||
|
||||
font-family: ${props => props.theme.typography.fontFamily};
|
||||
font-weight: ${props => props.theme.typography.fontWeightRegular};
|
||||
|
|
|
@ -29,7 +29,12 @@ export function ExternalExample({ example, mimeType }: ExampleProps) {
|
|||
return (
|
||||
<StyledPre>
|
||||
Error loading external example: <br />
|
||||
<a className={'token string'} href={example.externalValueUrl} target="_blank">
|
||||
<a
|
||||
className={'token string'}
|
||||
href={example.externalValueUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{example.externalValueUrl}
|
||||
</a>
|
||||
</StyledPre>
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// @ts-ignore
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import ReactDropdown from 'react-dropdown';
|
||||
|
||||
import { observer } from 'mobx-react';
|
||||
import * as React from 'react';
|
||||
import { MediaTypeSamples } from './MediaTypeSamples';
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// @ts-ignore
|
||||
import Dropdown from 'react-dropdown';
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import ReactDropdown from 'react-dropdown';
|
||||
|
||||
import { transparentize } from 'polished';
|
||||
import styled from '../../styled-components';
|
||||
|
|
|
@ -9,6 +9,7 @@ import { DiscriminatorDropdown } from './DiscriminatorDropdown';
|
|||
import { SchemaProps } from './Schema';
|
||||
|
||||
import { mapWithLast } from '../../utils';
|
||||
import { OptionsContext } from '../OptionsProvider';
|
||||
|
||||
export interface ObjectSchemaProps extends SchemaProps {
|
||||
discriminator?: {
|
||||
|
@ -19,6 +20,8 @@ export interface ObjectSchemaProps extends SchemaProps {
|
|||
|
||||
@observer
|
||||
export class ObjectSchema extends React.Component<ObjectSchemaProps> {
|
||||
static contextType = OptionsContext;
|
||||
|
||||
get parentSchema() {
|
||||
return this.props.discriminator!.parentSchema;
|
||||
}
|
||||
|
@ -41,6 +44,8 @@ export class ObjectSchema extends React.Component<ObjectSchemaProps> {
|
|||
})
|
||||
: fields;
|
||||
|
||||
const expandByDefault = this.context.expandSingleSchemaField && filteredFields.length === 1;
|
||||
|
||||
return (
|
||||
<PropertiesTable>
|
||||
{showTitle && <PropertiesTableCaption>{this.props.schema.title}</PropertiesTableCaption>}
|
||||
|
@ -51,6 +56,7 @@ export class ObjectSchema extends React.Component<ObjectSchemaProps> {
|
|||
key={field.name}
|
||||
isLast={isLast}
|
||||
field={field}
|
||||
expandByDefault={expandByDefault}
|
||||
renderDiscriminatorSwitch={
|
||||
(discriminator &&
|
||||
discriminator.fieldName === field.name &&
|
||||
|
|
|
@ -7,6 +7,7 @@ import { MenuItem } from '../SideMenu/MenuItem';
|
|||
import { MarkerService } from '../../services/MarkerService';
|
||||
import { SearchResult } from '../../services/SearchWorker.worker';
|
||||
|
||||
import { bind, debounce } from 'decko';
|
||||
import { PerfectScrollbarWrap } from '../../common-elements/perfect-scrollbar';
|
||||
import {
|
||||
ClearIcon,
|
||||
|
@ -94,11 +95,18 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
|
|||
setResults(results: SearchResult[], term: string) {
|
||||
this.setState({
|
||||
results,
|
||||
term,
|
||||
});
|
||||
this.props.marker.mark(term);
|
||||
}
|
||||
|
||||
@bind
|
||||
@debounce(400)
|
||||
searchCallback(searchTerm: string) {
|
||||
this.props.search.search(searchTerm).then(res => {
|
||||
this.setResults(res, searchTerm);
|
||||
});
|
||||
}
|
||||
|
||||
search = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const q = event.target.value;
|
||||
if (q.length < 3) {
|
||||
|
@ -106,13 +114,12 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
|
|||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
this.setState(
|
||||
{
|
||||
term: q,
|
||||
});
|
||||
|
||||
this.props.search.search(event.target.value).then(res => {
|
||||
this.setResults(res, q);
|
||||
});
|
||||
},
|
||||
() => this.searchCallback(this.state.term),
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
@ -97,7 +97,7 @@ export class SecurityDefs extends React.PureComponent<SecurityDefsProps> {
|
|||
scheme.http.scheme === 'bearer' && scheme.http.bearerFormat && (
|
||||
<tr key="bearer">
|
||||
<th> Bearer format </th>
|
||||
<td> "{scheme.http.bearerFormat}" </td>
|
||||
<td> "{scheme.http.bearerFormat}" </td>
|
||||
</tr>
|
||||
),
|
||||
]
|
||||
|
@ -105,7 +105,11 @@ export class SecurityDefs extends React.PureComponent<SecurityDefsProps> {
|
|||
<tr>
|
||||
<th> Connect URL </th>
|
||||
<td>
|
||||
<a target="_blank" href={scheme.openId.connectUrl}>
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href={scheme.openId.connectUrl}
|
||||
>
|
||||
{scheme.openId.connectUrl}
|
||||
</a>
|
||||
</td>
|
||||
|
|
|
@ -25,7 +25,7 @@ export class SideMenu extends React.Component<{ menu: MenuStore; className?: str
|
|||
>
|
||||
<MenuItems items={store.items} onActivate={this.activate} root={true} />
|
||||
<RedocAttribution>
|
||||
<a target="_blank" href="https://github.com/Redocly/redoc">
|
||||
<a target="_blank" rel="noopener noreferrer" href="https://github.com/Redocly/redoc">
|
||||
Documentation Powered by ReDoc
|
||||
</a>
|
||||
</RedocAttribution>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable import/no-internal-modules */
|
||||
/* tslint:disable:no-implicit-dependencies */
|
||||
|
||||
import { shallow } from 'enzyme';
|
||||
|
|
|
@ -9,7 +9,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat
|
|||
"deprecated": false,
|
||||
"description": "",
|
||||
"example": undefined,
|
||||
"expanded": false,
|
||||
"expanded": undefined,
|
||||
"explode": false,
|
||||
"in": undefined,
|
||||
"kind": "field",
|
||||
|
@ -59,7 +59,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat
|
|||
"deprecated": false,
|
||||
"description": "",
|
||||
"example": undefined,
|
||||
"expanded": false,
|
||||
"expanded": undefined,
|
||||
"explode": false,
|
||||
"in": undefined,
|
||||
"kind": "field",
|
||||
|
|
|
@ -18,6 +18,8 @@ import {
|
|||
SECURITY_DEFINITIONS_JSX_NAME,
|
||||
} from '../utils/openapi';
|
||||
|
||||
import { IS_BROWSER } from '../utils';
|
||||
|
||||
export interface StoreState {
|
||||
menu: {
|
||||
activeItemIdx: number;
|
||||
|
@ -134,16 +136,16 @@ export class AppStore {
|
|||
|
||||
const elements: Element[] = [];
|
||||
for (let i = start; i < end; i++) {
|
||||
let elem = this.menu.getElementAt(i);
|
||||
const elem = this.menu.getElementAt(i);
|
||||
if (!elem) {
|
||||
continue;
|
||||
}
|
||||
if (this.menu.flatItems[i].type === 'section') {
|
||||
elem = elem.parentElement!.parentElement;
|
||||
}
|
||||
if (elem) {
|
||||
elements.push(elem);
|
||||
}
|
||||
|
||||
if (idx === -1 && IS_BROWSER) {
|
||||
const $description = document.querySelector('[data-role="redoc-description"]');
|
||||
if ($description) elements.push($description);
|
||||
}
|
||||
|
||||
this.marker.addOnly(elements);
|
||||
|
|
|
@ -148,7 +148,7 @@ export class OpenAPIParser {
|
|||
* @param obj object to dereference
|
||||
* @param forceCircular whether to dereference even if it is circular ref
|
||||
*/
|
||||
deref<T extends object>(obj: OpenAPIRef | T, forceCircular: boolean = false): T {
|
||||
deref<T extends object>(obj: OpenAPIRef | T, forceCircular = false): T {
|
||||
if (this.isRef(obj)) {
|
||||
const resolved = this.byRef<T>(obj.$ref)!;
|
||||
const visited = this._refCounter.visited(obj.$ref);
|
||||
|
|
|
@ -26,6 +26,7 @@ export interface RedocRawOptions {
|
|||
jsonSampleExpandLevel?: number | string | 'all';
|
||||
hideSchemaTitles?: boolean | string;
|
||||
payloadSampleIdx?: number;
|
||||
expandSingleSchemaField?: boolean | string;
|
||||
|
||||
unstable_ignoreMimeParameters?: boolean;
|
||||
|
||||
|
@ -160,6 +161,7 @@ export class RedocNormalizedOptions {
|
|||
enumSkipQuotes: boolean;
|
||||
hideSchemaTitles: boolean;
|
||||
payloadSampleIdx: number;
|
||||
expandSingleSchemaField: boolean;
|
||||
|
||||
/* tslint:disable-next-line */
|
||||
unstable_ignoreMimeParameters: boolean;
|
||||
|
@ -200,7 +202,9 @@ export class RedocNormalizedOptions {
|
|||
this.enumSkipQuotes = argValueToBoolean(raw.enumSkipQuotes);
|
||||
this.hideSchemaTitles = argValueToBoolean(raw.hideSchemaTitles);
|
||||
this.payloadSampleIdx = RedocNormalizedOptions.normalizePayloadSampleIdx(raw.payloadSampleIdx);
|
||||
this.expandSingleSchemaField = argValueToBoolean(raw.expandSingleSchemaField);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
||||
this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);
|
||||
|
||||
this.allowedMdComponents = raw.allowedMdComponents || {};
|
||||
|
|
|
@ -9,7 +9,7 @@ const EVENT = 'scroll';
|
|||
export class ScrollService {
|
||||
private _scrollParent: Window | HTMLElement | undefined;
|
||||
private _emiter: EventEmitter;
|
||||
private _prevOffsetY: number = 0;
|
||||
private _prevOffsetY = 0;
|
||||
constructor(private options: RedocNormalizedOptions) {
|
||||
this._scrollParent = IS_BROWSER ? window : undefined;
|
||||
this._emiter = new EventEmitter();
|
||||
|
|
|
@ -4,21 +4,23 @@ import { OperationModel } from './models';
|
|||
|
||||
import Worker from './SearchWorker.worker';
|
||||
|
||||
let worker: new () => Worker;
|
||||
|
||||
if (IS_BROWSER) {
|
||||
function getWorker() {
|
||||
let worker: new () => Worker;
|
||||
if (IS_BROWSER) {
|
||||
try {
|
||||
// tslint:disable-next-line
|
||||
worker = require('workerize-loader?inline&fallback=false!./SearchWorker.worker');
|
||||
} catch (e) {
|
||||
worker = require('./SearchWorker.worker').default;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
worker = require('./SearchWorker.worker').default;
|
||||
}
|
||||
return new worker();
|
||||
}
|
||||
|
||||
export class SearchStore<T> {
|
||||
searchWorker = new worker();
|
||||
searchWorker = getWorker();
|
||||
|
||||
indexItems(groups: Array<IMenuItem | OperationModel>) {
|
||||
const recurse = items => {
|
||||
|
|
|
@ -8,6 +8,7 @@ describe('Models', () => {
|
|||
let parser;
|
||||
|
||||
test('should hoist oneOfs when mergin allOf', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const spec = require('./fixtures/oneOfHoist.json');
|
||||
parser = new OpenAPIParser(spec, undefined, opts);
|
||||
expect(parser.mergeAllOf(spec.components.schemas.test)).toMatchSnapshot();
|
||||
|
|
|
@ -6,9 +6,9 @@ const opts = new RedocNormalizedOptions({});
|
|||
|
||||
describe('Models', () => {
|
||||
describe('FieldModel', () => {
|
||||
let parser;
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const spec = require('../fixtures/fields.json');
|
||||
parser = new OpenAPIParser(spec, undefined, opts);
|
||||
const parser = new OpenAPIParser(spec, undefined, opts);
|
||||
|
||||
test('basic field details', () => {
|
||||
const field = new FieldModel(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
import { SchemaModel } from '../../models/Schema';
|
||||
import { OpenAPIParser } from '../../OpenAPIParser';
|
||||
import { RedocNormalizedOptions } from '../../RedocNormalizedOptions';
|
||||
|
|
|
@ -30,7 +30,7 @@ function getDefaultStyleValue(parameterLocation: OpenAPIParameterLocation): Open
|
|||
*/
|
||||
export class FieldModel {
|
||||
@observable
|
||||
expanded: boolean = false;
|
||||
expanded: boolean | undefined;
|
||||
|
||||
schema: SchemaModel;
|
||||
name: string;
|
||||
|
|
5
src/types/components.d.ts
vendored
5
src/types/components.d.ts
vendored
|
@ -1,5 +0,0 @@
|
|||
import { AppStore } from '../services/AppStore';
|
||||
|
||||
export interface BaseContainerProps {
|
||||
store: AppStore;
|
||||
}
|
|
@ -8,7 +8,11 @@ describe('Utils', () => {
|
|||
const fn = (...args) => args;
|
||||
|
||||
const actual = mapWithLast(arr, fn);
|
||||
const expected = [[1, false], [2, false], [3, true]];
|
||||
const expected = [
|
||||
[1, false],
|
||||
[2, false],
|
||||
[3, true],
|
||||
];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
|
|
|
@ -640,7 +640,7 @@ describe('Utils', () => {
|
|||
|
||||
describe('OpenAPI sortByRequired', () => {
|
||||
it('should equal to the old data when all items have no required props', () => {
|
||||
let fields = [
|
||||
const fields = [
|
||||
{
|
||||
name: 'loginName',
|
||||
required: false,
|
||||
|
@ -694,7 +694,7 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('other item should be the same order when some of items are required', () => {
|
||||
let fields = [
|
||||
const fields = [
|
||||
{
|
||||
name: 'loginName',
|
||||
required: true,
|
||||
|
@ -744,7 +744,7 @@ describe('Utils', () => {
|
|||
required: false,
|
||||
},
|
||||
];
|
||||
let sortedFields = [
|
||||
const sortedFields = [
|
||||
{
|
||||
name: 'loginName',
|
||||
required: true,
|
||||
|
@ -798,7 +798,7 @@ describe('Utils', () => {
|
|||
});
|
||||
|
||||
it('should the order of required items is as same as the order parameter ', () => {
|
||||
let fields = [
|
||||
const fields = [
|
||||
{
|
||||
name: 'loginName',
|
||||
required: true,
|
||||
|
|
|
@ -16,6 +16,7 @@ function throttle(func, wait) {
|
|||
const now = new Date().getTime();
|
||||
const remaining = wait - (now - previous);
|
||||
context = this;
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
args = arguments;
|
||||
if (remaining <= 0 || remaining > wait) {
|
||||
if (timeout) {
|
||||
|
|
|
@ -189,7 +189,7 @@ export function removeQueryString(serverUrl: string): string {
|
|||
function parseURL(url: string) {
|
||||
if (typeof URL === 'undefined') {
|
||||
// node
|
||||
return new (require('url')).URL(url);
|
||||
return new (require('url').URL)(url);
|
||||
} else {
|
||||
return new URL(url);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { dirname } from 'path';
|
||||
const URLtemplate = require('url-template');
|
||||
import * as URLtemplate from 'url-template';
|
||||
|
||||
import { FieldModel } from '../services/models';
|
||||
import { OpenAPIParser } from '../services/OpenAPIParser';
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
"./custom.d.ts",
|
||||
"./demo/playground/hmr-playground.tsx",
|
||||
"./src/**/*.ts?",
|
||||
"demo/*.tsx"
|
||||
"demo/*.tsx",
|
||||
"src/empty.js"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"extends": ["tslint:latest", "tslint-react"],
|
||||
"rules": {
|
||||
"array-type": false,
|
||||
"interface-name": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"jsx-no-multiline-js": false,
|
||||
|
|
Loading…
Reference in New Issue
Block a user