Skip to content

Commit

Permalink
test: add failing test case for openAPI propr not convertible to JSON…
Browse files Browse the repository at this point in the history
… schema
  • Loading branch information
toomuchdesign committed Mar 6, 2024
1 parent a8b4e24 commit 9c61a36
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/fixtures/security-fields/specs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
openapi: 3.0.0
info:
title: Minimal OpenAPI specification to reproduce an issue
version: 1.0.0
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer

schemas:
HelloWorld:
type: object
properties:
message:
type: string
required:
- message
paths:
'/hello':
get:
security:
- bearerAuth: []
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/HelloWorld'
17 changes: 17 additions & 0 deletions test/securityFields.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'path';
import { describe, it, expect } from 'vitest';
import { fixtures, makeTestOutputPath } from './test-utils';
import { openapiToTsJsonSchema } from '../src';

describe('OpenApi security fields', () => {
it('handles schema correctly', async () => {
await expect(
openapiToTsJsonSchema({
openApiSchema: path.resolve(fixtures, 'security-fields/specs.yaml'),
outputPath: makeTestOutputPath('security-fields'),
definitionPathsToGenerateFrom: ['components.schemas', 'paths'],
silent: true,
}),
).resolves.not.toThrow();

Check failure on line 15 in test/securityFields.test.ts

View workflow job for this annotation

GitHub Actions / test-and-build (20, ubuntu-latest)

test/securityFields.test.ts > OpenApi security fields > handles schema correctly

AssertionError: promise rejected "InvalidTypeError: Type "http" is not a va…" instead of resolving ❯ test/securityFields.test.ts:15:5 Caused by: InvalidTypeError: Type "http" is not a valid type ❯ validateType node_modules/@openapi-contrib/openapi-schema-to-json-schema/src/lib/converters/schema.ts:115:11 ❯ convertSchema node_modules/@openapi-contrib/openapi-schema-to-json-schema/src/lib/converters/schema.ts:91:5 ❯ convertFromSchema node_modules/@openapi-contrib/openapi-schema-to-json-schema/src/lib/converters/schema.ts:19:21 ❯ Proxy.openapiSchemaToJsonSchema node_modules/@openapi-contrib/openapi-schema-to-json-schema/src/index.ts:66:20 ❯ convertToJsonSchema src/utils/convertOpenApiToJsonSchema.ts:21:18 ❯ default.deep src/utils/convertOpenApiToJsonSchema.ts:39:20 ❯ mapObject node_modules/map-obj/index.js:35:21 ❯ mapObject node_modules/map-obj/index.js:51:5 ❯ mapObject node_modules/map-obj/index.js:51:5 ❯ Proxy.module.exports node_modules/map-obj/index.js:65:9

Check failure on line 15 in test/securityFields.test.ts

View workflow job for this annotation

GitHub Actions / test-and-build (20, macOS-latest)

test/securityFields.test.ts > OpenApi security fields > handles schema correctly

AssertionError: promise rejected "InvalidTypeError: Type "http" is not a va…" instead of resolving ❯ test/securityFields.test.ts:15:5 Caused by: InvalidTypeError: Type "http" is not a valid type ❯ validateType node_modules/@openapi-contrib/openapi-schema-to-json-schema/src/lib/converters/schema.ts:115:11 ❯ convertSchema node_modules/@openapi-contrib/openapi-schema-to-json-schema/src/lib/converters/schema.ts:91:5 ❯ convertFromSchema node_modules/@openapi-contrib/openapi-schema-to-json-schema/src/lib/converters/schema.ts:19:21 ❯ Proxy.openapiSchemaToJsonSchema node_modules/@openapi-contrib/openapi-schema-to-json-schema/src/index.ts:66:20 ❯ convertToJsonSchema src/utils/convertOpenApiToJsonSchema.ts:21:18 ❯ default.deep src/utils/convertOpenApiToJsonSchema.ts:39:20 ❯ mapObject node_modules/map-obj/index.js:35:21 ❯ mapObject node_modules/map-obj/index.js:51:5 ❯ mapObject node_modules/map-obj/index.js:51:5 ❯ Proxy.module.exports node_modules/map-obj/index.js:65:9
});
});

0 comments on commit 9c61a36

Please sign in to comment.