Skip to content
Merged
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
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,30 @@ whose query parameters need two of them stops generation.
## Linting generated output

The generated JSDoc is transcribed from the OpenAPI document, so the prose is
the document author's and the comment rules judge it unfairly. The package
ships an override for that, scoped to wherever the output lives:
the document author's and the comment rules judge it unfairly. Query parameter
names, schema nesting and the optionality of inputs are the document's contract
too.

```ts
import { defineConfig } from "@block65/shared-config/oxlint";
import * as codegen from "@block65/openapi-codegen/oxlint";
After writing, the generator runs your project's own oxlint over the output,
with your config. Each file gets a directive that turns off only the rules on
that exemption list which fired in it:

export default defineConfig({
overrides: [...codegen.defineOverrides("src/generated/*")],
});
```ts
// oxlint-disable block65/no-narrative-comment, block65/prefer-exact-optional
```

It turns off comment rules only. Anything else the generated output trips is a
bug in the generator, so report it rather than adding it to the override.
An object schema the document leaves open is never exempt: it stays a lint
error until the document sets `additionalProperties: false`. A header schema is
the exception, because a request carries headers the document does not name.
Where the rule fires on one, the generator brackets that declaration with a
disable and enable naming the reason.

No lint config is needed for generated code. Anything else the output trips is
a bug in the generator, so report it rather than turning the rule off.

Every run relints every file, so the directives follow your current lint
config. Without oxlint in the project, or with a config that fails to load,
the files get no directive.

## Object strictness comes from the document

Expand Down
17 changes: 0 additions & 17 deletions __tests__/codegen-regressions.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import path from "node:path";
import type { oas31 } from "openapi3-ts";
import { assert, expect, test } from "vitest";
import { generatedFiles } from "../lib/oxlint.ts";
import { processOpenApiDocument } from "../lib/process-document.ts";

const respOk = {
Expand Down Expand Up @@ -182,21 +180,6 @@ test("AllInputs union carries every command that takes an input", async () => {
expect(carried).toEqual([]);
});

// `generatedFiles` limits the shipped lint override, so an emitted module
// absent from that list would lint unscoped at every consumer
test("the shipped lint override names every file the generator emits", async () => {
const result = await processOpenApiDocument(
"/tmp/generated-file-set",
docWithSchema("Thing", { type: "object", properties: {} }),
);

const emitted = Object.values(result)
.map((file) => path.basename(file.getFilePath()))
.toSorted();

expect(emitted).toStrictEqual([...generatedFiles].toSorted());
});

// An empty schema permits any value, so the keys outside `properties` are
// unconstrained and the object is loose
test("additionalProperties chooses the object schema", async () => {
Expand Down
12 changes: 6 additions & 6 deletions __tests__/fixtures/docker/.openapi-codegen-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"#generator": "d9c25059b8f56e84cd41d51232262509",
"commands.ts": "20f63fd7ad412eb1f03ae5cfc4b81df9",
"types.ts": "72a44fac13cd4872db19c1a64b11a6ea",
"#generator": "25c3995293e37099b578d8abd616d258",
"commands.ts": "137aa1b06856ca44a0c780958480af81",
"types.ts": "6b85d6261f52a556a0dc6a584b3da2db",
"main.ts": "0f596fab7f6e9bb140fcd133caccb38d",
"valibot.ts": "822492c19be03028e145c1819bc12f83",
"hono.ts": "8cc50e47f0a5be0ec4b87f3229cb653e",
"valibot.ts": "2c62b6192664e3a42e1b44700d430df7",
"hono.ts": "4dee43760e6f999bf0da89d4c063bcd4",
"commands-validated.ts": "c6066f3a4ead3dadfad70443e923a265",
"enums.ts": "fc732c1471b27b2a8fa327ed82a0a6c6"
"enums.ts": "6d2420ab590db68349e2e8463a1b026d"
}
2 changes: 2 additions & 0 deletions __tests__/fixtures/docker/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/max-comment-lines, block65/no-comment-history, block65/no-comment-list, block65/no-comment-punctuation, block65/no-narrative-comment, block65/no-negated-comment, block65/no-padded-comment, block65/no-single-character-declaration, unicorn-unported/comment-content

import {
Command,
stripUndefined,
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/docker/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/no-comment-list, block65/no-comment-punctuation, block65/no-narrative-comment, block65/no-trailing-comment-punctuation

/**
* Kind of change
*
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/docker/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/declaration-comments, block65/no-comment-history, block65/no-narrative-comment, block65/no-trailing-comment-punctuation

import { PublicValidationError } from "@block65/rest-client";
import { sValidator } from "@hono/standard-validator";
import type { ValidationTargets } from "hono";
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/docker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/max-comment-lines, block65/no-absence-comment, block65/no-comment-history, block65/no-comment-list, block65/no-comment-overclaim, block65/no-comment-punctuation, block65/no-figurative-comment, block65/no-narrative-comment, block65/no-negated-comment, block65/no-padded-comment, block65/no-trailing-comment-punctuation, unicorn-unported/comment-content

import type { Jsonifiable, UndefinedOnPartialDeep } from "type-fest";

/** An open port on a container */
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/docker/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/max-comment-lines, block65/no-absence-comment, block65/no-assumption-comment, block65/no-banned-comment-words, block65/no-comment-history, block65/no-comment-list, block65/no-comment-overclaim, block65/no-comment-punctuation, block65/no-figurative-comment, block65/no-narrative-comment, block65/no-negated-comment, block65/no-padded-comment, block65/no-trailing-comment-punctuation, block65/prefer-exact-optional, unicorn-unported/comment-content

import * as v from "valibot";

/**
Expand Down
12 changes: 6 additions & 6 deletions __tests__/fixtures/openai/.openapi-codegen-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"#generator": "d9c25059b8f56e84cd41d51232262509",
"commands.ts": "7d2187eb106fc582735b22176033ea28",
"types.ts": "e2ca3f6a2e1e1a382f4d11f187b341df",
"#generator": "25c3995293e37099b578d8abd616d258",
"commands.ts": "82d7434078d4f7ba525c36db35c4c33b",
"types.ts": "605fb801d1203d2e523cbcb63cb8d0e6",
"main.ts": "5ba91c2efb44e3e5c5bd1e1a1b90bb51",
"valibot.ts": "1ce0f05f51117be27a3719d479c82790",
"hono.ts": "f5768dde31ada252b89074452fe2f549",
"valibot.ts": "9d670c8ddc0f9bb81a5dd1a80efd5eee",
"hono.ts": "54130437a23164b228769eb3ec967e4e",
"commands-validated.ts": "e4929484f6a64b784ff7b03327f58a3a",
"enums.ts": "350bddfda5b5eb357bbf6cff60f1808f"
"enums.ts": "87a5ccd7e57cc937104b2d256e8d67b1"
}
2 changes: 2 additions & 0 deletions __tests__/fixtures/openai/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/max-comment-lines, block65/no-comment-punctuation, block65/no-narrative-comment, block65/no-trailing-comment-punctuation

import { Command, stripUndefined, jsonStringify } from "@block65/rest-client";
import type { Except, UndefinedOnPartialDeep } from "type-fest";
import type {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/openai/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/no-comment-punctuation, block65/no-narrative-comment, block65/no-trailing-comment-punctuation

/** The role of the author of a message */
export const chatCompletionRole = [
"system",
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/openai/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/declaration-comments, block65/no-comment-history, block65/no-narrative-comment, block65/no-trailing-comment-punctuation

import { PublicValidationError } from "@block65/rest-client";
import { sValidator } from "@hono/standard-validator";
import type { ValidationTargets } from "hono";
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/openai/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/max-comment-lines, block65/no-absence-comment, block65/no-comment-list, block65/no-comment-punctuation, block65/no-figurative-comment, block65/no-hedging-comment, block65/no-jargon-comment, block65/no-narrative-comment, block65/no-negated-comment, block65/no-padded-comment, block65/no-trailing-comment-punctuation, unicorn-unported/comment-content

import type {
Jsonifiable,
LiteralUnion,
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/openai/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/max-comment-lines, block65/no-absence-comment, block65/no-comment-list, block65/no-comment-punctuation, block65/no-figurative-comment, block65/no-hedging-comment, block65/no-jargon-comment, block65/no-narrative-comment, block65/no-negated-comment, block65/no-padded-comment, block65/no-trailing-comment-punctuation, block65/prefer-exact-optional, unicorn-unported/comment-content

import * as v from "valibot";

export const inputDeleteModelResponseSchema = v.looseObject({
Expand Down
8 changes: 4 additions & 4 deletions __tests__/fixtures/petstore/.openapi-codegen-manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"#generator": "d9c25059b8f56e84cd41d51232262509",
"commands.ts": "608af748764e3adf1fd212532dfabd10",
"#generator": "25c3995293e37099b578d8abd616d258",
"commands.ts": "69c6a9f2924568fc08fd489508c9df34",
"types.ts": "ea65c3e67352d4e22b97af80085727b4",
"main.ts": "64edb526dcbcbd345e631ccff959f11d",
"valibot.ts": "e33769c41dc720ddafa6a22cd1c09dc2",
"hono.ts": "cea6c9d1b1305028c67d24cddfaa4f30",
"valibot.ts": "2383058357d21e704546455f4e073d67",
"hono.ts": "be7061d9a002b7d6f42bbdfc53727ec7",
"commands-validated.ts": "90b52a2210f1b9cc0e123225210fe74a"
}
2 changes: 2 additions & 0 deletions __tests__/fixtures/petstore/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/max-comment-lines, block65/no-narrative-comment, block65/no-trailing-comment-punctuation

import { Command, stripUndefined, jsonStringify } from "@block65/rest-client";
import type { UndefinedOnPartialDeep } from "type-fest";
import type {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/petstore/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/declaration-comments, block65/no-comment-history, block65/no-narrative-comment, block65/no-trailing-comment-punctuation

import { PublicValidationError } from "@block65/rest-client";
import { sValidator } from "@hono/standard-validator";
import type { ValidationTargets } from "hono";
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/petstore/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/prefer-exact-optional

import * as v from "valibot";

export const inputErrorSchema = v.looseObject({
Expand Down
17 changes: 12 additions & 5 deletions __tests__/fixtures/test1.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@
},
"EventSource": {
"oneOf": [
{ "type": "string", "enum": ["native"] },
{
"type": "string",
"enum": ["native"]
},
{
"type": "string",
"pattern": "^https://embed\\.example\\.com/.+$",
Expand Down Expand Up @@ -140,7 +143,8 @@
}
}
}
}
},
"additionalProperties": false
},
"LongRunningOperationSuccess": {
"type": "object",
Expand Down Expand Up @@ -272,7 +276,8 @@
}
}
}
]
],
"additionalProperties": false
},
"BillingAccountCreateRequest": {
"type": "object",
Expand Down Expand Up @@ -491,7 +496,8 @@
}
}
}
]
],
"additionalProperties": false
},
"UpdatePaymentMethodRequest": {
"type": "object",
Expand Down Expand Up @@ -668,7 +674,8 @@
}
}
}
]
],
"additionalProperties": false
},
"CreateBillingSubscriptionRequest": {
"type": "object",
Expand Down
8 changes: 4 additions & 4 deletions __tests__/fixtures/test1/.openapi-codegen-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"#generator": "d9c25059b8f56e84cd41d51232262509",
"#generator": "25c3995293e37099b578d8abd616d258",
"commands.ts": "19fd590dfc5cc8616a70dcf78326c027",
"types.ts": "a5a7fef55f948f68f724f7e50ba282ca",
"types.ts": "2fa39af3c41c92051312d9ba51ee2a5a",
"main.ts": "1e2091a697e1aa9d8b770d777c172bf8",
"valibot.ts": "70182c02f4c6ba0d6d3574c0bb1227d1",
"hono.ts": "f303b24e8f1d5b1e9c168fdb913d3636",
"valibot.ts": "d7e166b84040d92d2eefc8b2f986e5a1",
"hono.ts": "26885b9a53e8c0343a2fdb21f4eb8a37",
"commands-validated.ts": "cc5f84090799e163e229aabd160311f8",
"enums.ts": "26ade5ccad3bf30118ce8691b99b7c91"
}
2 changes: 2 additions & 0 deletions __tests__/fixtures/test1/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/declaration-comments, block65/no-comment-history, block65/no-narrative-comment, block65/no-trailing-comment-punctuation

import { PublicValidationError } from "@block65/rest-client";
import { sValidator } from "@hono/standard-validator";
import type { ValidationTargets } from "hono";
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/test1/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Do not edit directly
*/

// oxlint-disable block65/no-narrative-comment

import type { Jsonifiable, UndefinedOnPartialDeep } from "type-fest";

export type PromoCode = string;
Expand Down
Loading
Loading