Repository navigation
fix(cli): pass the controller's own argument names to the service - #11938
Open
sarankumar1325 wants to merge 1 commit into
Open
sarankumar1325 wants to merge 1 commit into
sarankumar1325 wants to merge 1 commit into
Conversation
The generated controller implementation passed each OpenAPI parameter by its spec name, so a name that is not a valid identifier (pet-id, or the reserved word if) produced code that does not compile, while the method signature declares the escaped name (petId, _if). Pass the names the signature declares, including the request body's. Fixes loopbackio#11937 Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This branch has not been deployed
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.
Fixes #11937
lb4 openapi --clientwrites a controller method that passes each OpenAPI parameter to the service by its spec name (param.name). The method signature declares the escaped name instead (escapeIdentifier, theargNameofbuildParameter). So a name that isn't a valid identifier gives code that doesn't compile:pet-id→getPet(pet-id)while the argument ispetId.if→getCustomers(if, …)while the argument is_if.The request body was passed as a hard-coded
_requestBody. That happens to equal the escaped body name today.buildMethodSpecnow records the argument names as it builds the signature, including the body's. The implementation passes those, so it always matches what the method declares.Tests:
test/unit/openapi/spec-helper.unit.js: two newgenerateControllerSpecstests. The hyphenatedpet-idgivesgetPet(petId); it fails without the fix withgetPet(pet-id). A query parameter plus a request body givesgetPet(limit, _requestBody).snapshots/unit/openapi/controller-spec.unit.snapshots.js: thecustomer.yamlfixture's snapshot recorded the broken output. It changes in two strings only:getCustomers(if, limit, access-token)becomesgetCustomers(_if, limit, accessToken), andcreateCustomer(access-token, _requestBody)becomescreateCustomer(accessToken, _requestBody). I regenerated it withUPDATE_SNAPSHOTS=1and checked that nothing else in the file changed.test/fixtures/openapiand compared the output. Only those two implementations differ, so theopenapi-clientintegration snapshots (petstore) are unchanged.mocha test/unit/openapi/*.unit.js: 48 passing. One failure, the uspto "schema to model"before allhook, also fails onmasterin my checkout. I installed onlypackages/cli, not the whole monorepo.Checklist
npm testpasses on your machine (unit tests for the openapi generator only; see above)packages/cliwere updatedexamples/*were updatedI wrote this with an AI assistant and checked the change and the tests myself.