Skip to content

Commit

Permalink
fix(graphql): minor api prompt fixes (#8603)
Browse files Browse the repository at this point in the history
minor api prompt fixes
  • Loading branch information
sundersc committed Oct 31, 2021
1 parent a3bdd44 commit b9aabe2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Expand Up @@ -308,6 +308,7 @@ const serviceApiInputWalkthrough = async (context: $TSContext, defaultValuesFile
// API name question
resourceAnswers = await inquirer.prompt(resourceQuestions);
resourceAnswers[inputs[0].key] = resourceAnswers[inputs[1].key];
allDefaultValues[inputs[1].key] = resourceAnswers[inputs[1].key];
break;
case 'API_AUTH_MODE':
// Ask additonal questions
Expand Down Expand Up @@ -832,7 +833,13 @@ export async function askApiKeyQuestions(authSettings = undefined) {
default: defaultValues.apiKeyExpirationDays,
validate: validateDays,
// adding filter to ensure parsing input as int -> https://github.com/SBoudrias/Inquirer.js/issues/866
filter: value => (isNaN(parseInt(value, 10)) ? value : parseInt(value, 10)),
filter: value => {
const val = parseInt(value, 10);
if (isNaN(val) || val <= 0 || val > 365) {
return value;
}
return val;
},
},
];

Expand Down Expand Up @@ -900,8 +907,8 @@ async function askOpenIDConnectQuestions(authSettings) {
};
}

function validateDays(input) {
const isValid = /^\d+$/.test(input);
async function validateDays(input) {
const isValid = /^\d{0,3}$/.test(input);
const days = isValid ? parseInt(input, 10) : 0;
if (!isValid || days < 1 || days > 365) {
return 'Number of days must be between 1 and 365.';
Expand Down
Expand Up @@ -18,8 +18,8 @@ export const supportedServices = {
question: 'Provide API name:',
validation: {
operator: 'regex',
value: '^[a-zA-Z0-9]+$',
onErrorMsg: 'You can use the following characters: a-z A-Z 0-9',
value: '^[a-zA-Z0-9]{1,80}$',
onErrorMsg: 'You can use the following characters: a-z A-Z 0-9 with maximum length of 80',
},
required: true,
},
Expand Down

0 comments on commit b9aabe2

Please sign in to comment.