• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

panates / opra / 25746441103

12 May 2026 04:01PM UTC coverage: 83.035% (+0.001%) from 83.034%
25746441103

push

github

erayhanoglu
1.28.1

3727 of 4805 branches covered (77.57%)

Branch coverage included in aggregate %.

33671 of 40234 relevant lines covered (83.69%)

222.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.86
/packages/common/src/document/http/http-parameter.ts
1
import { omitUndefined } from '@jsopen/objects';
1✔
2
import {
1✔
3
  asMutable,
1✔
4
  type Combine,
1✔
5
  type StrictOmit,
1✔
6
  type Type,
1✔
7
  type TypeThunkAsync,
1✔
8
} from 'ts-gems';
1✔
9
import { type Validator, vg } from 'valgen';
1✔
10
import type { OpraSchema } from '../../schema/index.js';
1✔
11
import type { ApiDocument } from '../api-document.js';
1✔
12
import { DocumentElement } from '../common/document-element.js';
1✔
13
import { Value } from '../common/value.js';
1✔
14
import { DataType } from '../data-type/data-type.js';
1✔
15
import type { EnumType } from '../data-type/enum-type.js';
1✔
16
import { parseRegExp } from '../utils/parse-regexp.util.js';
1✔
17

1✔
18
/**
1✔
19
 * @namespace HttpParameter
1✔
20
 */
1✔
21
export namespace HttpParameter {
1✔
22
  export interface Metadata extends StrictOmit<
1✔
23
    OpraSchema.HttpParameter,
1✔
24
    'type'
1✔
25
  > {
1✔
26
    name: string | RegExp;
1✔
27
    type?:
1✔
28
      | string
1✔
29
      | TypeThunkAsync
1✔
30
      | EnumType.EnumObject
1✔
31
      | EnumType.EnumArray
1✔
32
      | object;
1✔
33
    keyParam?: boolean;
1✔
34
    designType?: Type;
1✔
35
  }
1✔
36

1✔
37
  export interface Options extends Partial<StrictOmit<Metadata, 'type'>> {
1✔
38
    type?: string | TypeThunkAsync | object;
1✔
39
    parser?: (v: any) => any;
1✔
40
  }
1✔
41

1✔
42
  export interface InitArguments extends Combine<
1✔
43
    {
1✔
44
      type?: DataType;
1✔
45
    },
1✔
46
    Metadata
1✔
47
  > {
1✔
48
    parser?: (v: any) => any;
1✔
49
  }
1✔
50
}
1✔
51

1✔
52
/**
1✔
53
 * Type definition for HttpParameter
1✔
54
 * @class HttpParameter
1✔
55
 */
1✔
56
interface HttpParameterStatic {
1✔
57
  new (
1✔
58
    owner: DocumentElement,
1✔
59
    args: HttpParameter.InitArguments,
1✔
60
  ): HttpParameter;
1✔
61

1✔
62
  prototype: HttpParameter;
1✔
63
}
1✔
64

1✔
65
/**
1✔
66
 * Type definition of HttpParameter prototype
1✔
67
 * @interface HttpParameter
1✔
68
 */
1✔
69
export interface HttpParameter extends HttpParameterClass {}
1✔
70

1✔
71
export const HttpParameter = function (
1✔
72
  this: HttpParameter,
1,119✔
73
  owner: DocumentElement,
1,119✔
74
  initArgs: HttpParameter.InitArguments,
1,119✔
75
) {
1,119✔
76
  if (!this)
1,119✔
77
    throw new TypeError('"this" should be passed to call class constructor');
1,119!
78
  Value.call(this, owner, initArgs);
1,119✔
79
  const _this = asMutable(this);
1,119✔
80
  if (initArgs.name) {
1,119✔
81
    _this.name =
1,119✔
82
      initArgs.name instanceof RegExp
1,119✔
83
        ? initArgs.name
12✔
84
        : initArgs.name.startsWith('/')
1,107✔
85
          ? parseRegExp(initArgs.name, {
2✔
86
              includeFlags: 'i',
2✔
87
              excludeFlags: 'm',
2✔
88
            })
2✔
89
          : initArgs.name;
1,119✔
90
  }
1,119✔
91
  _this.location = initArgs.location;
1,119✔
92
  _this.deprecated = initArgs.deprecated;
1,119✔
93
  _this.required = initArgs.required;
1,119✔
94
  if (_this.required == null && initArgs.location === 'path')
1,119✔
95
    _this.required = true;
1,119✔
96
  _this.default = initArgs.default;
1,119✔
97
  _this.arraySeparator = initArgs.arraySeparator;
1,119✔
98
  _this.keyParam = initArgs.keyParam;
1,119✔
99
  _this.parser = initArgs.parser;
1,119✔
100
  _this.designType = initArgs.designType;
1,119✔
101
} as Function as HttpParameterStatic;
1,119✔
102

1✔
103
/**
1✔
104
 * @class HttpParameter
1✔
105
 */
1✔
106
class HttpParameterClass extends Value {
1✔
107
  declare readonly owner: DocumentElement;
1✔
108
  declare location: OpraSchema.HttpParameterLocation;
1✔
109
  declare keyParam?: boolean;
1✔
110
  declare deprecated?: boolean | string;
1✔
111
  declare required?: boolean;
1✔
112
  declare readonly default?: any;
1✔
113
  declare arraySeparator?: string;
1✔
114
  declare parser?: (v: any) => any;
1✔
115
  declare designType?: Type;
1✔
116

1✔
117
  toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpParameter {
1✔
118
    return omitUndefined<OpraSchema.HttpParameter>({
1,205✔
119
      ...super.toJSON(options),
1,205✔
120
      name: this.name,
1,205✔
121
      location: this.location,
1,205✔
122
      arraySeparator: this.arraySeparator,
1,205✔
123
      keyParam: this.keyParam,
1,205✔
124
      required: this.required,
1,205✔
125
      default: this.default,
1,205✔
126
      deprecated: this.deprecated,
1,205✔
127
    });
1,205✔
128
  }
1,205✔
129

1✔
130
  generateCodec(
1✔
131
    codec: 'encode' | 'decode',
47✔
132
    options?: DataType.GenerateCodecOptions,
47✔
133
    properties?: any,
47✔
134
  ): Validator {
47✔
135
    const fn =
47✔
136
      this.type?.generateCodec(codec, options, {
47✔
137
        ...properties,
47✔
138
        designType: this.designType,
47✔
139
      }) || vg.isAny();
47!
140
    if (this.default !== undefined) {
47!
141
      return vg.optional(fn, this.default);
×
142
    }
×
143
    return fn;
47✔
144
  }
47✔
145
}
1✔
146

1✔
147
HttpParameter.prototype = HttpParameterClass.prototype;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc