@opra/common
Version:
Opra common package
55 lines (54 loc) • 1.9 kB
JavaScript
import { omitUndefined } from '@jsopen/objects';
import { asMutable, } from 'ts-gems';
import { vg } from 'valgen';
import { Value } from '../common/value.js';
import { parseRegExp } from '../utils/parse-regexp.util.js';
export const HttpParameter = function (owner, initArgs) {
if (!this)
throw new TypeError('"this" should be passed to call class constructor');
Value.call(this, owner, initArgs);
const _this = asMutable(this);
if (initArgs.name) {
_this.name =
initArgs.name instanceof RegExp
? initArgs.name
: initArgs.name.startsWith('/')
? parseRegExp(initArgs.name, {
includeFlags: 'i',
excludeFlags: 'm',
})
: initArgs.name;
}
_this.location = initArgs.location;
_this.deprecated = initArgs.deprecated;
_this.required = initArgs.required;
if (_this.required == null && initArgs.location === 'path')
_this.required = true;
_this.arraySeparator = initArgs.arraySeparator;
_this.keyParam = initArgs.keyParam;
_this.parser = initArgs.parser;
_this.designType = initArgs.designType;
};
/**
* @class HttpParameter
*/
class HttpParameterClass extends Value {
toJSON(options) {
return omitUndefined({
...super.toJSON(options),
name: this.name,
location: this.location,
arraySeparator: this.arraySeparator,
keyParam: this.keyParam,
required: this.required,
deprecated: this.deprecated,
});
}
generateCodec(codec, options, properties) {
return (this.type?.generateCodec(codec, options, {
...properties,
designType: this.designType,
}) || vg.isAny());
}
}
HttpParameter.prototype = HttpParameterClass.prototype;