Skip to content

refactor(core): reorganize API and utils files into a core folder #159

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

J3m5
Copy link
Contributor

@J3m5 J3m5 commented Jul 14, 2025

  • ♻️ Created a core folder to better organize API files and utility functions.

  • ✨ Extracted buildEnumObject function for creating objects from enum values.

  • ✨ Moved getType function into core with enhanced documentation.

  • 🐛 Fixed issue in parseOpenApi3Documentation to prevent duplicate headers.

  • ✨ Extracted assignResourceRelationships function.

  • 📝 Updated import paths to use a centralized index file for utilities.

  • 🔧 Updated dependencies and npm scripts

  • 🛠️ Updated CI configuration to support matrix builds

@J3m5 J3m5 self-assigned this Jul 14, 2025
Copy link

github-actions bot commented Jul 14, 2025

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 70.7% (🎯 70%) 280 / 396
🟢 Statements 70.75% (🎯 70%) 283 / 400
🟢 Functions 70.76% (🎯 70%) 46 / 65
🟢 Branches 58.51% (🎯 58%) 220 / 376
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/core/utils/buildEnumObject.ts 100% 83.33% 100% 100%
src/core/utils/getType.ts 80% 60% 100% 80% 19
src/core/utils/removeTrailingSlash.ts 100% 100% 100% 100%
src/graphql/parseGraphQl.ts 0% 0% 0% 0% 11-118
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/getType.ts 22.72% 21.95% 100% 22.72% 7-10, 16, 24-51, 56-66
src/hydra/parseHydraDocumentation.ts 87.12% 77.87% 90.9% 87.02% 31, 58-60, 66, 74-76, 80-82, 102-108, 114, 121-123, 196, 211, 269, 280-285, 370
src/openapi3/handleJson.ts 90.47% 65.62% 92.85% 90.36% 39, 58, 123, 174, 181, 195, 205, 216
src/openapi3/parseOpenApi3Documentation.ts 0% 0% 0% 0% 18-43
src/swagger/handleJson.ts 81.81% 64.7% 100% 81.81% 21, 30, 36, 42
src/swagger/parseSwaggerDocumentation.ts 0% 100% 0% 0% 16-36
Generated in workflow #256 for commit 05de4f0 by the Vitest Coverage Report Action

@J3m5 J3m5 requested review from Copilot and a team July 14, 2025 17:22
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 reorganizes shared API and utility code under a new core directory, extracts and centralizes helper functions, and improves request header handling.

  • Consolidated core classes and types in src/core
  • Extracted utilities (buildEnumObject, getType, assignResourceRelationships) into src/core/utils with updated imports
  • Enhanced parseOpenApi3Documentation to only append the Accept header once

Reviewed Changes

Copilot reviewed 26 out of 29 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/swagger/parseSwaggerDocumentation.ts Updated imports of Api and removeTrailingSlash to point at core
src/swagger/handleJson.ts Swapped manual enum creation for buildEnumObject, moved imports to core utils
src/openapi3/parseOpenApi3Documentation.ts Refactored header setup to avoid duplicate Accept entries, centralized imports
src/openapi3/handleJson.ts Introduced assignResourceRelationships, optimized operation destructuring
src/openapi3/handleJson.test.ts Updated parsedJsonReplacer import to core utils
src/openapi3/getType.ts Removed local getType (moved to core utils)
src/index.ts Replaced individual exports with consolidated core export
src/hydra/parseHydraDocumentation.ts Removed duplicate removeTrailingSlash, migrated imports to core
src/hydra/parseHydraDocumentation.test.ts Updated parsedJsonReplacer import to core utils
src/hydra/getType.ts Updated FieldType import to core index
src/hydra/getParameters.ts Migrated Resource, Parameter, RequestInitExtended imports to core
src/hydra/fetchResource.ts Updated RequestInitExtended import to core types
src/hydra/fetchJsonLd.ts Updated RequestInitExtended import to core types
src/graphql/parseGraphQl.ts Pointed Api, Field, Resource imports at core index
src/core/utils/removeTrailingSlash.ts Added new removeTrailingSlash utility
src/core/utils/parsedJsonReplacer.ts Converted to named export
src/core/utils/index.ts Exposed all core utilities via single index
src/core/utils/getType.ts Introduced shared getType helper
src/core/utils/getResources.test.ts Updated test import for getResourcePaths
src/core/utils/getResourcePaths.ts Renamed and exported path utility
src/core/utils/buildEnumObject.ts Introduced new buildEnumObject helper
src/core/index.ts Aggregated core exports
src/core/{Resource,Operation,Field,Api}.ts Updated assignSealed imports to use utils index
Comments suppressed due to low confidence (3)

src/core/utils/buildEnumObject.ts:11

  • Add unit tests for buildEnumObject to verify correct mapping of enum values and that it returns null for empty or undefined inputs.
export function buildEnumObject(

src/openapi3/handleJson.ts:26

  • Add tests for assignResourceRelationships to ensure fields are correctly classified as embedded or referenced based on type and naming patterns.
function assignResourceRelationships(resources: Resource[]) {

src/core/utils/getType.ts:14

  • Introduce unit tests for getType to cover format mappings (e.g., int32→integer) and default fallback behavior.
export function getType(openApiType: string, format?: string): FieldType {

J3m5 added 8 commits July 14, 2025 19:25
…update paths

- Moved utility imports to a centralized index file in the utils directory.
- Updated import paths across various modules to use the new index file.
- Removed redundant utility functions and adjusted related code accordingly.

Signed-off-by: J3m5 <[email protected]>
- Implement buildEnumObject to create an object from enum values.
- Update openapi and swagger handleJson to use buildEnumObject.
- Refactor inflection imports to use named imports instead of default import
- Small refactors
- Add TSDoc for the getTYpe util function

Signed-off-by: J3m5 <[email protected]>
- Extracted assignResourceRelationships function to assign embedded and reference properties to resource fields.
- Refactored handleJson to utilize the new relationship assignment function.

Signed-off-by: J3m5 <[email protected]>
J3m5 added 2 commits July 14, 2025 19:57
- Updated @types/node from 22.15.34 to 22.16.3
- Updated msw from 2.10.2 to 2.10.4
- Updated oxlint from 1.4.0 to 1.6.0
- Adjusted test script to use 'vitest run' and added 'test:watch'

Signed-off-by: J3m5 <[email protected]>
- Added concurrency settings
- Implemented matrix strategy for OS and Node versions

Signed-off-by: J3m5 <[email protected]>
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.

1 participant