Skip to content

feat: Fallback to an alternate string if operationId is undefined. #139

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

Merged
merged 3 commits into from
Jun 30, 2025

Conversation

Himenon
Copy link
Owner

@Himenon Himenon commented Jun 30, 2025

Summary

It will allow code to be generated even for schemas like the following.

  /undefined/operation/:id:
    get:
      # operationId: getUndefinedOperation
      responses:
        200:
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Undefined operation response

Test Plan

Updated snapshot test

@Himenon Himenon changed the title feat: Fall back to an alternate string if operationId is undefined. feat: Fallback to an alternate string if operationId is undefined. Jun 30, 2025
@Himenon Himenon requested a review from Copilot June 30, 2025 03:15
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 adds fallback operationId generation for OpenAPI operations missing an operationId, updates the core generator to apply this mapping, and refreshes tests/snapshots accordingly.

  • Introduces generateValidRootSchema to assign synthetic operationIds based on method and path
  • Integrates the fallback logic into src/index.ts before 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 operationId uses 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 consistent operationId values.
        operation.operationId = `${method.toLowerCase()}${path.charAt(0).toUpperCase() + path.slice(1)}`;

@Himenon Himenon merged commit 35b9d6c into main Jun 30, 2025
2 checks passed
@Himenon Himenon deleted the feat/fallback-operaion-id branch June 30, 2025 03:16
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