Skip to content

feat: Fix config file reading and add API endpoints generation with path parameter support#2

Merged
kolotao merged 2 commits into
mainfrom
dev
Dec 11, 2025
Merged

feat: Fix config file reading and add API endpoints generation with path parameter support#2
kolotao merged 2 commits into
mainfrom
dev

Conversation

@kolotao
Copy link
Copy Markdown
Member

@kolotao kolotao commented Dec 11, 2025

🎯 Summary

This PR fixes a critical bug with config file reading and adds a new feature for generating API endpoint URL constants with path parameter support.

🐛 Bug Fixes

Config File Reading

  • Fixed: Config file values were being overwritten by CLI default values (e.g., false for boolean flags)
  • Solution: Added explicit flag detection to only override config file values when flags are actually provided in CLI
  • Impact: Config file now works correctly without requiring CLI flags

✨ New Features

API Endpoints Generation

  • Added: --generate-api-endpoints flag to generate API endpoint URL constants
  • Structure: Endpoints are organized in nested object structure matching endpoint folder hierarchy
  • Location: Generated in api/index.ts directory
  • Usage: Provides type-safe endpoint URLs for frontend development

Path Parameter Support

  • Added: buildUrl() utility function for replacing path parameters in endpoint URLs
  • Features:
    • Supports single and multiple path parameters
    • Type-safe parameter replacement
    • Error handling for missing parameters
    • Works seamlessly with generated PathParams types

📝 Changes

Core Changes

  • src/config.ts: Fixed config file reading logic with explicit flag detection
  • src/types.ts: Added generateApiEndpoints option to Config interface
  • src/cli.ts: Added --generate-api-endpoints CLI flag
  • src/writer.ts: Added API endpoints file generation logic
  • src/generator/api-endpoints-generator.ts: New module for generating endpoint constants and buildUrl utility

Documentation

  • Updated README.md with:
    • API endpoints generation documentation
    • buildUrl function usage examples
    • Path parameter handling guide
  • Updated swagger-type-parser.config.json.example with new option

🚀 Usage Examples

Config File

{
"input": "http://localhost:8000/api/v1/openapi.json",
"output": "./src/api/types",
"generateApiEndpoints": true
}### API Endpoints
import { apiEndpoints, buildUrl } from './api/types/api';

// Simple endpoint
await apiClient.post(apiEndpoints.auth.auth_login, payload);

// With path parameters
const url = buildUrl(apiEndpoints.users.users_profile, { user_id: '123' });
// Returns: '/api/v1/users/profile/123'## ✅ Testing

  • ✅ Config file reading works correctly
  • ✅ CLI flags properly override config file values
  • ✅ API endpoints generated with correct structure
  • buildUrl function handles single and multiple parameters
  • ✅ Error handling for missing parameters

📦 Breaking Changes

None - this is a backward-compatible feature addition and bug fix.

- Introduce filterUndefined function to remove undefined values from the configuration object
- Update mergeConfig function to utilize filtered CLI config, ensuring only non-undefined values override file config values
- Add buildUrl function to replace path parameters in endpoint URLs
- Support for single and multiple path parameters
- Type-safe parameter replacement with error handling
- Update README with examples of using buildUrl
- Remove unused placeholder variable
@kolotao kolotao merged commit e58c8c5 into main Dec 11, 2025
2 checks 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.

1 participant