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

Add Default Value Option #216

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

mhkhoraidah
Copy link

@mhkhoraidah mhkhoraidah commented Apr 26, 2022

You can add a default value by using 'default:' with single value.

For example: default:ITEM_ID

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Test
  • Docs
  • Refactor
  • Build-related changes
  • Other, please describe:

Description: default value example \examples\parameters\default.js and add run command 'npm run parameters:default'

You can add a default value by using 'default:' with single value.

For example: `default:ITEM_ID`
@sonarcloud
Copy link

sonarcloud bot commented Apr 26, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@kevinccbsg
Copy link
Member

Hi @mhkhoraidah sorry for the delayed response but this PR does not pass the tests so we could not merge it. I really like the change but we cannot merge it 😅

const addEnumValues = require('../utils/enumValues');
const { refSchema, formatRefSchema } = require('../utils/refSchema');

const getSchema = (entity, message) => (type, enumValues = [], jsonOptions = {}) => {
const getSchema = (entity, message) => (type, defaultValue = '', enumValues = [], jsonOptions = {}) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add a default value for this property: it should be optional and, therefore, remain as undefined if not specified.

Also, depending on the type, an empty string wouldn't always make sense. On a numeric field, for example, we may want need to use a zero or something else, as an empty string could be considered a NaN value. For boolean fields, a default of true or false would make more sense. These are just examples, but this is to illustrate that we should not use an empty string as a default for every field.

@@ -0,0 +1,5 @@
const addDefaultValue = (value = '') => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the same reasons mentioned in the comment above, this default value should be removed.

This default value is the reason why tests are failing: with the current code, we're always appending { default: '' } to every property, even if no default value has been specified for it in the docs.

image

@LonelyPrincess LonelyPrincess added enhancement New feature or request Chore Project setup labels May 19, 2022
@sonarcloud
Copy link

sonarcloud bot commented Aug 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chore Project setup enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants