-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Support Nx Crystal Plugin and inferred tasks #41
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
base: main
Are you sure you want to change the base?
Conversation
- Updated schema.json to accept inputSpec as either string or Record<string, string> - Updated TypeScript interface to match new schema - Modified executor to handle multiple input specs by generating each in subdirectories - Added comprehensive unit tests for the new functionality Resolves #36
- Updated reference documentation to show both string and object types - Added examples for single and multiple API specifications - Added comprehensive example for microservice architecture use case
- Updated hasher Zod schema to accept union of string and record - Added logic to handle both single and multiple inputSpec hashing - Added comprehensive tests for multiple inputSpec scenarios - Ensures proper caching support for the new feature
- Cast path parameters to string in mock implementations - Ensures proper type handling for readFileSync and fetch mocks
Allow users to provide a custom target name when running the add-generate-api-target generator. If a build target exists, automatically add the custom target to its dependsOn array. Closes #38 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add plugin.ts with CreateNodesV2 implementation - Automatically detect OpenAPI spec files in workspace - Create generate-api tasks for detected specs - Support configurable target names and output paths - Export plugin from index.ts - Update package.json with nx-plugin configuration Resolves #16 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Remove unused imports (relative, existsSync) - Replace any types with unknown type - Fix unused variable warnings - Remove unused defaultSpecFilePatterns variable - Add proper error handling without unused catch variable 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
| "nx-plugin": { | ||
| "projectFilePatterns": [ | ||
| "**/*.openapi.json", | ||
| "**/*.openapi.yaml", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a trailing space after "**/*.openapi.yaml" in the file pattern array that should be removed. While it might not cause immediate issues, it's best to keep these pattern strings clean to avoid potential pattern matching problems in different environments.
- "**/*.openapi.yaml",
+ "**/*.openapi.yaml",| "**/*.openapi.yaml", | |
| "**/*.openapi.yaml", |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
|
We should make the file pattern to find matching openapi-specs configurable to lot hardcode it to openapi.{json,yaml.yml} |
Code Review Complete ✅I've thoroughly reviewed this PR implementing Crystal Plugin support for the Nx OpenAPI plugin. Here's my detailed feedback: OverviewThis is an excellent implementation of Crystal Plugin (Project Inference) support that resolves #16. The code quality is high and the feature adds significant value to the plugin. Code Quality Analysis 🔍Strengths:
Code Patterns:
Testing Results 🧪
Minor Suggestions for Future Improvements 💡
Security Considerations 🔒
Documentation 📚The documentation updates in ConclusionThis is a high-quality PR that significantly enhances the plugin's usability. The Crystal Plugin support will make it much easier for users to work with OpenAPI specifications in Nx workspaces without manual configuration. Recommendation: Ready to merge after addressing any minor suggestions if desired. Great work! 🎉 |
- Make specFilePatterns configurable in plugin options - Expand default glob pattern to include common API spec patterns - Add pattern matching logic in createNodesInternal - Update inputs to cover various OpenAPI file patterns - Maintain backward compatibility with default patterns Addresses PR feedback to make file patterns configurable instead of hardcoded. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
| const regex = new RegExp( | ||
| '^' + pattern | ||
| .replace(/\./g, '\\.') | ||
| .replace(/\*\*/g, '.*') | ||
| .replace(/\*/g, '[^/]*') | ||
| .replace(/\{([^}]+)\}/g, '($1)') | ||
| .replace(/,/g, '|') + '$' | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern conversion has an issue with the anchors (^ and $). These anchors force the pattern to match the entire string, but for file path matching, you need to match patterns that may appear anywhere in the path.
Consider either:
- Removing the anchors:
const regex = new RegExp(
pattern
.replace(/\./g, '\\.')
.replace(/\*\*/g, '.*')
.replace(/\*/g, '[^/]*')
.replace(/\{([^}]+)\}/g, '($1)')
.replace(/,/g, '|')
);- Or using a dedicated glob-to-regex library like
micromatchorminimatchwhich handles these edge cases correctly.
This will ensure patterns like **/openapi.json correctly match paths like apps/demo/openapi.json.
| const regex = new RegExp( | |
| '^' + pattern | |
| .replace(/\./g, '\\.') | |
| .replace(/\*\*/g, '.*') | |
| .replace(/\*/g, '[^/]*') | |
| .replace(/\{([^}]+)\}/g, '($1)') | |
| .replace(/,/g, '|') + '$' | |
| ); | |
| const regex = new RegExp( | |
| pattern | |
| .replace(/\./g, '\\.') | |
| .replace(/\*\*/g, '.*') | |
| .replace(/\*/g, '[^/]*') | |
| .replace(/\{([^}]+)\}/g, '($1)') | |
| .replace(/,/g, '|') | |
| ); |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
Summary
This PR implements Crystal Plugin (Project Inference) support for the Nx OpenAPI plugin, resolving #16. Updated to address PR feedback with configurable file patterns.
Changes Made
plugin.tswithCreateNodesV2implementationgenerate-apitasksFeatures
generate-apitasks without manual configurationConfigurable File Patterns
The plugin now supports custom file patterns through the
specFilePatternsoption:Default patterns:
**/*.openapi.{json,yaml,yml}**/openapi.{json,yaml,yml}-spec,api-spec,swaggerCustom configuration example:
{ "plugins": [ { "plugin": "@lambda-solutions/nx-plugin-openapi", "options": { "targetName": "generate-api", "specFilePatterns": [ "**/*-api.json", "**/api-docs/*.yaml", "services/**/swagger.json" ] } } ] }Technical Details
The plugin scans for OpenAPI files using an expanded pattern and filters based on user-specified patterns. Users can configure the plugin in
nx.jsonwith custom file patterns, target names, and output paths.Testing
Migration
This change is fully backward compatible. Existing explicit task configurations will continue to work alongside the new inferred tasks. Users can optionally adopt configurable patterns for custom OpenAPI file naming conventions.
🤖 Generated with Claude Code