Skip to content

Commit ff8b61d

Browse files
committed
refactor(docs): improve JSDoc comments following oxlint jsdoc plugin
- Edit .oxlintrc.json to enable jsdoc plugin - Added parameter and return type annotations in buildEnumObject, getType, fetchJsonLd, parseHydraDocumentation, and handleJson functions. Signed-off-by: J3m5 <5523410+J3m5@users.noreply.github.com>
1 parent 323858b commit ff8b61d

6 files changed

Lines changed: 47 additions & 11 deletions

File tree

.oxlintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"import",
2121
"eslint",
2222
"oxc",
23-
"promise"
23+
"promise",
24+
"jsdoc"
2425
],
2526
"rules": {
2627
"@typescript-eslint/no-empty-object-type": [

src/core/utils/buildEnumObject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { humanize } from "inflection";
55
* The keys of the object are the humanized versions of the enum values,
66
* and the values are the original enum values.
77
*
8-
* @param enumArray - An array of enum values.
9-
* @returns An object mapping humanized enum names to their original values, or null if the input is empty.
8+
* @param {any[] | undefined} enumArray - An array of enum values.
9+
* @returns {Record<string, string | number> | null} An object mapping humanized enum names to their original values, or null if the input is empty.
1010
*/
1111
export function buildEnumObject(
1212
enumArray: any[] | undefined,

src/core/utils/getType.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import type { FieldType } from "../Field.js";
77
* If a format is provided, it will map certain formats (e.g., "int32", "int64") to "integer".
88
* Otherwise, it will camelize the format string. If no format is provided, it returns the OpenAPI type.
99
*
10-
* @param openApiType - The OpenAPI type string.
11-
* @param format - An optional format string.
12-
* @returns The mapped FieldType.
10+
* @param {string} openApiType - The OpenAPI type string.
11+
* @param {string} [format] - An optional format string.
12+
* @returns {FieldType} The mapped FieldType.
1313
*/
1414
export function getType(openApiType: string, format?: string): FieldType {
1515
if (format) {

src/hydra/fetchJsonLd.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ interface ResponseDocument extends RemoteDocument {
1919

2020
/**
2121
* Sends a JSON-LD request to the API.
22+
* @param {string} url The URL to request.
23+
* @param {RequestInitExtended} [options] Optional fetch options.
24+
* @returns {Promise<ResponseDocument | EmptyResponseDocument>} The response document or an empty response document.
2225
*/
2326
export default async function fetchJsonLd(
2427
url: string,

src/hydra/parseHydraDocumentation.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@ import type {
1616

1717
/**
1818
* Extracts the short name of a resource.
19+
* @param {string} url The resource URL.
20+
* @param {string} entrypointUrl The API entrypoint URL.
21+
* @returns {string} The short name of the resource.
1922
*/
2023
function guessNameFromUrl(url: string, entrypointUrl: string): string {
2124
return url.slice(entrypointUrl.length + 1);
2225
}
2326

27+
/**
28+
* Gets the title or label from an ExpandedOperation object.
29+
* @param {ExpandedOperation} obj The operation object.
30+
* @returns {string} The title or label.
31+
*/
2432
function getTitleOrLabel(obj: ExpandedOperation): string {
2533
const a =
2634
obj["http://www.w3.org/2000/01/rdf-schema#label"] ??
@@ -36,6 +44,9 @@ function getTitleOrLabel(obj: ExpandedOperation): string {
3644

3745
/**
3846
* Finds the description of the class with the given id.
47+
* @param {ExpandedDoc[]} docs The expanded documentation array.
48+
* @param {string} classToFind The class ID to find.
49+
* @returns {ExpandedClass} The matching expanded class.
3950
*/
4051
function findSupportedClass(
4152
docs: ExpandedDoc[],
@@ -87,6 +98,9 @@ export function getDocumentationUrlFromHeaders(headers: Headers): string {
8798

8899
/**
89100
* Retrieves Hydra's entrypoint and API docs.
101+
* @param {string} entrypointUrl The URL of the API entrypoint.
102+
* @param {RequestInitExtended} [options] Optional fetch options.
103+
* @returns {Promise<{ entrypointUrl: string; docsUrl: string; response: Response; entrypoint: Entrypoint[]; docs: ExpandedDoc[]; }>} An object containing entrypointUrl, docsUrl, response, entrypoint, and docs.
90104
*/
91105
async function fetchEntrypointAndDocs(
92106
entrypointUrl: string,
@@ -98,6 +112,11 @@ async function fetchEntrypointAndDocs(
98112
entrypoint: Entrypoint[];
99113
docs: ExpandedDoc[];
100114
}> {
115+
/**
116+
* Loads a JSON-LD document from the given input.
117+
* @param {string} input The URL or IRI to load.
118+
* @returns {Promise<any>} The fetched JSON-LD response.
119+
*/
101120
async function documentLoader(input: string) {
102121
const response = await fetchJsonLd(input, options);
103122
if (!("body" in response)) {
@@ -154,6 +173,12 @@ async function fetchEntrypointAndDocs(
154173
}
155174
}
156175

176+
/**
177+
* Finds the related class for a property.
178+
* @param {ExpandedDoc[]} docs The expanded documentation array.
179+
* @param {ExpandedRdfProperty} property The property to find the related class for.
180+
* @returns {ExpandedClass} The related expanded class.
181+
*/
157182
function findRelatedClass(
158183
docs: ExpandedDoc[],
159184
property: ExpandedRdfProperty,
@@ -213,6 +238,9 @@ function findRelatedClass(
213238

214239
/**
215240
* Parses Hydra documentation and converts it to an intermediate representation.
241+
* @param {string} entrypointUrl The API entrypoint URL.
242+
* @param {RequestInitExtended} [options] Optional fetch options.
243+
* @returns {Promise<{ api: Api; response: Response; status: number; }>} The parsed API, response, and status.
216244
*/
217245
export default async function parseHydraDocumentation(
218246
entrypointUrl: string,
@@ -470,8 +498,12 @@ export default async function parseHydraDocumentation(
470498
});
471499

472500
resource.parameters = [];
473-
resource.getParameters = (): Promise<Parameter[]> =>
474-
getParameters(resource, options);
501+
resource.getParameters =
502+
/**
503+
* Gets the parameters for the resource.
504+
* @returns {Promise<Parameter[]>} The parameters for the resource.
505+
*/
506+
(): Promise<Parameter[]> => getParameters(resource, options);
475507

476508
resources.push(resource);
477509
}

src/openapi3/handleJson.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import type {
2020
* Assigns relationships between resources based on their fields.
2121
* Sets the field's `embedded` or `reference` property depending on its type.
2222
*
23-
* @param resources - Array of Resource objects to process.
24-
* @returns The same array of resources with relationships assigned.
23+
* @param {Resource[]} resources - Array of Resource objects to process.
24+
* @returns {Resource[]} The same array of resources with relationships assigned.
2525
*/
26-
function assignResourceRelationships(resources: Resource[]) {
26+
function assignResourceRelationships(resources: Resource[]): Resource[] {
2727
for (const resource of resources) {
2828
for (const field of resource.fields ?? []) {
2929
const name = camelize(field.name).replace(/Ids?$/, "");

0 commit comments

Comments
 (0)