feat: Fallback to an alternate string if operationId is undefined.#139
Merged
feat: Fallback to an alternate string if operationId is undefined.#139
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds fallback operationId generation for OpenAPI operations missing an operationId, updates the core generator to apply this mapping, and refreshes tests/snapshots accordingly.
- Introduces
generateValidRootSchemato assign syntheticoperationIds based on method and path - Integrates the fallback logic into
src/index.tsbefore code generation - Updates YAML fixture and Jest snapshots to reflect new operations and updated snapshot header URL
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/api.v2.domain/index.yml | Added a path without an explicit operationId |
| test/tests/functional/__snapshots/typedef-with-template-test.ts.snap | Updated snapshot header URL and added generated types for the new operation |
| test/tests/class/__snapshots/typedef-with-template-test.ts.snap | Same snapshot updates for the class-based client |
| src/index.ts | Imported and applied generateValidRootSchema |
| src/generateValidRootSchema.ts | New utility to assign fallback operationId values |
Comments suppressed due to low confidence (2)
src/generateValidRootSchema.ts:7
- [nitpick] Rephrase the comment to follow project comment conventions and be more descriptive, e.g.,
Assign fallback operationId for operations without one.
/** update undefined operation id */
src/generateValidRootSchema.ts:28
- The fallback
operationIduses raw path characters (slashes, colons), which leads to generated names with$tokens. Consider sanitizing the path—replacing non-alphanumeric characters with separators or underscores—to produce cleaner, more consistentoperationIdvalues.
operation.operationId = `${method.toLowerCase()}${path.charAt(0).toUpperCase() + path.slice(1)}`;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
It will allow code to be generated even for schemas like the following.
Test Plan
Updated snapshot test