Skip to content
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

fix: add condition to check type of property before parsing from json #10582

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

aaqilniz
Copy link
Contributor

@aaqilniz aaqilniz commented Jun 26, 2024

While generating a datasource based on the REST connector, the generator works fine with prompts. But it fails to work with --config option.

The connector fails to parse the incoming option that has object type (options and operations option) as the config has already been parsed at base-generator.js.

The following works:

lb4 datasource 
? Datasource name: rest
? Select the connector for rest:  REST services (supported by StrongLoop)
? Base URL for the REST service: /sample
? Default options for the request: {"headers":{"Accept":"application/json","Content-Type":"application/json"}}
? An array of operation templates: []
? Use default CRUD mapping: No

But passing the same options as config fails:

lb4 datasource -c '{"name":"rest","connector":"rest","baseURL":"/sample","options":{"headers":{"Accept":"application/json","Content-Type":"application/json"}}, "operations":[]}' --yes

To fix this, I have added a check (to see if it is a string - hence not been parsed) before parsing the options at the datasource generator.

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@coveralls
Copy link

coveralls commented Jun 29, 2024

Pull Request Test Coverage Report for Build 9683866757

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 54.772%

Totals Coverage Status
Change from base Build 9621050209: 0.0%
Covered Lines: 9566
Relevant Lines: 12465

💛 - Coveralls

@aaqilniz aaqilniz changed the title fix: add condition to check type of property before parsing from json… fix: add condition to check type of property before parsing from json Aug 25, 2024
@aaqilniz aaqilniz marked this pull request as ready for review August 25, 2024 05:03
@dhmlau dhmlau merged commit 37d6780 into loopbackio:master Nov 7, 2024
12 of 13 checks passed
@dhmlau
Copy link
Member

dhmlau commented Nov 7, 2024

@aaqilniz, thanks for the fix. Your PR has landed! 🎉

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.

3 participants