Skip to content

Commit 28686f4

Browse files
authored
fix(types): Add looser types to input schema (#61)
* fix(types): Add looser types to input schema * fix(types): Add looser types to input schema
1 parent e21a5bf commit 28686f4

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/index.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import deepEqual from "fast-deep-equal";
22
import { fromSchema, fromParameter } from "./lib/convert";
3-
import type { Options, OptionsInternal, OpenAPI3 } from "./openapi-schema-types";
3+
import type { Options, OptionsInternal } from "./openapi-schema-types";
44
import { NOT_SUPPORTED, STRUCTS } from "./consts";
55
import type { JSONSchema4 } from "json-schema";
66
import type { ParameterObject, ResponseObject } from "openapi-typescript/src/types";
77
import { cloneDeep } from "./lib/utils/cloneDeep";
8+
import type { AcceptibleInputSchema } from "./openapi-schema-types";
9+
810
const patternPropertiesHandler = (schema) => {
911
let pattern;
1012
const patternsObj = schema.patternProperties;
@@ -56,7 +58,10 @@ const resolveOptions = (_options?: Options): OptionsInternal => {
5658
return options;
5759
};
5860

59-
const openapiSchemaToJsonSchema = <T extends OpenAPI3 = OpenAPI3>(schema: T, options?: Options): JSONSchema4 => {
61+
const openapiSchemaToJsonSchema = <T extends AcceptibleInputSchema = AcceptibleInputSchema>(
62+
schema: T,
63+
options?: Options,
64+
): JSONSchema4 => {
6065
const optionsInternal = resolveOptions(options);
6166
return fromSchema<T>(schema, optionsInternal);
6267
};

src/lib/converters/schema.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import type { PatternPropertiesHandler } from "../../openapi-schema-types";
88
import type { OpenAPI3 } from "openapi-typescript";
99
import type { ReferenceObject } from "openapi-typescript/src/types";
1010
import { cloneDeep } from "../utils/cloneDeep";
11+
import type { AcceptibleInputSchema } from "../../openapi-schema-types";
1112

1213
// Convert from OpenAPI 3.0 `SchemaObject` to JSON schema v4
13-
function convertFromSchema<T extends OpenAPI3 = OpenAPI3>(schema: T, options: OptionsInternal): JSONSchema4 {
14+
function convertFromSchema<T extends AcceptibleInputSchema = AcceptibleInputSchema>(
15+
schema: T,
16+
options: OptionsInternal,
17+
): JSONSchema4 {
1418
const newSchema = convertSchema(schema, options);
1519
(<JSONSchema4>newSchema).$schema = "http://json-schema.org/draft-04/schema#";
1620
return newSchema;

src/openapi-schema-types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { JSONSchema4 } from "json-schema";
66
export type { OpenAPI3 };
77
// We don't know what the shape of the object looks like when it's passed in, but we know its some mix of these two
88
export type PatternPropertiesHandler = (schema: SchemaObject) => SchemaObject;
9+
export type AcceptibleInputSchema = SchemaObject | OpenAPI3 | Record<string, any>;
910

1011
export interface Options {
1112
dateToDateTime?: boolean;

0 commit comments

Comments
 (0)