MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / param

Function param

packages/openapi-v3/src/decorators/parameter.decorator.ts:39–84  ·  view source on GitHub ↗
(paramSpec: ParameterObject)

Source from the content-addressed store, hash-verified

37 * @param paramSpec - Parameter specification.
38 */
39export function param(paramSpec: ParameterObject) {
40 return function (target: object, member: string, index: number) {
41 paramSpec = {...paramSpec};
42 // Get the design time method parameter metadata
43 const methodSig = MetadataInspector.getDesignTypeForMethod(target, member);
44 const paramTypes = methodSig?.parameterTypes || [];
45
46 // Map design-time parameter type to the OpenAPI param type
47
48 const paramType = paramTypes[index];
49
50 if (paramType) {
51 if (
52 // generate schema if `paramSpec` doesn't have it
53 !paramSpec.schema ||
54 // generate schema if `paramSpec` has `schema` but without `type`
55 (isSchemaObject(paramSpec.schema) && !paramSpec.schema.type)
56 ) {
57 // If content explicitly mentioned do not resolve schema
58 if (!paramSpec.content) {
59 // please note `resolveSchema` only adds `type` and `format` for `schema`
60 paramSpec.schema = resolveSchema(paramType, paramSpec.schema);
61 }
62 }
63 }
64
65 if (
66 paramSpec.schema &&
67 isSchemaObject(paramSpec.schema) &&
68 paramSpec.schema.type === 'array'
69 ) {
70 // The design-time type is `Object` for `any`
71 if (paramType != null && paramType !== Object && paramType !== Array) {
72 throw new Error(
73 `The parameter type is set to 'array' but the JavaScript type is ${paramType.name}`,
74 );
75 }
76 }
77
78 ParameterDecoratorFactory.createDecorator<ParameterObject>(
79 OAI3Keys.PARAMETERS_KEY,
80 paramSpec,
81 {decoratorName: '@param'},
82 )(target, member, index);
83 };
84}
85
86/**
87 * The `type` and `format` inferred by a common name of OpenAPI 3.0.0 data type

Callers 10

findByIdMethod · 0.85
updateByIdMethod · 0.85
replaceByIdMethod · 0.85
deleteByIdMethod · 0.85
arrayFunction · 0.85
createParamShortcutFunction · 0.85
fooMethod · 0.85
greetMethod · 0.85
updateMethod · 0.85

Calls 3

resolveSchemaFunction · 0.90
createDecoratorMethod · 0.45

Tested by 3

fooMethod · 0.68
greetMethod · 0.68
updateMethod · 0.68