How to disable swagger validation in net core - asp.net-core

I'm looking for a way to disable the swagger validation feature when using Swashbuckle for a net core web api project. More precisely how can I set the ValidatorUrl to null.

I have found that it is not disabled by default. I am running Swashbuckle.AspNetCore v1.1.0 and .net core 2.0. I have tried the following which DOESN'T WORK
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "MY API");
c.EnabledValidator(null);
});
The only solution that I have found is to modify their swagger-ui.js file. I don't like this solution but it works.
Around line 198 you will see the following:
return " <span style=\"float:right\"><a target=\"_blank\" href=\""
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.validatorUrl : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
+ "/debug?url="
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.url : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
+ "\"><img id=\"validator\" src=\""
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.validatorUrl : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
+ "?url="
+ ((stack1 = (helpers.escape || (depth0 && depth0.escape) || alias2).call(alias1,(depth0 != null ? depth0.url : depth0),{"name":"escape","hash":{},"data":data})) != null ? stack1 : "")
+ "\"></a>\n </span>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {};
I removed their anchor tag and it now looks like this:
return " <span style=\"float:right\"></span>\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {};

Related

GSheets Multi-Select Dropdown affects entire worksheet instead of a specific sheet

I am new to this and I found an old post with this code. I am currently using it but it affects all tabs of my spreadsheet. Is there a way for it to work on a specific tab only? Thank you.
`const separator = ', ';
const dvType = SpreadsheetApp.DataValidationCriteria.VALUE_IN_RANGE;
function onEdit(e) {
if (e.value != null && e.oldValue != null && e.value !== "") {
var dataValidation = e.range.getDataValidation();
if(dataValidation != null && dataValidation.getCriteriaType() == dvType &&
e.value.indexOf(separator) < 0 && e.oldValue.indexOf(e.value) < 0) {
e.range.setValue(e.oldValue + separator + e.value);
}
}
}`
I tried to change the criteria but since I am new to coding, I always get error.

How can I find the city with spaces or accents like in the documentation geo.api.gouv using vuejs and axios?

I use this API :
https://geo.api.gouv.fr/decoupage-administratif/communes
It works really good but the problem is that if I'm searching a city (commune) like : "Saint-Étienne" I have to write exactly "Saint-Étienne". I would like to find this city for example without space : "saint étienne" or accent : "saint etienne".
In the documentation it's good.
But in my project in Vue.Js with Axios I can't find solutions. The v-select needs the exact writing.
Here is the input :
<v-autocomplete
v-else
#input="inputCity('departureCity', 'departureDepartment', selectedArrayCityDeparture)"
:loading="loading"
:items="citiesDeparture"
:search-input.sync="searchCitiesDeparture"
v-model="selectedArrayCityDeparture"
:rules="[
(value) => searchCitiesDeparture !== null || $t('form.validation.theDepartureCity') + ' ' + $t('isRequired')
]"
text
hide-no-data’
required
:label="$t('form.departureCity')"
:no-data-text="$t('noDataAvailable')"
/>
methods :
inputCity(cityType, departmentType, index) {
if (index !== null && this.responseCities[index] !== undefined) {
this.form[cityType] = this.responseCities[index].nom;
this.form[departmentType] = this.responseCities[index].codeDepartement;
}
},
querySelections(q, cities) {
this.$axios.get(this.apiRoutes.gouv.cities(q)).then(
response => {
this.loading = false;
this[cities] = _.map(response.data, function (item, i) {
return ({ text: item.nom + ' (' + item.codeDepartement + ')' , value: i });
});
this.responseCities = response.data;
}
)
},
watch :
search (val) {
val && val !== this.select && this.querySelections(val)
},
searchCitiesArrival(val) {
if (val !== null && val !== undefined && val.length > 1 && !(this.selectedArrayCityArrival !== null && this.citiesArrival[this.selectedArrayCityArrival] !== undefined && this.citiesArrival[this.selectedArrayCityArrival].text === val)) {
this.querySelections(val, "citiesArrival");
}
},
searchCitiesDeparture(val) {
if (val !== null && val !== undefined && val.length > 1 && !(this.selectedArrayCityDeparture !== null && this.citiesDeparture[this.selectedArrayCityDeparture] !== undefined && this.citiesDeparture[this.selectedArrayCityDeparture].text === val)) {
this.querySelections(val, "citiesDeparture");
}
}
data :
citiesDeparture: [],
citiesArrival: [],
responseCities: [],
call Api :
gouv: {
cities: function (name) {
return ('https://geo.api.gouv.fr/communes?nom=' + name + '&fields=&format=json&geometry=centre"');
}
},
How can I find the city with spaces or accents like in the documentation ?

TypeError can be thrown as "key" might be null or undefined here in SonarQube

In JQuery Library jquery-1.4.1-vsdoc.js, Following is the code block :
jQuery.fn.extend({
data: function( key, value ) {
if ( typeof key === "undefined" && this.length ) {
return jQuery.data( this[0] );
} else if ( typeof key === "object" ) {
return this.each(function() {
jQuery.data( this, key );
});
}
var parts = key.split(".");
parts[1] = parts[1] ? "." + parts[1] : "";
thought there is no problem at all but SonarQube gives me a critical error:
TypeError can be thrown as "key" might be null or undefined here.
The word key in key.split(".") is highlighted. Indicating variable key can be undefined/null here.
Please suggest how to resolve this issue. SonarQube Build Number is Version 6.3 (build 19869)
I have this issue previously, Here the issue is you are only checking for undefined.
You ave to check both undefined & null.
Like this
if( key !== undefined && key !== null){
var parts = key.split(".");
parts[1] = parts[1] ? "." + parts[1] : "";
}
I think it will be helpful

New Aurelia Validation ! equals(expectedValue)

The old way:
this.validator = this.validation.on(this)
.ensure('baseContent.RedirectFrom')
.isNotEmpty()
.ensure('baseContent.RedirectTo')
.isNotEmpty()
.isNotEqualTo(() => { return this.baseContent.RedirectFrom }, 'Redirect from');
});
isNotEquals doesn't seem to exist in the new validation there is a equals(expectedValue)
I have considered doing a custom validation element however struggled as it passed through 'RedirectFrom' as undefined.
ValidationRules.customRule('notEqualTo',
(value, obj, otherValue) => {
return value === null || value === undefined || value === '' || otherValue === null || otherValue === undefined || otherValue === ''|| value === otherValue;
},
"must not match");
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', this.baseContent.RedirectFrom)
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', this.RedirectFrom)
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', RedirectFrom)
Anyone see anything I'm missing?
obj[propertyName]
CustomValidation.js
ValidationRules.customRule('mustNotMatchValue',
(value, obj, valueToNotMatch) => {
return value === null || value === undefined || value === '' || obj[valueToNotMatch] === null || obj[valueToNotMatch] === undefined || obj[valueToNotMatch] === '' || value !== obj[valueToNotMatch];
},
"must not match ${$config.valueToNotMatch}",
(valueToNotMatch) => ({ valueToNotMatch }));
baseContent.js
.ensure('RedirectTo').required().satisfiesRule('mustNotMatchValue', 'RedirectFrom');

Format Textbox input for phone number MVC

I am simply using a #Html.TextBoxFor(m => m.PhoneNumber, new { id = "phoneNo")
I am using a regex to limit it to 10 numbers only.
Is there a way I can format the textbox to appear like (555) 444-3333 while they type, but in the model it will simply be passing the 10 numbers, like 5554443333? I meant to automatically create those brackets and - while also checking using regex if they entered 10 numbers?
You can do it with jquery as Matt said at his comment, stated at this question of the site:
Phone mask with jQuery and Masked Input Plugin
Or with plain javascript, as explained by xxx here with alternatives too:
Mask US phone number string with JavaScript
List of alternatives coded for a example input called "phone":
Example code with plain javaScript:
document.getElementById('phone').addEventListener('input', function (e) {
var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
});
Example code with jQuery but without adding any new dependence():
$('#phone', '#example-form')
.keydown(function (e) {
var key = e.which || e.charCode || e.keyCode || 0;
$phone = $(this);
// Don't let them remove the starting '('
if ($phone.val().length === 1 && (key === 8 || key === 46)) {
$phone.val('(');
return false;
}
// Reset if they highlight and type over first char.
else if ($phone.val().charAt(0) !== '(') {
$phone.val('('+$phone.val());
}
// Auto-format- do not expose the mask as the user begins to type
if (key !== 8 && key !== 9) {
if ($phone.val().length === 4) {
$phone.val($phone.val() + ')');
}
if ($phone.val().length === 5) {
$phone.val($phone.val() + ' ');
}
if ($phone.val().length === 9) {
$phone.val($phone.val() + '-');
}
}
// Allow numeric (and tab, backspace, delete) keys only
return (key == 8 ||
key == 9 ||
key == 46 ||
(key >= 48 && key <= 57) ||
(key >= 96 && key <= 105));
})
.bind('focus click', function () {
$phone = $(this);
if ($phone.val().length === 0) {
$phone.val('(');
}
else {
var val = $phone.val();
$phone.val('').val(val); // Ensure cursor remains at the end
}
})
.blur(function () {
$phone = $(this);
if ($phone.val() === '(') {
$phone.val('');
}
});
Example code with jQuery using Masked Input Plugin:
$("#phone").mask("(99) 9999?9-9999");
$("#phone").on("blur", function() {
var last = $(this).val().substr( $(this).val().indexOf("-") + 1 );
if( last.length == 3 ) {
var move = $(this).val().substr( $(this).val().indexOf("-") - 1, 1 );
var lastfour = move + last;
var first = $(this).val().substr( 0, 9 );
$(this).val( first + '-' + lastfour );
}
});