Skip to content

Commit

Permalink
Merge pull request #3 from jmendiara/chore/lastUpdates
Browse files Browse the repository at this point in the history
chore: Update upstream
  • Loading branch information
jmendiara authored Sep 30, 2019
2 parents cf73cfd + 7fc1a69 commit fc392aa
Show file tree
Hide file tree
Showing 11 changed files with 1,380 additions and 1,219 deletions.
33 changes: 23 additions & 10 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ YargsParser.command(
yargs.demandOption('spec');
return yargs;
},
async argv => {
const config: Options = {
async (argv: any) => {
const config = {
ssr: true,
output: argv.o as string,
cdn: argv.cdn as boolean,
Expand Down Expand Up @@ -188,21 +188,34 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
if (options.watch && existsSync(pathToSpec)) {
const pathToSpecDirectory = resolve(dirname(pathToSpec));
const watchOptions = {
ignored: /(^|[\/\\])\../,
ignored: [/(^|[\/\\])\../, /___jb_[a-z]+___$/],
ignoreInitial: true,
};

const watcher = watch(pathToSpecDirectory, watchOptions);
const log = console.log.bind(console);

const handlePath = async path => {
try {
spec = await loadAndBundleSpec(pathToSpec);
pageHTML = await getPageHTML(spec, pathToSpec, options);
log('Updated successfully');
} catch (e) {
console.error('Error while updating: ', e.message);
}
};

watcher
.on('change', async path => {
log(`${path} changed, updating docs`);
try {
spec = await loadAndBundleSpec(pathToSpec);
pageHTML = await getPageHTML(spec, pathToSpec, options);
log('Updated successfully');
} catch (e) {
console.error('Error while updating: ', e.message);
}
handlePath(path);
})
.on('add', async path => {
log(`File ${path} added, updating docs`);
handlePath(path);
})
.on('addDir', path => {
log(`↗ Directory ${path} added. Files in here will trigger reload.`);
})
.on('error', error => console.error(`Watcher error: ${error}`))
.on('ready', () => log(`👀 Watching ${pathToSpecDirectory} for changes...`));
Expand Down
78 changes: 39 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,77 +52,77 @@
"docker:build": "docker build -f config/docker/Dockerfile -t redoc ."
},
"devDependencies": {
"@babel/core": "7.5.5",
"@babel/core": "7.6.2",
"@babel/plugin-syntax-decorators": "7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-jsx": "7.2.0",
"@babel/plugin-syntax-typescript": "7.3.3",
"@cypress/webpack-preprocessor": "4.1.0",
"@hot-loader/react-dom": "^16.8.6",
"@types/chai": "4.1.7",
"@hot-loader/react-dom": "^16.9.0",
"@types/chai": "4.2.3",
"@types/dompurify": "^0.0.33",
"@types/enzyme": "^3.10.3",
"@types/enzyme-to-json": "^1.5.3",
"@types/jest": "^24.0.15",
"@types/jest": "^24.0.18",
"@types/json-pointer": "^1.0.30",
"@types/lodash": "^4.14.136",
"@types/lodash": "^4.14.141",
"@types/lunr": "^2.3.2",
"@types/mark.js": "^8.11.4",
"@types/marked": "^0.6.5",
"@types/prismjs": "^1.16.0",
"@types/prop-types": "^15.7.1",
"@types/react": "^16.8.23",
"@types/react-dom": "^16.8.5",
"@types/prop-types": "^15.7.3",
"@types/react": "^16.9.3",
"@types/react-dom": "^16.9.1",
"@types/react-hot-loader": "^4.1.0",
"@types/react-tabs": "^2.3.1",
"@types/styled-components": "^4.1.18",
"@types/styled-components": "^4.1.19",
"@types/tapable": "1.0.4",
"@types/webpack": "^4.32.1",
"@types/webpack": "^4.39.2",
"@types/webpack-env": "^1.14.0",
"@types/yargs": "^13.0.0",
"@types/yargs": "^13.0.3",
"babel-loader": "8.0.6",
"babel-plugin-styled-components": "^1.10.6",
"beautify-benchmark": "^0.2.4",
"bundlesize": "^0.18.0",
"conventional-changelog-cli": "^2.0.23",
"copy-webpack-plugin": "^5.0.4",
"core-js": "^3.1.4",
"coveralls": "^3.0.5",
"css-loader": "^3.1.0",
"cypress": "~3.4.0",
"core-js": "^3.2.1",
"coveralls": "^3.0.6",
"css-loader": "^3.2.0",
"cypress": "~3.4.1",
"deploy-to-gh-pages": "^1.3.7",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"enzyme-to-json": "^3.3.5",
"fork-ts-checker-webpack-plugin": "1.4.3",
"enzyme-to-json": "^3.4.0",
"fork-ts-checker-webpack-plugin": "1.5.0",
"html-webpack-plugin": "^3.1.0",
"jest": "^24.8.0",
"jest": "^24.9.0",
"license-checker": "^25.0.1",
"lodash": "^4.17.15",
"mobx": "^4.3.1",
"prettier": "^1.18.2",
"prettier-eslint": "^9.0.0",
"raf": "^3.4.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"rimraf": "^2.6.3",
"react": "^16.10.1",
"react-dom": "^16.10.1",
"rimraf": "^3.0.0",
"shelljs": "^0.8.3",
"source-map-loader": "^0.2.4",
"style-loader": "^0.23.1",
"styled-components": "^4.3.2",
"ts-jest": "24.0.2",
"ts-loader": "6.0.4",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"tslint-react": "^4.0.0",
"typescript": "^3.5.3",
"style-loader": "^1.0.0",
"styled-components": "^4.4.0",
"ts-jest": "24.1.0",
"ts-loader": "6.2.0",
"ts-node": "^8.4.1",
"tslint": "^5.20.0",
"tslint-react": "^4.1.0",
"typescript": "^3.6.3",
"unfetch": "^4.1.0",
"url-polyfill": "^1.1.7",
"webpack": "^4.38.0",
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.7.2",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.1",
"webpack-node-externals": "^1.6.0",
"workerize-loader": "^1.0.4",
"workerize-loader": "^1.1.0",
"yaml-js": "^0.2.3"
},
"peerDependencies": {
Expand All @@ -135,28 +135,28 @@
"dependencies": {
"classnames": "^2.2.6",
"decko": "^1.2.0",
"dompurify": "^1.0.11",
"dompurify": "^2.0.3",
"eventemitter3": "^4.0.0",
"json-pointer": "^0.6.0",
"json-schema-ref-parser": "^6.1.0",
"lunr": "2.3.6",
"mark.js": "^8.11.1",
"marked": "^0.7.0",
"memoize-one": "^5.0.5",
"mobx-react": "^6.1.1",
"memoize-one": "~5.0.5",
"mobx-react": "^6.1.3",
"openapi-sampler": "1.0.0-beta.15",
"perfect-scrollbar": "^1.4.0",
"polished": "^3.4.1",
"prismjs": "^1.17.1",
"prop-types": "^15.7.2",
"react-dropdown": "^1.6.4",
"react-hot-loader": "^4.12.10",
"react-hot-loader": "^4.12.14",
"react-tabs": "^3.0.0",
"slugify": "^1.3.4",
"slugify": "^1.3.5",
"stickyfill": "^1.1.1",
"swagger2openapi": "^5.3.1",
"tslib": "^1.10.0",
"uri-template-lite": "^19.4.0"
"url-template": "^2.0.8"
},
"bundlesize": [
{
Expand Down
11 changes: 7 additions & 4 deletions src/components/Endpoint/Endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Markdown } from '../Markdown/Markdown';
import { OptionsContext } from '../OptionsProvider';
import { SelectOnClick } from '../SelectOnClick/SelectOnClick';

import { getBasePath } from '../../utils';
import { expandDefaultServerVariables, getBasePath } from '../../utils';
import {
EndpointInfo,
HttpVerb,
Expand Down Expand Up @@ -61,15 +61,18 @@ export class Endpoint extends React.Component<EndpointProps, EndpointState> {
</EndpointInfo>
<ServersOverlay expanded={expanded}>
{operation.servers.map(server => {
const normalizedUrl = options.expandDefaultServerVariables
? expandDefaultServerVariables(server.url, server.variables)
: server.url;
return (
<ServerItem key={server.url}>
<ServerItem key={normalizedUrl}>
<Markdown source={server.description || ''} compact={true} />
<SelectOnClick>
<ServerUrl>
<span>
{hideHostname || options.hideHostname
? getBasePath(server.url)
: server.url}
? getBasePath(normalizedUrl)
: normalizedUrl}
</span>
{operation.path}
</ServerUrl>
Expand Down
8 changes: 3 additions & 5 deletions src/components/Schema/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
if (discriminatorProp !== undefined) {
if (!oneOf || !oneOf.length) {
throw new Error(
`Looks like you are using discriminator wrong: you don't have any definition inherited from the ${
schema.title
}`,
`Looks like you are using discriminator wrong: you don't have any definition inherited from the ${schema.title}`,
);
}
return (
Expand All @@ -66,9 +64,9 @@ export class Schema extends React.Component<Partial<SchemaProps>> {

switch (type) {
case 'object':
return <ObjectSchema {...this.props as any} />;
return <ObjectSchema {...(this.props as any)} />;
case 'array':
return <ArraySchema {...this.props as any} />;
return <ArraySchema {...(this.props as any)} />;
}

// TODO: maybe adjust FieldDetails to accept schema
Expand Down
72 changes: 39 additions & 33 deletions src/components/StickySidebar/StickyResponsiveSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface StickySidebarProps {
menu: MenuStore;
}

export interface StickySidebarState {
offsetTop?: string;
}

const stickyfill = Stickyfill && Stickyfill();

const StyledStickySidebar = styled.div<{ open?: boolean }>`
Expand Down Expand Up @@ -77,13 +81,26 @@ const FloatingButton = styled.div`
`;

@observer
export class StickyResponsiveSidebar extends React.Component<StickySidebarProps> {
export class StickyResponsiveSidebar extends React.Component<
StickySidebarProps,
StickySidebarState
> {
static contextType = OptionsContext;
context!: React.ContextType<typeof OptionsContext>;
state: StickySidebarState = {};

stickyElement: Element;

componentDidMount() {
if (stickyfill) {
stickyfill.add(this.stickyElement);
}

// rerender when hydrating from SSR
// see https://github.com/facebook/react/issues/8017#issuecomment-256351955
this.setState({
offsetTop: this.getScrollYOffset(this.context),
});
}

componentWillUnmount() {
Expand All @@ -92,7 +109,7 @@ export class StickyResponsiveSidebar extends React.Component<StickySidebarProps>
}
}

getScrollYOffset(options) {
getScrollYOffset(options: RedocNormalizedOptions) {
let top;
if (this.props.scrollYOffset !== undefined) {
top = RedocNormalizedOptions.normalizeScrollYOffset(this.props.scrollYOffset)();
Expand All @@ -105,43 +122,32 @@ export class StickyResponsiveSidebar extends React.Component<StickySidebarProps>
render() {
const open = this.props.menu.sideBarOpened;

const style = options => {
const top = this.getScrollYOffset(options);
return {
top,
height: `calc(100vh - ${top})`,
};
};
const top = this.state.offsetTop || this.getScrollYOffset(this.context);

return (
<OptionsContext.Consumer>
{options => (
<>
<StyledStickySidebar
open={open}
className={this.props.className}
style={style(options)}
// tslint:disable-next-line
ref={el => {
this.stickyElement = el as any;
}}
>
{this.props.children}
</StyledStickySidebar>
<FloatingButton onClick={this.toggleNavMenu}>
<AnimatedChevronButton open={open} />
</FloatingButton>
</>
)}
</OptionsContext.Consumer>
<>
<StyledStickySidebar
open={open}
className={this.props.className}
style={{
top,
height: `calc(100vh - ${top})`,
}}
// tslint:disable-next-line
ref={el => {
this.stickyElement = el as any;
}}
>
{this.props.children}
</StyledStickySidebar>
<FloatingButton onClick={this.toggleNavMenu}>
<AnimatedChevronButton open={open} />
</FloatingButton>
</>
);
}

private toggleNavMenu = () => {
this.props.menu.toggleSidebar();
};

// private closeNavMenu = () => {
// this.setState({ open: false });
// };
}
7 changes: 7 additions & 0 deletions src/services/RedocNormalizedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export interface RedocRawOptions {
allowedMdComponents?: Dict<MDXComponentMeta>;

labels?: LabelsConfigRaw;

enumSkipQuotes?: boolean | string;

expandDefaultServerVariables?: boolean;
}

function argValueToBoolean(val?: string | boolean): boolean {
Expand Down Expand Up @@ -149,6 +152,8 @@ export class RedocNormalizedOptions {
unstable_ignoreMimeParameters: boolean;
allowedMdComponents: Dict<MDXComponentMeta>;

expandDefaultServerVariables: boolean;

constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
raw = { ...defaults, ...raw };
const hook = raw.theme && raw.theme.extensionsHook;
Expand Down Expand Up @@ -184,6 +189,8 @@ export class RedocNormalizedOptions {
this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);

this.allowedMdComponents = raw.allowedMdComponents || {};

this.expandDefaultServerVariables = argValueToBoolean(raw.expandDefaultServerVariables);
this.extensionsComponents = raw.extensionsComponents || {};
}
}
Loading

0 comments on commit fc392aa

Please sign in to comment.