Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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,180 changes: 5,180 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/code-gen-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export class CodeGenProcess {
Ts: this.config.Ts,
formatDescription:
this.schemaParserFabric.schemaFormatters.formatDescription,
escapeJSDocContent:
this.schemaParserFabric.schemaFormatters.escapeJSDocContent,
internalCase: internalCase,
classNameCase: pascalCase,
pascalCase: pascalCase,
Expand Down
20 changes: 16 additions & 4 deletions src/schema-parser/schema-formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,30 @@ export class SchemaFormatters {
return formatterFn?.(parsedSchema) || parsedSchema;
};

escapeJSDocContent = (content) => {
if (!content) return "";
// Escape */ sequences to prevent breaking out of JSDoc comments
// Escape /* sequences to prevent creating nested comments
return content
.replace(/\*\//g, "*\\/")
.replace(/\/\*/g, "\\/*");
};

formatDescription = (description, inline) => {
if (!description) return "";

const hasMultipleLines = description.includes("\n");
// First escape JSDoc comment characters
const escapedDescription = this.escapeJSDocContent(description);

const hasMultipleLines = escapedDescription.includes("\n");

if (!hasMultipleLines) return description;
if (!hasMultipleLines) return escapedDescription;

if (inline) {
return (
lodash
// @ts-expect-error TS(2339) FIXME: Property '_' does not exist on type 'LoDashStatic'... Remove this comment to see the full error message
._(description)
._(escapedDescription)
.split(/\n/g)
.map((part) => part.trim())
.compact()
Expand All @@ -122,7 +134,7 @@ export class SchemaFormatters {
);
}

return description.replace(/\n$/g, "");
return escapedDescription.replace(/\n$/g, "");
};

formatObjectContent = (content) => {
Expand Down
8 changes: 4 additions & 4 deletions templates/base/object-field-jsdoc.ejs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<%
const { field, utils } = it;
const { formatDescription, require, _ } = utils;
const { formatDescription, escapeJSDocContent, require, _ } = utils;

const comments = _.uniq(
_.compact([
field.title,
field.title && escapeJSDocContent(field.title),
field.description,
field.deprecated && ` * @deprecated`,
!_.isUndefined(field.format) && `@format ${field.format}`,
!_.isUndefined(field.minimum) && `@min ${field.minimum}`,
!_.isUndefined(field.maximum) && `@max ${field.maximum}`,
!_.isUndefined(field.pattern) && `@pattern ${field.pattern}`,
!_.isUndefined(field.pattern) && `@pattern ${escapeJSDocContent(field.pattern)}`,
!_.isUndefined(field.example) &&
`@example ${_.isObject(field.example) ? JSON.stringify(field.example) : field.example}`,
`@example ${_.isObject(field.example) ? JSON.stringify(field.example) : escapeJSDocContent(field.example)}`,
]).reduce((acc, comment) => [...acc, ...comment.split(/\n/g)], []),
);
%>
Expand Down
6 changes: 3 additions & 3 deletions templates/base/route-docs.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
const { config, route, utils } = it;
const { _, formatDescription, fmtToJSDocLine, pascalCase, require } = utils;
const { _, formatDescription, escapeJSDocContent, fmtToJSDocLine, pascalCase, require } = utils;
const { raw, request, routeName } = route;

const jsDocDescription = raw.description ?
Expand All @@ -9,7 +9,7 @@ const jsDocDescription = raw.description ?
const jsDocLines = _.compact([
_.size(raw.tags) && ` * @tags ${raw.tags.join(", ")}`,
` * @name ${pascalCase(routeName.usage)}`,
raw.summary && ` * @summary ${raw.summary}`,
raw.summary && ` * @summary ${escapeJSDocContent(raw.summary)}`,
` * @request ${_.upperCase(request.method)}:${raw.route}`,
raw.deprecated && ` * @deprecated`,
routeName.duplicate && ` * @originalName ${routeName.original}`,
Expand All @@ -18,7 +18,7 @@ const jsDocLines = _.compact([
...(config.generateResponses && raw.responsesTypes.length
? raw.responsesTypes.map(
({ type, status, description, isSuccess }) =>
` * @response \`${status}\` \`${_.replace(_.replace(type, /\/\*/g, "\\*"), /\*\//g, "*\\")}\` ${description}`,
` * @response \`${status}\` \`${_.replace(_.replace(type, /\/\*/g, "\\*"), /\*\//g, "*\\")}\` ${escapeJSDocContent(description)}`,
)
: []),
]).map(str => str.trimEnd()).join("\n");
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/extended.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27686,7 +27686,7 @@ export interface SecretScanningUpdateAlertPayload {
export interface SelectedActions {
/** Whether GitHub-owned actions are allowed. For example, this includes the actions in the \`actions\` organization. */
github_owned_allowed: boolean;
/** Specifies a list of string-matching patterns to allow specific action(s). Wildcards, tags, and SHAs are allowed. For example, \`monalisa/octocat@*\`, \`monalisa/octocat@v2\`, \`monalisa/*\`." */
/** Specifies a list of string-matching patterns to allow specific action(s). Wildcards, tags, and SHAs are allowed. For example, \`monalisa/octocat@*\`, \`monalisa/octocat@v2\`, \`monalisa\\/*\`." */
patterns_allowed: string[];
/** Whether actions in GitHub Marketplace from verified creators are allowed. Set to \`true\` to allow all GitHub Marketplace actions by verified creators. */
verified_allowed: boolean;
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/simple.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15493,7 +15493,7 @@ export enum SecretScanningAlertState {
export interface SelectedActions {
/** Whether GitHub-owned actions are allowed. For example, this includes the actions in the \`actions\` organization. */
github_owned_allowed: boolean;
/** Specifies a list of string-matching patterns to allow specific action(s). Wildcards, tags, and SHAs are allowed. For example, \`monalisa/octocat@*\`, \`monalisa/octocat@v2\`, \`monalisa/*\`." */
/** Specifies a list of string-matching patterns to allow specific action(s). Wildcards, tags, and SHAs are allowed. For example, \`monalisa/octocat@*\`, \`monalisa/octocat@v2\`, \`monalisa\\/*\`." */
patterns_allowed: string[];
/** Whether actions in GitHub Marketplace from verified creators are allowed. Set to \`true\` to allow all GitHub Marketplace actions by verified creators. */
verified_allowed: boolean;
Expand Down
Loading
Loading