Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 5 additions & 0 deletions .changeset/metal-worms-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/http-open-api": minor
---

- Added 3.2 `SwaggerUiProvider`
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, expectTypeOf, it } from 'vitest';

import {
type OpenApi3Dot2OperationObject,
type OpenApi3Dot2PathItemObject,
} from '@inversifyjs/open-api-types/v3Dot2';

import { type FilteredByValueType } from './FilteredByValueType.js';

// eslint-disable-next-line vitest/prefer-describe-function-title
describe('FilteredByValueType', () => {
describe('having an object with optional properties of mixed types', () => {
interface TestObject {
bar?: number;
baz?: string;
foo?: string;
record?: Record<string, string>;
}

describe('when used with string as value type', () => {
it('should only include keys with matching value type', () => {
expectTypeOf<
keyof FilteredByValueType<TestObject, string>
>().toEqualTypeOf<'baz' | 'foo'>();
});
});
});

describe('having OpenApi3Dot2PathItemObject', () => {
describe('when used with OpenApi3Dot2OperationObject as value type', () => {
it('should only include HTTP method keys', () => {
expectTypeOf<
keyof FilteredByValueType<
OpenApi3Dot2PathItemObject,
OpenApi3Dot2OperationObject
>
>().toEqualTypeOf<
| 'delete'
| 'get'
| 'head'
| 'options'
| 'patch'
| 'post'
| 'put'
| 'query'
| 'trace'
>();
});

it('should not include additionalOperations', () => {
expectTypeOf<
FilteredByValueType<
OpenApi3Dot2PathItemObject,
OpenApi3Dot2OperationObject
>
>().not.toHaveProperty('additionalOperations');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export type FilteredByValueType<TObject, TType> = {
[TKey in keyof TObject as TObject[TKey] extends TType | undefined
? TKey
: never]: TObject[TKey] extends TType | undefined ? TObject[TKey] : never;
[TKey in keyof TObject as NonNullable<TObject[TKey]> extends TType
? string extends keyof NonNullable<TObject[TKey]>
? string extends keyof TType
? TKey
: never
: TKey
: never]: TObject[TKey];
};
Loading