mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-09 20:57:44 +00:00
fix: do not add a config folder to api path (#1187)
This commit is contained in:
23
__tests__/build-docs/build-docs-with-config-option/index.hbs
Normal file
23
__tests__/build-docs/build-docs-with-config-option/index.hbs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf8" />
|
||||||
|
<title>{{title}}</title>
|
||||||
|
<!-- needed for adaptive design -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{{{redocHead}}}
|
||||||
|
{{#unless disableGoogleFont}}<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">{{/unless}}
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
{{{redocHTML}}}
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
openapi: 3.1.0
|
||||||
|
servers:
|
||||||
|
- url: http://localhost
|
||||||
|
info:
|
||||||
|
title: Sample API
|
||||||
|
version: 1.0.0
|
||||||
|
paths:
|
||||||
|
/hello:
|
||||||
|
get:
|
||||||
|
operationId: getMessage
|
||||||
|
security: []
|
||||||
|
summary: Get a greeting message
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: ./message-schema.yaml
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
extends:
|
||||||
|
- minimal
|
||||||
|
theme:
|
||||||
|
openapi:
|
||||||
|
htmlTemplate: ../index.hbs
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`E2E build-docs build docs with config option 1`] = `
|
||||||
|
|
||||||
|
🎉 bundled successfully in: nested/redoc-static.html (38 KiB) [⏱ <test>ms].
|
||||||
|
|
||||||
|
Found nested/redocly.yaml and using theme.openapi options
|
||||||
|
Prerendering docs
|
||||||
|
|
||||||
|
`;
|
||||||
1
__tests__/build-docs/simple-build-docs/pets.yaml
Symbolic link
1
__tests__/build-docs/simple-build-docs/pets.yaml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../resources/pets.yaml
|
||||||
10
__tests__/build-docs/simple-build-docs/snapshot.js
Normal file
10
__tests__/build-docs/simple-build-docs/snapshot.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`E2E build-docs simple build-docs 1`] = `
|
||||||
|
|
||||||
|
🎉 bundled successfully in: redoc-static.html (318 KiB) [⏱ <test>ms].
|
||||||
|
|
||||||
|
Found undefined and using theme.openapi options
|
||||||
|
Prerendering docs
|
||||||
|
|
||||||
|
`;
|
||||||
@@ -3,6 +3,7 @@ import { join, relative } from 'path';
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
import { toMatchSpecificSnapshot } from './specific-snapshot';
|
import { toMatchSpecificSnapshot } from './specific-snapshot';
|
||||||
import { getCommandOutput, getEntrypoints, callSerializer, getParams } from './helpers';
|
import { getCommandOutput, getEntrypoints, callSerializer, getParams } from './helpers';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
expect.extend({
|
expect.extend({
|
||||||
toMatchExtendedSpecificSnapshot(received, snapshotFile) {
|
toMatchExtendedSpecificSnapshot(received, snapshotFile) {
|
||||||
@@ -372,4 +373,31 @@ describe('E2E', () => {
|
|||||||
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
|
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('build-docs', () => {
|
||||||
|
const folderPath = join(__dirname, 'build-docs');
|
||||||
|
|
||||||
|
test('simple build-docs', () => {
|
||||||
|
const testPath = join(folderPath, 'simple-build-docs');
|
||||||
|
const args = getParams('../../../packages/cli/src/index.ts', 'build-docs', ['pets.yaml']);
|
||||||
|
const result = getCommandOutput(args, testPath);
|
||||||
|
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
|
||||||
|
|
||||||
|
expect(fs.existsSync(join(testPath, 'redoc-static.html'))).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('build docs with config option', () => {
|
||||||
|
const testPath = join(folderPath, 'build-docs-with-config-option');
|
||||||
|
const args = getParams('../../../packages/cli/src/index.ts', 'build-docs', [
|
||||||
|
'nested/openapi.yaml',
|
||||||
|
'--config=nested/redocly.yaml',
|
||||||
|
'-o=nested/redoc-static.html',
|
||||||
|
]);
|
||||||
|
const result = getCommandOutput(args, testPath);
|
||||||
|
(<any>expect(result)).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
|
||||||
|
|
||||||
|
expect(fs.existsSync(join(testPath, 'nested/redoc-static.html'))).toEqual(true);
|
||||||
|
expect(fs.statSync(join(testPath, 'nested/redoc-static.html')).size).toEqual(38839);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ type CLICommands =
|
|||||||
| 'preview-docs'
|
| 'preview-docs'
|
||||||
| 'push'
|
| 'push'
|
||||||
| 'split'
|
| 'split'
|
||||||
| 'stats';
|
| 'stats'
|
||||||
|
| 'build-docs';
|
||||||
|
|
||||||
export function getParams(
|
export function getParams(
|
||||||
indexEntryPoint: string,
|
indexEntryPoint: string,
|
||||||
|
|||||||
@@ -30,12 +30,13 @@ export const handlerBuildCommand = async (argv: BuildDocsArgv, configFromFile: C
|
|||||||
try {
|
try {
|
||||||
const elapsed = getExecutionTime(startedAt);
|
const elapsed = getExecutionTime(startedAt);
|
||||||
|
|
||||||
const api = await loadAndBundleSpec(
|
const api = await loadAndBundleSpec(isAbsoluteUrl(pathToApi) ? pathToApi : resolve(pathToApi));
|
||||||
isAbsoluteUrl(pathToApi)
|
const pageHTML = await getPageHTML(
|
||||||
? pathToApi
|
api,
|
||||||
: resolve(argv.config ? dirname(argv.config) : '', pathToApi)
|
pathToApi,
|
||||||
|
{ ...options, redocCurrentVersion },
|
||||||
|
argv.config
|
||||||
);
|
);
|
||||||
const pageHTML = await getPageHTML(api, pathToApi, { ...options, redocCurrentVersion });
|
|
||||||
|
|
||||||
mkdirSync(dirname(options.output), { recursive: true });
|
mkdirSync(dirname(options.output), { recursive: true });
|
||||||
writeFileSync(options.output, pageHTML);
|
writeFileSync(options.output, pageHTML);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Config, isAbsoluteUrl } from '@redocly/openapi-core';
|
|||||||
import { renderToString } from 'react-dom/server';
|
import { renderToString } from 'react-dom/server';
|
||||||
import { ServerStyleSheet } from 'styled-components';
|
import { ServerStyleSheet } from 'styled-components';
|
||||||
import { compile } from 'handlebars';
|
import { compile } from 'handlebars';
|
||||||
import { join } from 'path';
|
import { dirname, join, resolve } from 'path';
|
||||||
import { existsSync, lstatSync, readFileSync } from 'fs';
|
import { existsSync, lstatSync, readFileSync } from 'fs';
|
||||||
|
|
||||||
import type { BuildDocsOptions } from './types';
|
import type { BuildDocsOptions } from './types';
|
||||||
@@ -57,9 +57,10 @@ export async function getPageHTML(
|
|||||||
templateOptions,
|
templateOptions,
|
||||||
redocOptions = {},
|
redocOptions = {},
|
||||||
redocCurrentVersion,
|
redocCurrentVersion,
|
||||||
}: BuildDocsOptions
|
}: BuildDocsOptions,
|
||||||
|
configPath?: string
|
||||||
) {
|
) {
|
||||||
process.stderr.write('Prerendering docs');
|
process.stderr.write('Prerendering docs\n');
|
||||||
|
|
||||||
const apiUrl = redocOptions.specUrl || (isAbsoluteUrl(pathToApi) ? pathToApi : undefined);
|
const apiUrl = redocOptions.specUrl || (isAbsoluteUrl(pathToApi) ? pathToApi : undefined);
|
||||||
const store = await createStore(api, apiUrl, redocOptions);
|
const store = await createStore(api, apiUrl, redocOptions);
|
||||||
@@ -72,7 +73,7 @@ export async function getPageHTML(
|
|||||||
templateFileName = templateFileName
|
templateFileName = templateFileName
|
||||||
? templateFileName
|
? templateFileName
|
||||||
: redocOptions?.htmlTemplate
|
: redocOptions?.htmlTemplate
|
||||||
? (redocOptions.htmlTemplate as string)
|
? resolve(configPath ? dirname(configPath) : '', redocOptions.htmlTemplate)
|
||||||
: join(__dirname, './template.hbs');
|
: join(__dirname, './template.hbs');
|
||||||
const template = compile(readFileSync(templateFileName).toString());
|
const template = compile(readFileSync(templateFileName).toString());
|
||||||
return template({
|
return template({
|
||||||
|
|||||||
Reference in New Issue
Block a user