Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(oas): ignore path item properties other than http methods #243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/oas/src/converter/DefaultConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ import type {
import pointer from 'json-pointer';

export class DefaultConverter implements Converter {
private readonly ALLOWED_METHODS: readonly string[] = [
'GET',
'PUT',
'POST',
'DELETE',
'OPTIONS',
'HEAD',
'PATCH',
'TRACE'
];

private spec: OpenAPI.Document;
private securityRequirements?: SecurityRequirementsParser<OpenAPI.Document>;
private readonly refParser = new $RefParser();
Expand All @@ -39,9 +50,8 @@ export class DefaultConverter implements Converter {
return Object.entries(this.spec.paths).flatMap(
([path, pathMethods]: [string, PathItemObject]) =>
Object.keys(pathMethods)
.filter(
(method: string) =>
!method.toLowerCase().startsWith('x-swagger-router-controller')
.filter((method: string) =>
this.ALLOWED_METHODS.includes(method.toUpperCase())
)
.map((method) => this.createHarEntry(path, method))
);
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 @@ -384,5 +384,19 @@ describe('DefaultConverter', () => {
expect(result).toStrictEqual(expectedDoc);
}
);

it('should ignore properties other than http method', async () => {
// arrange
const { inputDoc, expectedDoc } = await createFixture({
inputFile: `./fixtures/path-item.ignore-non-http-method-properties.oas.yaml`,
expectedFile: `./fixtures/path-item.ignore-non-http-method-properties.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,25 @@
[
{
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
},
{
"name": "accept",
"value": "application/json"
}
],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"method": "POST",
"postData": {
"mimeType": "application/json",
"text": "{\"email\":\"[email protected]\",\"name\":\"Cristobal.Weissnat\",\"number\":\"6915656974\",\"password\":\"5hmb0gvyC__hVQg\"}"
},
"queryString": [],
"url": "http://localhost:8888/identity/api/auth/signup"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
openapi: 3.0.1
info:
title: OWASP crAPI API
version: 1-oas3
externalDocs:
description: Completely Ridiculous API (crAPI)
url: https://github.com/OWASP/crAPI
servers:
- url: http://localhost:8888
paths:
/identity/api/auth/signup:
post:
operationId: signup
summary: Sign up
description: Used to create an account
tags:
- Identity / Auth
security: []
requestBody:
content:
application/json:
schema:
type: object
required:
- email
- name
- number
- password
properties:
email:
type: string
example: [email protected]
name:
type: string
example: Cristobal.Weissnat
number:
type: string
example: '6915656974'
password:
type: string
example: 5hmb0gvyC__hVQg
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/CRAPIResponse'
description: ''
parameters: []
components:
schemas:
CRAPIResponse:
type: object
properties:
message:
type: string
status:
type: integer
format: int32
Loading