Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-parks-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-typescript": minor
---

Add --no-lint flag to skip Redocly styleguide linting
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ The following flags are supported in the CLI:
| `--make-paths-enum` | | `false` | Generate ApiPaths enum for all paths |
| `--generate-path-params` | | `false` | Generate path parameters for all paths where they are undefined by schema |
| `--read-write-markers` | | `false` | Generate `$Read<T>`/`$Write<T>` markers for readOnly/writeOnly properties |
| `--no-lint` | | `false` | Skip Redocly styleguide linting |

### pathParamsAsTypes

Expand Down
2 changes: 2 additions & 0 deletions packages/openapi-typescript/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Options
--root-types-keep-casing Keep casing of root types (should only be used with --root-types)
--make-paths-enum Generate ApiPaths enum for all paths
--read-write-markers Generate $Read/$Write markers for readOnly/writeOnly properties
--no-lint Generate the types without linting
`;

const OUTPUT_FILE = "FILE";
Expand Down Expand Up @@ -96,6 +97,7 @@ const BOOLEAN_FLAGS = [
"rootTypes",
"rootTypesKeepCasing",
"rootTypesNoSchemaPrefix",
"lint",
];

const flags = parser(args, {
Expand Down
1 change: 1 addition & 0 deletions packages/openapi-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default async function openapiTS(
redoc,
cwd: options.cwd instanceof URL ? options.cwd : new URL(`file://${options.cwd ?? process.cwd()}/`),
silent: options.silent ?? false,
lint: options.lint ?? true,
});

const ctx: GlobalContext = {
Expand Down
15 changes: 9 additions & 6 deletions packages/openapi-typescript/src/lib/redoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ValidateAndBundleOptions {
redoc: RedoclyConfig;
silent: boolean;
cwd?: URL;
lint?: boolean;
}

interface ParseSchemaOptions {
Expand Down Expand Up @@ -142,12 +143,14 @@ export async function validateAndBundle(

// 2. lint
const redocLintT = performance.now();
const problems = await lintDocument({
document,
config: options.redoc.styleguide,
externalRefResolver: resolver,
});
_processProblems(problems, options);
if (options.lint !== false) {
const problems = await lintDocument({
document,
config: options.redoc.styleguide,
externalRefResolver: resolver,
});
_processProblems(problems, options);
}
debug("Linted schema", "lint", performance.now() - redocLintT);

// 3. bundle
Expand Down
2 changes: 2 additions & 0 deletions packages/openapi-typescript/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ export type SecurityRequirementObject = {
};

export interface OpenAPITSOptions {
/** Run Redocly styleguide linting (default: true) */
lint?: boolean;
/** Treat all objects as if they have `additionalProperties: true` by default (default: false) */
additionalProperties?: boolean;
/** Alphabetize all keys? (default: false) */
Expand Down
10 changes: 10 additions & 0 deletions packages/openapi-typescript/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ describe("CLI", () => {
});

describe("Redocly config", () => {
test("--no-lint skips styleguide errors", async () => {
const fixtureDir = new URL("./fixtures/redocly-lint-error/", import.meta.url);
const outputFile = new URL("./output/openapi.ts", fixtureDir);
fs.rmSync(outputFile, { force: true });
await execa(cmd, ["--redocly", "test/fixtures/redocly-lint-error/redocly.yaml", "--no-lint"], {
cwd,
});
expect(fs.existsSync(outputFile)).toBe(true);
expect(fs.readFileSync(outputFile, "utf8")).toContain("export interface paths");
});
test.skipIf(os.platform() === "win32")("automatic config", async () => {
const cwd = new URL("./fixtures/redocly/", import.meta.url);

Expand Down
Loading