-
Notifications
You must be signed in to change notification settings - Fork 0
feature: openapi processor #46
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
Conversation
- Implement bundle step with @scalar/json-magic for external ref resolution - Implement upgrade step with @scalar/openapi-upgrader for OAS 2.0/3.0 to 3.1 - Implement dereference step with @scalar/openapi-parser for inline refs - Add ProcessorError with step tracking (bundle/upgrade/dereference/validation) - Handle empty input by returning minimal valid OpenAPI 3.1 document - Add comprehensive unit tests with YAML/JSON fixtures - Update vitest.config.ts to exclude temp/ from test discovery Closes: vite-open-api-server-z5y.2
📝 WalkthroughWalkthroughImplements a full OpenAPI processing pipeline: bundling external refs, upgrading to OpenAPI 3.1, dereferencing $ref pointers, and validating the final document. Adds step-aware Changes
Sequence DiagramsequenceDiagram
participant Client
participant Processor
participant Bundler
participant Upgrader
participant Dereferencer
participant Validator
Client->>Processor: processOpenApiDocument(input)
activate Processor
alt Empty input (null/undefined/empty)
Processor->>Processor: createEmptyDocument()
Processor-->>Client: minimal OpenAPI 3.1 document
else Non-empty input
Processor->>Bundler: bundleDocument(input)
activate Bundler
Bundler-->>Processor: bundled document
deactivate Bundler
Processor->>Upgrader: upgradeDocument(bundled)
activate Upgrader
Upgrader-->>Processor: upgraded OpenAPI 3.1 doc
deactivate Upgrader
Processor->>Dereferencer: dereferenceDocument(upgraded)
activate Dereferencer
Dereferencer-->>Processor: fully dereferenced doc
deactivate Dereferencer
Processor->>Validator: validateDocument(dereferenced)
activate Validator
Validator-->>Processor: validated document
deactivate Validator
Processor-->>Client: final OpenAPI 3.1 document
else Error during step
Processor-->>Client: ProcessorError(message, step)
end
deactivate Processor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
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.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@packages/core/src/parser/processor.ts`:
- Around line 77-92: The current isEmptyInput function treats the string '[]' as
empty; instead, stop treating '[]' as a benign empty document and surface it as
malformed by throwing a ProcessorError with step 'validation' (use the existing
ProcessorError class) when input === '[]' is detected; update isEmptyInput (or
the caller that currently relies on it) to throw new ProcessorError('Invalid
OpenAPI document: array literal "[]" is not a valid document', 'validation')
rather than returning true, or if you intentionally want to accept it add a
brief inline comment explaining why '[]' is treated as empty.
- Around line 121-128: The function processOpenApiDocument currently accepts and
handles undefined/null but its parameter type is declared as string |
Record<string, unknown>; update the function signature to include null and
undefined (e.g., input: string | Record<string, unknown> | null | undefined) so
the type matches runtime behavior, and adjust any exported types or callers that
rely on the old signature (search for processOpenApiDocument references) to
ensure callers compile with the new union type.
- Extract pipeline steps into helper functions (bundleDocument, upgradeDocument, dereferenceDocument) - Add DRY helpers: getErrorMessage, isValidObject - Document security considerations for SSRF and file read risks - Document basePath option as reserved for future use - Export ProcessorStep type for better type safety - Update TECHNICAL-SPECIFICATION.md with ProcessorError.step signature - Add 8 new tests for edge cases and error paths Cognitive complexity reduced from 22 to within allowed limits. Closes: vite-open-api-server-z5y.7
- Throw ProcessorError for array literal '[]' instead of treating as empty (arrays are not valid OpenAPI documents) - Update function signature to include null | undefined in input type to match runtime behavior - Update tests to use new signature without type assertions - Add test for '[]' validation error with step='validation'
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/core/src/parser/processor.ts`:
- Around line 119-141: In isEmptyInput, arrays should be treated as invalid
OpenAPI documents, not as empty objects: add an Array.isArray(input) check
(before the typeof input === 'object' branch) and throw a ProcessorError with a
validation type (e.g., 'Invalid OpenAPI document: array literal is not a valid
document') similar to the existing '[]' string case so array inputs do not fall
through and return a minimal doc.
| function isEmptyInput(input: string | Record<string, unknown> | undefined | null): boolean { | ||
| if (!input) { | ||
| return true; | ||
| } | ||
|
|
||
| if (typeof input === 'string') { | ||
| const trimmed = input.trim(); | ||
|
|
||
| // Array literals are not valid OpenAPI documents - throw validation error | ||
| if (trimmed === '[]') { | ||
| throw new ProcessorError( | ||
| 'Invalid OpenAPI document: array literal "[]" is not a valid document', | ||
| 'validation', | ||
| ); | ||
| } | ||
|
|
||
| // Empty string or empty object literal treated as empty input | ||
| return trimmed === '' || trimmed === '{}'; | ||
| } | ||
|
|
||
| if (typeof input === 'object') { | ||
| return Object.keys(input).length === 0; | ||
| } |
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.
Treat array inputs as invalid, not empty.
An empty array currently falls through the object branch and returns a minimal doc; arrays aren’t valid OpenAPI documents. Mirror the '[]' string handling by throwing a validation error for array inputs.
🐛 Proposed fix
function isEmptyInput(input: string | Record<string, unknown> | undefined | null): boolean {
+ if (Array.isArray(input)) {
+ throw new ProcessorError(
+ 'Invalid OpenAPI document: array input is not a valid document',
+ 'validation',
+ );
+ }
if (!input) {
return true;
}🤖 Prompt for AI Agents
In `@packages/core/src/parser/processor.ts` around lines 119 - 141, In
isEmptyInput, arrays should be treated as invalid OpenAPI documents, not as
empty objects: add an Array.isArray(input) check (before the typeof input ===
'object' branch) and throw a ProcessorError with a validation type (e.g.,
'Invalid OpenAPI document: array literal is not a valid document') similar to
the existing '[]' string case so array inputs do not fall through and return a
minimal doc.
Summary by CodeRabbit
New Features
Tests
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.