Skip to content

Commit 6be2111

Browse files
authored
Fix generation of parameters with a dot in the description (#986)
1 parent 20617a2 commit 6be2111

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/transform/operation-object.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import transformSchemaObject from "./schema-object.js";
2020
export interface TransformOperationObjectOptions {
2121
path: string;
2222
ctx: GlobalContext;
23+
wrapObject?: boolean;
2324
}
2425

2526
export default function transformOperationObject(
2627
operationObject: OperationObject,
27-
{ path, ctx }: TransformOperationObjectOptions
28+
{ path, ctx, wrapObject = true }: TransformOperationObjectOptions
2829
): string {
2930
let { indentLv } = ctx;
30-
const output: string[] = ["{"];
31+
const output: string[] = wrapObject ? ["{"] : [];
3132
indentLv++;
3233
const c = getSchemaObjectComment(operationObject, indentLv);
3334
if (c) output.push(indent(c, indentLv));
@@ -154,6 +155,8 @@ export default function transformOperationObject(
154155
}
155156

156157
indentLv--;
157-
output.push(indent("}", indentLv));
158+
if (wrapObject) {
159+
output.push(indent("}", indentLv));
160+
}
158161
return output.join("\n");
159162
}

src/transform/path-item-object.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export interface TransformPathItemObjectOptions {
99

1010
type Method = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
1111

12-
const UNWRAP_OBJ_RE = /^\s*{\s*([^.]+)\s*}\s*$/;
13-
1412
export default function transformPathItemObject(
1513
pathItem: PathItemObject,
1614
{ path, ctx }: TransformPathItemObjectOptions
@@ -44,9 +42,7 @@ export default function transformPathItemObject(
4442
if (pathItem.parameters && pathItem.parameters.length) {
4543
output.push(
4644
indent(
47-
transformOperationObject({ parameters: pathItem.parameters }, { path, ctx })
48-
.replace(UNWRAP_OBJ_RE, "$1")
49-
.trim(),
45+
transformOperationObject({ parameters: pathItem.parameters }, { path, ctx, wrapObject: false }).trim(),
5046
indentLv
5147
)
5248
);

test/paths-object.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("Paths Object", () => {
2020
test("basic", () => {
2121
const schema: PathsObject = {
2222
"/api/v1/user/{user_id}": {
23-
parameters: [{ name: "page", in: "query", schema: { type: "number" } }],
23+
parameters: [{ name: "page", in: "query", schema: { type: "number" }, description: "Page number." }],
2424
get: {
2525
parameters: [{ name: "user_id", in: "path" }],
2626
responses: {
@@ -79,6 +79,7 @@ describe("Paths Object", () => {
7979
};
8080
};
8181
parameters?: {
82+
/** @description Page number. */
8283
query?: {
8384
page?: number;
8485
};

0 commit comments

Comments
 (0)