Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix_#250/support-po…
Browse files Browse the repository at this point in the history
…stman-2.0.0-auth
  • Loading branch information
ostridm committed Aug 22, 2024
2 parents 8bc4c2a + ce551fe commit bec2312
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/oas/src/utils/params.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import type { ParameterObject } from '../types';
import { ParameterObject } from '../types';
import { getOperation } from './operation';
import type { OpenAPI } from '@har-sdk/core';
import { OpenAPI } from '@har-sdk/core';

const assertDereferencedParam = (param: unknown): param is ParameterObject => {
const isReference = !!param && typeof param === 'object' && '$ref' in param;

if (isReference) {
throw new Error('Specification document is expected to be dereferenced.');
}

return !isReference;
};

export const getParameters = (
spec: OpenAPI.Document,
path: string,
method: string
): ParameterObject[] => {
const pathObj = getOperation(spec, path, method);
const params = [
...(spec.paths[path]?.parameters ?? []),
...(getOperation(spec, path, method)?.parameters ?? [])
].filter(assertDereferencedParam);

const combinedParams = new Map<string, ParameterObject>(
params.map((x) => [`${x.in}:${x.name}`, x])
);

return Array.isArray(pathObj.parameters)
? (pathObj.parameters as ParameterObject[])
: [];
return [...combinedParams.values()];
};

export const filterLocationParams = (
Expand Down
14 changes: 14 additions & 0 deletions packages/oas/tests/DefaultConverter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,19 @@ describe('DefaultConverter', () => {
// assert
expect(result).toStrictEqual(expectedDoc);
});

it('should correctly resolve path-item parameters', async () => {
// arrange
const { inputDoc, expectedDoc } = await createFixture({
inputFile: `./fixtures/path-item.params.resolution.oas.yaml`,
expectedFile: `./fixtures/path-item.params.resolution.oas.result.json`
});

// act
const result: Request[] = await oas2har(inputDoc as any);

// assert
expect(result).toStrictEqual(expectedDoc);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"bodySize": 0,
"cookies": [],
"headers": [],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [],
"url": "https://brokencrystals.com/org/lorem/users/42/devices/42"
}
]
38 changes: 38 additions & 0 deletions packages/oas/tests/fixtures/path-item.params.resolution.oas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
openapi: 3.0.3
info:
title: users/{id}
version: '1.0'
servers:
- url: https://brokencrystals.com
paths:
/org/{orgId}/users/{userId}/devices/{deviceId}:
parameters:
- $ref: '#/components/parameters/orgId'
- in: path
name: userId
required: true
schema:
type: string
get:
parameters:
- in: path
name: userId
required: true
schema:
type: number
- in: path
name: deviceId
required: true
schema:
type: number
responses:
'200':
description: ''
components:
parameters:
orgId:
in: path
name: orgId
required: true
schema:
type: string

0 comments on commit bec2312

Please sign in to comment.