-
Notifications
You must be signed in to change notification settings - Fork 18
test(oas3): add server variables object validation #440
Conversation
|
|
||
| // if you define a variable that is not in URL it warns (and the variable is discarded). | ||
| variablesKeys.forEach((key) => { | ||
| if (urlVariables.indexOf(key) === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (urlVariables.indexOf(key) === -1) { | |
| if (!urlVariables.includes(key)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
| variablesKeys.forEach((key) => { | ||
| if (urlVariables.indexOf(key) === -1) { | ||
| parseResult.push(createWarning(context.namespace, | ||
| `Server variable '${key}' is not present in the URL and will be discarted`, variables)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `Server variable '${key}' is not present in the URL and will be discarted`, variables)); | |
| `Server variable '${key}' is not present in the URL and will be ignored`, variables)); |
discarted has a typo, but instead I think "ignored" sounds a little better here. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can put ignored, however, as the variable is taken away, discarded may make the idea clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyway it has been replaced
| const name = 'Server Object'; | ||
| const requiredKeys = ['url']; | ||
|
|
||
| const validateVariableInURL = (context, object) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const validateVariableInURL = (context, object) => { | |
| const validateVariablesInURL = (context, object) => { |
I'd make variable plural in the method name as we're validating a set of variables not singular variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good, change on next commit
| .map(x => x.replace(/[{}]/g, '')); | ||
|
|
||
| // if you define a variable that is not in URL it warns (and the variable is discarded). | ||
| variablesKeys.forEach((key) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| variablesKeys.forEach((key) => { | |
| variables.keys().forEach((key) => { |
There's a method for this already so you can delete the above const variablesKeys = variables.content.map(variable => variable.key.toValue());.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, changed
| urlVariables.forEach((key) => { | ||
| if (!variables.hasKey(key)) { | ||
| parseResult.push(createWarning(context.namespace, | ||
| `URL variable '${key}' is missing within the server variables`, variables)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `URL variable '${key}' is missing within the server variables`, variables)); | |
| `URL variable '${key}' is missing within the server variables`, object.get('url'))); |
I think we want to use the URL here to create the warning, because the source map for the warning should originate from the URL which contains the variable which isn't defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see, changed
4dccd1c to
a39f634
Compare
|
@kylef merge? |
Closes APIARY-6482