Skip to content

Commit

Permalink
feat(oas): address pr comments
Browse files Browse the repository at this point in the history
closes #253
  • Loading branch information
ostridm committed Oct 7, 2024
1 parent 935e7a5 commit 0e4f426
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
10 changes: 10 additions & 0 deletions packages/oas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ console.log(requests);

Notice the `includeVendorExamples` option affects Swagger specifications only.

Some specifications may have configuration for `Accept` header value in request parameters section. The automatically inferred `Accept` header values may be skipped, to skip these inferred values in output use the `oas2har` function as follows:

```js
import schema from './swagger.json' assert { type: 'json' };
import { oas2har } from '@har-sdk/oas';

const requests = await oas2har(schema, { skipAcceptHeaderInference: true });
console.log(requests);
```

## License

Copyright © 2023 [Bright Security](https://brightsec.com/).
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/src/converter/Converter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OpenAPI, Request } from '@har-sdk/core';

export interface ConverterOptions {
omitInferringAcceptHeadersInFavorOfParams?: boolean;
skipAcceptHeaderInference?: boolean;
}

export interface Converter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export abstract class HeadersConverter<T extends OpenAPI.Document>
const paramsHeaders = this.parseFromParams(path, method);

const addInferred =
!this.options.omitInferringAcceptHeadersInFavorOfParams ||
!this.options.skipAcceptHeaderInference ||
!paramsHeaders.some((x) => x.name === 'accept');

headers.push(...(addInferred ? acceptHeaders : []), ...paramsHeaders);
Expand Down
2 changes: 1 addition & 1 deletion packages/oas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const oas2har = (
collection: OpenAPI.Document,
options: {
includeVendorExamples?: boolean;
omitInferringAcceptHeadersInFavorOfParams?: boolean;
skipAcceptHeaderInference?: boolean;
} = {}
): Promise<Request[]> => {
if (!collection) {
Expand Down
8 changes: 4 additions & 4 deletions packages/oas/tests/DefaultConverter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,16 @@ describe('DefaultConverter', () => {
expect(result).toStrictEqual(expectedDoc);
});

it('should omit the inferring of accept headers when accept header comes from parameters', async () => {
it('should skip accept header inference when it comes from parameters', async () => {
// arrange
const { inputDoc, expectedDoc } = await createFixture({
inputFile: `./fixtures/params-header.omit-inferring.oas.yaml`,
expectedFile: `./fixtures/params-header.omit-inferring.oas.result.json`
inputFile: `./fixtures/params-header.skip-inference.oas.yaml`,
expectedFile: `./fixtures/params-header.skip-inference.oas.result.json`
});

// act
const result: Request[] = await oas2har(inputDoc as any, {
omitInferringAcceptHeadersInFavorOfParams: true
skipAcceptHeaderInference: true
});

// assert
Expand Down

0 comments on commit 0e4f426

Please sign in to comment.