@vida-global/core 2.3.5 → 2.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -216,7 +216,7 @@ class ApiDocGenerator {
216
216
 
217
217
 
218
218
  get endpoint() {
219
- return this.#action.path.replace(/:([^/]+)/g, '{$1}');
219
+ return this.#action.path.replace(/:([^/?]+)\??/g, '{$1}');
220
220
  }
221
221
 
222
222
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vida-global/core",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "description": "Core libraries for supporting Vida development",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -70,6 +70,15 @@ describe('ApiDocGenerator', () => {
70
70
  expect(generator.endpoint).toEqual(formattedUrl);
71
71
  });
72
72
 
73
+ it ('removes the Express optional marker from a path parameter', () => {
74
+ const requiredName = Faker.Text.randomString();
75
+ const optionalName = Faker.Text.randomString();
76
+ const action = { path: `/things/:${requiredName}/:${optionalName}?` };
77
+ const generator = new ApiDocGenerator(action, ControllerClass);
78
+
79
+ expect(generator.endpoint).toEqual(`/things/{${requiredName}}/{${optionalName}}`);
80
+ });
81
+
73
82
  it ('returns the path unchanged when there are no params', () => {
74
83
  const path = `/${Faker.Text.randomString()}/${Faker.Text.randomString()}`;
75
84
  const action = { path };
@@ -157,6 +166,25 @@ describe('ApiDocGenerator', () => {
157
166
  expect(generator.pathParams.id.required).toBe(true);
158
167
  });
159
168
 
169
+ it ('uses the validator definition for an optional Express path parameter', () => {
170
+ const parameterName = Faker.Text.randomString();
171
+ const description = Faker.Text.randomString();
172
+ const action = { action: 'getRecord', method: 'GET', path: `/things/:${parameterName}?` };
173
+ ControllerClass.parametersForAction.mockReturnValue({
174
+ [parameterName]: { isString: true, optional: true, description },
175
+ });
176
+ const generator = new ApiDocGenerator(action, ControllerClass);
177
+
178
+ expect(generator.pathParams[parameterName]).toEqual({
179
+ name: parameterName,
180
+ in: 'path',
181
+ required: true,
182
+ description,
183
+ schema: { type: 'string' },
184
+ });
185
+ expect(generator.pathParams[`${parameterName}?`]).toBeUndefined();
186
+ });
187
+
160
188
  it ('excludes parameters that are not in the path', () => {
161
189
  const action = { action: 'getRecord', method: 'GET', path: '/user/:id' };
162
190
  ControllerClass.parametersForAction.mockReturnValue({
@@ -214,6 +242,17 @@ describe('ApiDocGenerator', () => {
214
242
  expect(Object.keys(generator.queryParams)).toEqual(['detail']);
215
243
  });
216
244
 
245
+ it ('does not duplicate an optional Express path parameter as a query parameter', () => {
246
+ const parameterName = Faker.Text.randomString();
247
+ const action = { action: 'getRecord', method: 'GET', path: `/things/:${parameterName}?` };
248
+ ControllerClass.parametersForAction.mockReturnValue({
249
+ [parameterName]: { isString: true, optional: true },
250
+ });
251
+ const generator = new ApiDocGenerator(action, ControllerClass);
252
+
253
+ expect(generator.queryParams[parameterName]).toBeUndefined();
254
+ });
255
+
217
256
  });
218
257
 
219
258