From 734a4beb1e4dd05314bdcebd81bedc6f8b3d57c4 Mon Sep 17 00:00:00 2001 From: JonLuca DeCaro Date: Sun, 21 Apr 2024 13:22:20 -0700 Subject: [PATCH] working directory tests --- lib/index.ts | 106 ++++--- test/specs/working-directory/api/example.yaml | 276 ++++++++++++++++++ .../components/examples/lorem_ipsum.yaml | 1 + .../components/parameters/Correlation.yaml | 9 + .../common/components/parameters/Tenant.yaml | 9 + .../common/components/parameters/User.yaml | 7 + .../common/components/responses/200.yaml | 12 + .../common/components/responses/201.yaml | 2 + .../common/components/responses/204.yaml | 2 + .../common/components/responses/400.yaml | 5 + .../common/components/responses/401.yaml | 6 + .../common/components/responses/403.yaml | 6 + .../common/components/responses/404.yaml | 4 + .../common/components/responses/409.yaml | 2 + .../common/components/responses/422.yaml | 6 + .../schemas/AuthenticationErrorModel.yaml | 10 + .../components/schemas/HealthModel.yaml | 17 ++ .../common/components/schemas/PagedQuery.yaml | 18 ++ .../schemas/ValidationErrorModel.yaml | 21 ++ .../security-schemes/bearer-token.yaml | 3 + .../common/paths/health.yaml | 20 ++ .../common/paths/metrics.yaml | 16 + .../nested/working-dir.spec.ts | 29 ++ 23 files changed, 539 insertions(+), 48 deletions(-) create mode 100644 test/specs/working-directory/api/example.yaml create mode 100644 test/specs/working-directory/common/components/examples/lorem_ipsum.yaml create mode 100644 test/specs/working-directory/common/components/parameters/Correlation.yaml create mode 100644 test/specs/working-directory/common/components/parameters/Tenant.yaml create mode 100644 test/specs/working-directory/common/components/parameters/User.yaml create mode 100644 test/specs/working-directory/common/components/responses/200.yaml create mode 100644 test/specs/working-directory/common/components/responses/201.yaml create mode 100644 test/specs/working-directory/common/components/responses/204.yaml create mode 100644 test/specs/working-directory/common/components/responses/400.yaml create mode 100644 test/specs/working-directory/common/components/responses/401.yaml create mode 100644 test/specs/working-directory/common/components/responses/403.yaml create mode 100644 test/specs/working-directory/common/components/responses/404.yaml create mode 100644 test/specs/working-directory/common/components/responses/409.yaml create mode 100644 test/specs/working-directory/common/components/responses/422.yaml create mode 100644 test/specs/working-directory/common/components/schemas/AuthenticationErrorModel.yaml create mode 100644 test/specs/working-directory/common/components/schemas/HealthModel.yaml create mode 100644 test/specs/working-directory/common/components/schemas/PagedQuery.yaml create mode 100644 test/specs/working-directory/common/components/schemas/ValidationErrorModel.yaml create mode 100644 test/specs/working-directory/common/components/security-schemes/bearer-token.yaml create mode 100644 test/specs/working-directory/common/paths/health.yaml create mode 100644 test/specs/working-directory/common/paths/metrics.yaml create mode 100644 test/specs/working-directory/nested/working-dir.spec.ts diff --git a/lib/index.ts b/lib/index.ts index 4542506c..e5d6c3a4 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -65,12 +65,12 @@ export class $RefParser; - public parse(schema: S | string, callback: SchemaCallback): Promise; - public parse(schema: S | string, options: O): Promise; - public parse(schema: S | string, options: O, callback: SchemaCallback): Promise; - public parse(baseUrl: string, schema: S | string, options: O): Promise; - public parse(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback): Promise; + public parse(schema: S | string | unknown): Promise; + public parse(schema: S | string | unknown, callback: SchemaCallback): Promise; + public parse(schema: S | string | unknown, options: O): Promise; + public parse(schema: S | string | unknown, options: O, callback: SchemaCallback): Promise; + public parse(baseUrl: string, schema: S | string | unknown, options: O): Promise; + public parse(baseUrl: string, schema: S | string | unknown, options: O, callback: SchemaCallback): Promise; async parse() { const args = normalizeArgs(arguments as any); let promise; @@ -144,29 +144,29 @@ export class $RefParser = ParserOptions>( - schema: S | string, + schema: S | string | unknown, ): Promise; public static parse = ParserOptions>( - schema: S | string, + schema: S | string | unknown, callback: SchemaCallback, ): Promise; public static parse = ParserOptions>( - schema: S | string, + schema: S | string | unknown, options: O, ): Promise; public static parse = ParserOptions>( - schema: S | string, + schema: S | string | unknown, options: O, callback: SchemaCallback, ): Promise; public static parse = ParserOptions>( baseUrl: string, - schema: S | string, + schema: S | string | unknown, options: O, ): Promise; public static parse = ParserOptions>( baseUrl: string, - schema: S | string, + schema: S | string | unknown, options: O, callback: SchemaCallback, ): Promise; @@ -188,12 +188,17 @@ export class $RefParser>; - public resolve(schema: S | string, callback: $RefsCallback): Promise; - public resolve(schema: S | string, options: O): Promise<$Refs>; - public resolve(schema: S | string, options: O, callback: $RefsCallback): Promise; - public resolve(baseUrl: string, schema: S | string, options: O): Promise<$Refs>; - public resolve(baseUrl: string, schema: S | string, options: O, callback: $RefsCallback): Promise; + public resolve(schema: S | string | unknown): Promise<$Refs>; + public resolve(schema: S | string | unknown, callback: $RefsCallback): Promise; + public resolve(schema: S | string | unknown, options: O): Promise<$Refs>; + public resolve(schema: S | string | unknown, options: O, callback: $RefsCallback): Promise; + public resolve(baseUrl: string, schema: S | string | unknown, options: O): Promise<$Refs>; + public resolve( + baseUrl: string, + schema: S | string | unknown, + options: O, + callback: $RefsCallback, + ): Promise; async resolve() { const args = normalizeArgs(arguments); @@ -219,29 +224,29 @@ export class $RefParser = ParserOptions>( - schema: S | string, + schema: S | string | unknown, ): Promise<$Refs>; public static resolve = ParserOptions>( - schema: S | string, + schema: S | string | unknown, callback: $RefsCallback, ): Promise; public static resolve = ParserOptions>( - schema: S | string, + schema: S | string | unknown, options: O, ): Promise<$Refs>; public static resolve = ParserOptions>( - schema: S | string, + schema: S | string | unknown, options: O, callback: $RefsCallback, ): Promise; public static resolve = ParserOptions>( baseUrl: string, - schema: S | string, + schema: S | string | unknown, options: O, ): Promise<$Refs>; public static resolve = ParserOptions>( baseUrl: string, - schema: S | string, + schema: S | string | unknown, options: O, callback: $RefsCallback, ): Promise; @@ -264,29 +269,29 @@ export class $RefParser = ParserOptions>( - schema: S | string, + schema: S | string | unknown, ): Promise; public static bundle = ParserOptions>( - schema: S | string, + schema: S | string | unknown, callback: SchemaCallback, ): Promise; public static bundle = ParserOptions>( - schema: S | string, + schema: S | string | unknown, options: O, ): Promise; public static bundle = ParserOptions>( - schema: S | string, + schema: S | string | unknown, options: O, callback: SchemaCallback, ): Promise; public static bundle = ParserOptions>( baseUrl: string, - schema: S | string, + schema: S | string | unknown, options: O, ): Promise; public static bundle = ParserOptions>( baseUrl: string, - schema: S | string, + schema: S | string | unknown, options: O, callback: SchemaCallback, ): Promise; @@ -308,12 +313,12 @@ export class $RefParser; - public bundle(schema: S | string, callback: SchemaCallback): Promise; - public bundle(schema: S | string, options: O): Promise; - public bundle(schema: S | string, options: O, callback: SchemaCallback): Promise; - public bundle(baseUrl: string, schema: S | string, options: O): Promise; - public bundle(baseUrl: string, schema: S | string, options: O, callback: SchemaCallback): Promise; + public bundle(schema: S | string | unknown): Promise; + public bundle(schema: S | string | unknown, callback: SchemaCallback): Promise; + public bundle(schema: S | string | unknown, options: O): Promise; + public bundle(schema: S | string | unknown, options: O, callback: SchemaCallback): Promise; + public bundle(baseUrl: string, schema: S | string | unknown, options: O): Promise; + public bundle(baseUrl: string, schema: S | string | unknown, options: O, callback: SchemaCallback): Promise; async bundle() { const args = normalizeArgs(arguments); try { @@ -338,29 +343,29 @@ export class $RefParser = ParserOptions>( - schema: S | string, + schema: S | string | unknown, ): Promise; public static dereference = ParserOptions>( - schema: S | string, + schema: S | string | unknown, callback: SchemaCallback, ): Promise; public static dereference = ParserOptions>( - schema: S | string, + schema: S | string | unknown, options: O, ): Promise; public static dereference = ParserOptions>( - schema: S | string, + schema: S | string | unknown, options: O, callback: SchemaCallback, ): Promise; public static dereference = ParserOptions>( baseUrl: string, - schema: S | string, + schema: S | string | unknown, options: O, ): Promise; public static dereference = ParserOptions>( baseUrl: string, - schema: S | string, + schema: S | string | unknown, options: O, callback: SchemaCallback, ): Promise; @@ -383,12 +388,17 @@ export class $RefParser): Promise; - public dereference(schema: S | string, options: O, callback: SchemaCallback): Promise; - public dereference(schema: S | string, callback: SchemaCallback): Promise; - public dereference(baseUrl: string, schema: S | string, options: O): Promise; - public dereference(schema: S | string, options: O): Promise; - public dereference(schema: S | string): Promise; + public dereference( + baseUrl: string, + schema: S | string | unknown, + options: O, + callback: SchemaCallback, + ): Promise; + public dereference(schema: S | string | unknown, options: O, callback: SchemaCallback): Promise; + public dereference(schema: S | string | unknown, callback: SchemaCallback): Promise; + public dereference(baseUrl: string, schema: S | string | unknown, options: O): Promise; + public dereference(schema: S | string | unknown, options: O): Promise; + public dereference(schema: S | string | unknown): Promise; async dereference() { const args = normalizeArgs(arguments); diff --git a/test/specs/working-directory/api/example.yaml b/test/specs/working-directory/api/example.yaml new file mode 100644 index 00000000..631436e9 --- /dev/null +++ b/test/specs/working-directory/api/example.yaml @@ -0,0 +1,276 @@ +--- +openapi: 3.1.0 +info: + title: Test Example Example + description: Test Example Example API + version: "1" +servers: + - url: https://api.stage.Test Example.ai + description: Stage API + - url: https://api.Test Example.ai + description: Production API +security: + - BearerAuth: [] +paths: + /api/v2/create/{sensor_id}: + parameters: + - name: sensor_id + required: true + schema: + title: Sensor ID + type: string + format: uuid + example: 123e4567-e89b-12d3-a456-426614174000 + in: path + - $ref: "../common/components/parameters/Correlation.yaml#/CorrelationParameter" + - $ref: "../common/components/parameters/Tenant.yaml#/TenantParameter" + post: + summary: Request example scan + tags: + - v2 + operationId: example_api_v2_scan_create_post + requestBody: + description: Request body for create + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ScanCreateRequest" + application/octet-stream: + schema: + type: string + format: binary + responses: + 201: + $ref: "../common/components/responses/201.yaml#/CreatedResponse" + 400: + $ref: "../common/components/responses/400.yaml#/BadRequestResponse" + 422: + $ref: "../common/components/responses/422.yaml#/ValidationErrorResponse" + /api/v1/create/{sensor_id}: + parameters: + - name: sensor_id + required: true + schema: + title: Sensor ID + type: string + format: uuid + in: path + example: 123e4567-e89b-12d3-a456-426614174000 + - $ref: "../common/components/parameters/Correlation.yaml#/CorrelationParameter" + - $ref: "../common/components/parameters/Tenant.yaml#/TenantParameter" + post: + tags: + - v1 + summary: Request example scan + operationId: example_api_v1_scan_create_post + requestBody: + description: Request body for create + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ScanCreateRequest" + application/octet-stream: + schema: + type: string + format: binary + responses: + 201: + $ref: "../common/components/responses/201.yaml#/CreatedResponse" + 400: + $ref: "../common/components/responses/400.yaml#/BadRequestResponse" + 422: + $ref: "../common/components/responses/422.yaml#/ValidationErrorResponse" + /api/v2/status: + post: + tags: + - v2 + summary: Batch request status + operationId: example_api_v2_batch_status + requestBody: + description: Request for multiple sensorIds + required: true + content: + application/json: + schema: + type: array + items: + type: string + responses: + 201: + $ref: "../common/components/responses/201.yaml#/CreatedResponse" + 400: + $ref: "../common/components/responses/400.yaml#/BadRequestResponse" + 422: + $ref: "../common/components/responses/422.yaml#/ValidationErrorResponse" + + /api/v1/status/{sensor_id}: + parameters: + - name: sensor_id + required: true + schema: + title: Sensor ID + type: string + format: uuid + in: path + example: 123e4567-e89b-12d3-a456-426614174000 + - $ref: "../common/components/parameters/Correlation.yaml#/CorrelationParameter" + - $ref: "../common/components/parameters/Tenant.yaml#/TenantParameter" + get: + tags: + - v1 + summary: Get Status or Result of a Scan + operationId: example_api_v1_sensors_sensor_id_get + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/ScanResultsV2" + 400: + $ref: "../common/components/responses/400.yaml#/BadRequestResponse" + 404: + $ref: "../common/components/responses/404.yaml#/NotFoundResponse" + /api/v2/status/{sensor_id}: + parameters: + - name: sensor_id + required: true + schema: + title: Sensor ID + type: string + format: uuid + in: path + example: 123e4567-e89b-12d3-a456-426614174000 + - $ref: "../common/components/parameters/Correlation.yaml#/CorrelationParameter" + - $ref: "../common/components/parameters/Tenant.yaml#/TenantParameter" + get: + tags: + - v2 + summary: Get Status or Result of a Scan + operationId: example_api_v2_sensors_sensor_id_get + responses: + 200: + description: Successful response + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/ScanResultsV2" + 400: + $ref: "../common/components/responses/400.yaml#/BadRequestResponse" + 404: + $ref: "../common/components/responses/404.yaml#/NotFoundResponse" +components: + schemas: + ScanCreateRequest: + title: ScanCreateRequest + required: + - location + type: object + properties: + location: + title: POSIX Path + type: string + ScanResultsV2: + title: Example V2 Response + required: + - scan_id + - status + - start_time + - end_time + - results + - detections + properties: + scan_id: + title: Scan ID + type: string + status: + title: Status + type: string + enum: + - done + - accepted + - failed + - pending + - created + - retry + start_time: + title: Scan Start Time + type: integer + format: int64 + end_time: + title: Scan End Time + type: integer + format: int64 + results: + title: Scan Results + type: object + properties: + md5: + type: string + sha256: + type: string + type: + type: string + subtype: + type: array + items: + type: string + tlsh: + type: string + additionalProperties: true + detections: + type: array + items: + type: string + + ScanResultsV1: + title: Example V1 Response + required: + - scan_id + - status + - start_time + - end_time + - results + - detections + properties: + scan_id: + title: Scan ID + type: string + status: + title: Status + type: string + enum: + - done + - accepted + - failed + - pending + - created + - retry + start_time: + title: Scan Start Time + type: integer + format: int64 + end_time: + title: Scan End Time + type: integer + format: int64 + results: + title: Scan Results + type: array + items: + type: string + detections: + type: array + items: + type: string + securitySchemes: + BearerAuth: + $ref: "../common/components/security-schemes/bearer-token.yaml" + + + \ No newline at end of file diff --git a/test/specs/working-directory/common/components/examples/lorem_ipsum.yaml b/test/specs/working-directory/common/components/examples/lorem_ipsum.yaml new file mode 100644 index 00000000..92050e8a --- /dev/null +++ b/test/specs/working-directory/common/components/examples/lorem_ipsum.yaml @@ -0,0 +1 @@ +Lorem_Ipsum: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." \ No newline at end of file diff --git a/test/specs/working-directory/common/components/parameters/Correlation.yaml b/test/specs/working-directory/common/components/parameters/Correlation.yaml new file mode 100644 index 00000000..035ef5f0 --- /dev/null +++ b/test/specs/working-directory/common/components/parameters/Correlation.yaml @@ -0,0 +1,9 @@ +CorrelationParameter: + in: header + name: X-Correlation-Id + required: true + schema: + type: string + format: uuid + description: The unique identifier for the request. + example: 864e00cb-fb53-4016-97f1-78e2f07f25d3 \ No newline at end of file diff --git a/test/specs/working-directory/common/components/parameters/Tenant.yaml b/test/specs/working-directory/common/components/parameters/Tenant.yaml new file mode 100644 index 00000000..9d0b75d7 --- /dev/null +++ b/test/specs/working-directory/common/components/parameters/Tenant.yaml @@ -0,0 +1,9 @@ +TenantParameter: + in: header + name: X-Tenant-Id + required: true + schema: + type: string + format: uuid + description: The unique identifier for the tenant. + example: 1a618f53-8829-4ab7-b1e4-d4786617e1d0 \ No newline at end of file diff --git a/test/specs/working-directory/common/components/parameters/User.yaml b/test/specs/working-directory/common/components/parameters/User.yaml new file mode 100644 index 00000000..7d00be44 --- /dev/null +++ b/test/specs/working-directory/common/components/parameters/User.yaml @@ -0,0 +1,7 @@ +HLUserParameter: + in: header + name: HL-User-Id + required: true + schema: + type: string + description: The unique identifier for the user inside the HL backend. \ No newline at end of file diff --git a/test/specs/working-directory/common/components/responses/200.yaml b/test/specs/working-directory/common/components/responses/200.yaml new file mode 100644 index 00000000..5e755214 --- /dev/null +++ b/test/specs/working-directory/common/components/responses/200.yaml @@ -0,0 +1,12 @@ +EmptyResponse: + description: Successful Response + content: + application/json: + schema: {} +SuccessfulObjectResponse: + description: Successful Response + content: + application/json: + schema: + title: Any + type: object \ No newline at end of file diff --git a/test/specs/working-directory/common/components/responses/201.yaml b/test/specs/working-directory/common/components/responses/201.yaml new file mode 100644 index 00000000..f5ca806d --- /dev/null +++ b/test/specs/working-directory/common/components/responses/201.yaml @@ -0,0 +1,2 @@ +CreatedResponse: + description: The resource was successfully created. \ No newline at end of file diff --git a/test/specs/working-directory/common/components/responses/204.yaml b/test/specs/working-directory/common/components/responses/204.yaml new file mode 100644 index 00000000..6eb940e1 --- /dev/null +++ b/test/specs/working-directory/common/components/responses/204.yaml @@ -0,0 +1,2 @@ +NoContentResponse: + description: Operation successful; no content returned. \ No newline at end of file diff --git a/test/specs/working-directory/common/components/responses/400.yaml b/test/specs/working-directory/common/components/responses/400.yaml new file mode 100644 index 00000000..67c1a5df --- /dev/null +++ b/test/specs/working-directory/common/components/responses/400.yaml @@ -0,0 +1,5 @@ +BadRequestResponse: + description: | + The request failed due to a client error, with one or more of the following possible causes: + 1. The request required a tenant_id field, which was missing. + 2. The request was malformed syntactically or semantically. \ No newline at end of file diff --git a/test/specs/working-directory/common/components/responses/401.yaml b/test/specs/working-directory/common/components/responses/401.yaml new file mode 100644 index 00000000..5252b66a --- /dev/null +++ b/test/specs/working-directory/common/components/responses/401.yaml @@ -0,0 +1,6 @@ +AuthenticationErrorResponse: + description: Authentication Error + content: + application/json: + schema: + $ref: "../schemas/AuthenticationErrorModel.yaml#/AuthenticationErrorModel" \ No newline at end of file diff --git a/test/specs/working-directory/common/components/responses/403.yaml b/test/specs/working-directory/common/components/responses/403.yaml new file mode 100644 index 00000000..5252b66a --- /dev/null +++ b/test/specs/working-directory/common/components/responses/403.yaml @@ -0,0 +1,6 @@ +AuthenticationErrorResponse: + description: Authentication Error + content: + application/json: + schema: + $ref: "../schemas/AuthenticationErrorModel.yaml#/AuthenticationErrorModel" \ No newline at end of file diff --git a/test/specs/working-directory/common/components/responses/404.yaml b/test/specs/working-directory/common/components/responses/404.yaml new file mode 100644 index 00000000..1b190830 --- /dev/null +++ b/test/specs/working-directory/common/components/responses/404.yaml @@ -0,0 +1,4 @@ +NotFoundResponse: + description: The specified resource was not found. +NotFoundOrNotAuthorizedResponse: + description: The specified resource was not found or you are not authorized to access it. diff --git a/test/specs/working-directory/common/components/responses/409.yaml b/test/specs/working-directory/common/components/responses/409.yaml new file mode 100644 index 00000000..fe7b1202 --- /dev/null +++ b/test/specs/working-directory/common/components/responses/409.yaml @@ -0,0 +1,2 @@ +ConflictResponse: + description: The specified resource is in an incompatible state diff --git a/test/specs/working-directory/common/components/responses/422.yaml b/test/specs/working-directory/common/components/responses/422.yaml new file mode 100644 index 00000000..b1a2db7e --- /dev/null +++ b/test/specs/working-directory/common/components/responses/422.yaml @@ -0,0 +1,6 @@ +ValidationErrorResponse: + description: Validation Error + content: + application/json: + schema: + $ref: "../schemas/ValidationErrorModel.yaml#/ValidationErrorModel" \ No newline at end of file diff --git a/test/specs/working-directory/common/components/schemas/AuthenticationErrorModel.yaml b/test/specs/working-directory/common/components/schemas/AuthenticationErrorModel.yaml new file mode 100644 index 00000000..08c38f67 --- /dev/null +++ b/test/specs/working-directory/common/components/schemas/AuthenticationErrorModel.yaml @@ -0,0 +1,10 @@ +AuthenticationErrorModel: + title: AuthenticationErrorModel + required: + - detail + type: object + properties: + detail: + title: Detail + type: string + default: "Failed to authenticate" \ No newline at end of file diff --git a/test/specs/working-directory/common/components/schemas/HealthModel.yaml b/test/specs/working-directory/common/components/schemas/HealthModel.yaml new file mode 100644 index 00000000..e3aaa02b --- /dev/null +++ b/test/specs/working-directory/common/components/schemas/HealthModel.yaml @@ -0,0 +1,17 @@ +HealthModel: + title: HealthResponse + required: + - title + - version + - status + type: object + properties: + title: + title: Title + type: string + version: + title: Version + type: string + status: + title: Status + type: string \ No newline at end of file diff --git a/test/specs/working-directory/common/components/schemas/PagedQuery.yaml b/test/specs/working-directory/common/components/schemas/PagedQuery.yaml new file mode 100644 index 00000000..79348a60 --- /dev/null +++ b/test/specs/working-directory/common/components/schemas/PagedQuery.yaml @@ -0,0 +1,18 @@ +type: object +properties: + order_by: + title: Order By + type: string + order_dir: + title: Order direction + type: string + enum: [ "asc", "desc", "ASC", "DESC" ] + page_size: + title: Page Size + type: integer + default: 25 + page_number: + title: Page Number + type: integer + default: 0 + minimum: 0 \ No newline at end of file diff --git a/test/specs/working-directory/common/components/schemas/ValidationErrorModel.yaml b/test/specs/working-directory/common/components/schemas/ValidationErrorModel.yaml new file mode 100644 index 00000000..3060fbae --- /dev/null +++ b/test/specs/working-directory/common/components/schemas/ValidationErrorModel.yaml @@ -0,0 +1,21 @@ +ValidationErrorModel: + title: ValidationErrorModel + required: + - loc + - msg + - type + type: object + properties: + loc: + title: Location + type: array + items: + anyOf: + - type: string + - type: integer + msg: + title: Message + type: string + type: + title: Error Type + type: string \ No newline at end of file diff --git a/test/specs/working-directory/common/components/security-schemes/bearer-token.yaml b/test/specs/working-directory/common/components/security-schemes/bearer-token.yaml new file mode 100644 index 00000000..47be619e --- /dev/null +++ b/test/specs/working-directory/common/components/security-schemes/bearer-token.yaml @@ -0,0 +1,3 @@ +type: http +scheme: bearer +bearerFormat: JWT \ No newline at end of file diff --git a/test/specs/working-directory/common/paths/health.yaml b/test/specs/working-directory/common/paths/health.yaml new file mode 100644 index 00000000..1e36fae7 --- /dev/null +++ b/test/specs/working-directory/common/paths/health.yaml @@ -0,0 +1,20 @@ +get: + summary: Health + operationId: health + security: + - {} + responses: + 200: + description: Successful Response + content: + application/json: + schema: + $ref: "../components/schemas/HealthModel.yaml#/HealthModel" + 400: + description: Bad request + content: + application/json: + schema: + $ref: "../components/responses/400.yaml#/BadRequestResponse" + tags: + - Health and Metrics diff --git a/test/specs/working-directory/common/paths/metrics.yaml b/test/specs/working-directory/common/paths/metrics.yaml new file mode 100644 index 00000000..c92a9d84 --- /dev/null +++ b/test/specs/working-directory/common/paths/metrics.yaml @@ -0,0 +1,16 @@ +get: + summary: Metrics + operationId: metrics + security: + - {} + responses: + 200: + description: Successful Response + content: + text/plain: + schema: + type: string + 400: + $ref: "../components/responses/400.yaml#/BadRequestResponse" + tags: + - Health and Metrics \ No newline at end of file diff --git a/test/specs/working-directory/nested/working-dir.spec.ts b/test/specs/working-directory/nested/working-dir.spec.ts new file mode 100644 index 00000000..b51d203a --- /dev/null +++ b/test/specs/working-directory/nested/working-dir.spec.ts @@ -0,0 +1,29 @@ +import { describe, expect, it } from "vitest"; +import $RefParser from "../../../../lib"; +import path from "../../../utils/path"; +import yaml from "js-yaml"; +import fsp from "fs/promises"; +import helper from "../../../utils/helper"; +import { JSONParserError } from "../../../../lib/util/errors"; + +describe("Working directory", () => { + it("should parse using the relative directory of the resolved file", async () => { + const parser = new $RefParser(); + const schema = path.rel("test/specs/working-directory/api/example.yaml"); + await parser.dereference(schema); + }); + it("should throw an error when parsing an in memory schema using relative paths", async () => { + const parser = new $RefParser(); + const schema = path.rel("test/specs/working-directory/api/example.yaml"); + const contents = await fsp.readFile(schema, "utf-8"); + const parsed = await yaml.load(contents); + try { + await parser.dereference(parsed); + helper.shouldNotGetCalled(); + } catch (err) { + expect(err).to.be.an.instanceOf(JSONParserError); + // @ts-expect-error TS(2571): Object is of type 'unknown'. + expect(err.message).to.contain("Error opening file"); + } + }); +});