Skip to content

refactor: Remove lodash.get dependency #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2025
Merged

refactor: Remove lodash.get dependency #154

merged 3 commits into from
Jun 30, 2025

Conversation

J3m5
Copy link
Contributor

@J3m5 J3m5 commented Jun 14, 2025

Eliminate the lodash.get dependency and replace its usage with optional chaining, default values and type narrowing.

close #146

Copy link

github-actions bot commented Jun 14, 2025

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 71.35% (🎯 70%) 289 / 405
🟢 Statements 71.39% (🎯 70%) 292 / 409
🟢 Functions 71.64% (🎯 70%) 48 / 67
🟢 Branches 59.63% (🎯 58%) 229 / 384
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/hydra/fetchJsonLd.ts 100% 95% 100% 100%
src/hydra/fetchResource.ts 100% 60% 100% 100%
src/hydra/getParameters.ts 90% 75% 100% 88.88% 14
src/hydra/parseHydraDocumentation.ts 87.4% 78.26% 91.66% 87.31% 34, 61-63, 69, 77-79, 83-85, 105-111, 117, 124-126, 207, 222, 280, 291-296, 381
src/openapi3/dereferencedOpenApiv3.ts 100% 100% 100% 100%
src/openapi3/handleJson.ts 91.48% 68.86% 93.75% 91.39% 35, 115, 166, 173, 181, 191, 202, 264
src/openapi3/parseOpenApi3Documentation.ts 0% 0% 0% 0% 17-40
src/swagger/handleJson.ts 80.76% 65.21% 100% 80.76% 10, 25, 34, 40, 46
Generated in workflow #232 for commit 9c54332 by the Vitest Coverage Report Action

Base automatically changed from oxlint to main June 14, 2025 17:58
@J3m5 J3m5 force-pushed the remove-lodash.get branch from 1631843 to 4a4f5ab Compare June 14, 2025 17:59
@J3m5 J3m5 requested review from dunglas, alanpoulain and soyuka June 14, 2025 18:00
@J3m5 J3m5 self-assigned this Jun 14, 2025
@J3m5 J3m5 requested a review from Copilot June 14, 2025 18:08
Copilot

This comment was marked as outdated.

@J3m5 J3m5 force-pushed the remove-lodash.get branch 2 times, most recently from c739b9d to 01354c9 Compare June 15, 2025 17:18
@J3m5 J3m5 requested a review from Copilot June 17, 2025 07:07
Copilot

This comment was marked as outdated.

@J3m5 J3m5 requested a review from Copilot June 30, 2025 08:11
Copilot

This comment was marked as outdated.

@J3m5 J3m5 force-pushed the remove-lodash.get branch 3 times, most recently from a8143f1 to 1e37761 Compare June 30, 2025 08:40
@J3m5 J3m5 force-pushed the remove-lodash.get branch 2 times, most recently from 7423fa7 to 171cac0 Compare June 30, 2025 08:50
J3m5 added 2 commits June 30, 2025 10:54
* Removed duplicate definitions from `src/hydra/types.ts` and deleted `src/openapi3/types.ts`.
* Added a single canonical `RequestInitExtended` interface in `src/types.ts`.
* Updated all affected import paths across Hydra and OpenAPI3 modules.

Signed-off-by: J3m5 <5523410+J3m5@users.noreply.github.com>
…stom guards

* Introduce `src/openapi3/dereferencedOpenApiv3.ts`, providing fully-dereferenced
  versions of core OpenAPI 3 objects (Document, OperationObject, SchemaObject,
  etc.).
* Refactor `handleJson.ts` to consume the new types:
  * Remove bespoke type-guard helpers (`isParameter`, `isSchema`, …).
  * Eliminate most explicit `as` casts and manual type-narrowing logic.
  * Simplify enum/array handling through shared helpers (`buildEnumObject`,
    `getArrayType`).

Signed-off-by: J3m5 <5523410+J3m5@users.noreply.github.com>
@J3m5 J3m5 force-pushed the remove-lodash.get branch from 171cac0 to 9c54332 Compare June 30, 2025 08:54
@J3m5 J3m5 requested a review from Copilot June 30, 2025 08:57
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the lodash.get dependency by replacing its calls with native optional chaining, destructuring, and default values, centralizes the RequestInitExtended type, and adds helper functions for enum and array handling.

  • Replace all lodash.get usages with optional chaining and default values
  • Consolidate RequestInitExtended into a single definition in src/types.ts
  • Introduce buildEnumObject and getArrayType in the OpenAPI v3 handler

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/types.ts Add Nullable type and unified RequestInitExtended interface
src/swagger/handleJson.ts Remove lodash.get, use destructuring/optional chaining, update import
src/openapi3/types.ts Remove duplicate RequestInitExtended definition
src/openapi3/parseOpenApi3Documentation.ts Update import of RequestInitExtended
src/openapi3/handleJson.ts Replace lodash.get, add buildEnumObject/getArrayType, wrap parse
src/openapi3/dereferencedOpenApiv3.ts Add types for dereferenced OpenAPI v3 schemas
src/hydra/types.ts Remove duplicate RequestInitExtended definition
src/hydra/parseHydraDocumentation.ts Remove lodash.get, use optional chaining
src/hydra/getParameters.ts Update import of RequestInitExtended
src/hydra/fetchResource.ts Update type imports
src/hydra/fetchJsonLd.ts Update import of RequestInitExtended
package.json Remove lodash.get and its types
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (4)

src/swagger/handleJson.ts:10

  • Provide a descriptive message when throwing errors instead of using an empty Error().
    return url.slice(0, -1);

src/openapi3/handleJson.ts:49

  • [nitpick] Add a JSDoc comment explaining the purpose, inputs, and outputs of buildEnumObject to improve readability.
function buildEnumObject(enumArray: SchemaObjectDereferenced["enum"]) {

src/swagger/handleJson.ts:46

  • Include an informative message in this thrown Error to aid debugging and remove the // @todo placeholder.
      throw new Error(); // @TODO

src/swagger/handleJson.ts:8

  • [nitpick] The removeTrailingSlash function is duplicated in src/openapi3/handleJson.ts; consider extracting it into a shared utility.
export function removeTrailingSlash(url: string): string {

@J3m5 J3m5 changed the title Refactor: Remove lodash.get dependency refactor: Remove lodash.get dependency Jun 30, 2025
@J3m5 J3m5 merged commit e76a32b into main Jun 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get rid of lodash.get
1 participant