Skip to content

Commit

Permalink
Bump skuba from 7.0.1 to 7.1.1 (#161)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: samchungy <samchungy@gmail.com>
  • Loading branch information
dependabot[bot] and samchungy authored Aug 24, 2023
1 parent 8b77cea commit 7faf986
Show file tree
Hide file tree
Showing 34 changed files with 568 additions and 434 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/.gantry/**/*.yml
gantry*.yaml
gantry*.yml
pnpm-lock.yaml
# end managed by skuba

examples/**/*.yml
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/node": "^20.3.0",
"eslint-plugin-zod-openapi": "^0.1.0",
"openapi3-ts": "4.1.2",
"skuba": "7.0.1",
"skuba": "7.1.1",
"yaml": "2.3.1",
"zod": "3.22.2"
},
Expand Down
61 changes: 29 additions & 32 deletions src/create/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export interface ZodOpenApiOperationObject
oas31.OperationObject & oas30.OperationObject,
'requestBody' | 'responses' | 'parameters'
> {
parameters?: (
parameters?: Array<
| ZodType
| oas31.ParameterObject
| oas30.ParameterObject
| oas31.ReferenceObject
| oas30.ReferenceObject
)[];
>;
requestBody?: ZodOpenApiRequestBodyObject;
requestParams?: ZodOpenApiParameters;
responses: ZodOpenApiResponsesObject;
Expand All @@ -81,6 +81,7 @@ export interface ZodOpenApiPathItemObject
trace?: ZodOpenApiOperationObject;
}

// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
export interface ZodOpenApiPathsObject extends oas31.ISpecificationExtension {
[path: string]: ZodOpenApiPathItemObject;
}
Expand All @@ -90,36 +91,32 @@ export interface ZodOpenApiComponentsObject
oas31.ComponentsObject & oas30.ComponentsObject,
'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters'
> {
parameters?: {
[parameter: string]:
| ZodType
| oas31.ParameterObject
| oas30.ParameterObject
| oas31.ReferenceObject
| oas30.ReferenceObject;
};
schemas?: {
[ref: string]:
| ZodType
| oas31.SchemaObject
| oas31.ReferenceObject
| oas30.SchemaObject
| oas30.ReferenceObject;
};
requestBodies?: {
[ref: string]: ZodOpenApiRequestBodyObject;
};
headers?: {
[header: string]:
| ZodType
| oas31.HeaderObject
| oas30.HeaderObject
| oas31.ReferenceObject
| oas30.ReferenceObject;
};
responses?: {
[ref: string]: ZodOpenApiResponseObject;
};
parameters?: Record<
string,
| ZodType
| oas31.ParameterObject
| oas30.ParameterObject
| oas31.ReferenceObject
| oas30.ReferenceObject
>;
schemas?: Record<
string,
| ZodType
| oas31.SchemaObject
| oas31.ReferenceObject
| oas30.SchemaObject
| oas30.ReferenceObject
>;
requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
headers?: Record<
string,
| ZodType
| oas31.HeaderObject
| oas30.HeaderObject
| oas31.ReferenceObject
| oas30.ReferenceObject
>;
responses?: Record<string, ZodOpenApiResponseObject>;
}

export type ZodOpenApiVersion = OpenApiVersion;
Expand Down
14 changes: 7 additions & 7 deletions src/create/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const createParameters = (
zodObject: AnyZodObject | undefined,
components: ComponentsObject,
subpath: string[],
): (oas31.ParameterObject | oas31.ReferenceObject)[] => {
): Array<oas31.ParameterObject | oas31.ReferenceObject> => {
if (!zodObject) {
return [];
}
Expand Down Expand Up @@ -151,17 +151,17 @@ const createRequestParams = (

export const createManualParameters = (
parameters:
| (
| Array<
| oas31.ParameterObject
| oas31.ReferenceObject
| oas30.ParameterObject
| oas30.ReferenceObject
| ZodType
)[]
>
| undefined,
components: ComponentsObject,
subpath: string[],
): (oas31.ParameterObject | oas31.ReferenceObject)[] =>
): Array<oas31.ParameterObject | oas31.ReferenceObject> =>
parameters?.map((param, index) => {
if (isAnyZodType(param)) {
return createParamOrRef(param, components, [
Expand All @@ -174,18 +174,18 @@ export const createManualParameters = (

export const createParametersObject = (
parameters:
| (
| Array<
| oas31.ParameterObject
| oas31.ReferenceObject
| oas30.ParameterObject
| oas30.ReferenceObject
| ZodType
)[]
>
| undefined,
requestParams: ZodOpenApiParameters | undefined,
components: ComponentsObject,
subpath: string[],
): (oas31.ParameterObject | oas31.ReferenceObject)[] | undefined => {
): Array<oas31.ParameterObject | oas31.ReferenceObject> | undefined => {
const manualParameters = createManualParameters(
parameters,
components,
Expand Down
10 changes: 5 additions & 5 deletions src/create/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const newSchemaState = (state: SchemaState): SchemaState => ({
});

export const createNewSchema = <
Output = any,
Output = unknown,
Def extends ZodTypeDef = ZodTypeDef,
Input = Output,
>(
Expand Down Expand Up @@ -65,7 +65,7 @@ export const createNewSchema = <
};

export const createNewRef = <
Output = any,
Output = unknown,
Def extends ZodTypeDef = ZodTypeDef,
Input = Output,
>(
Expand Down Expand Up @@ -99,7 +99,7 @@ export const createNewRef = <
};

export const createExistingRef = <
Output = any,
Output = unknown,
Def extends ZodTypeDef = ZodTypeDef,
Input = Output,
>(
Expand Down Expand Up @@ -141,7 +141,7 @@ type Schema = {
};

export const createSchemaOrRef = <
Output = any,
Output = unknown,
Def extends ZodTypeDef = ZodTypeDef,
Input = Output,
>(
Expand All @@ -165,7 +165,7 @@ export const createSchemaOrRef = <
};

export const createSchemaObject = <
Output = any,
Output = unknown,
Def extends ZodTypeDef = ZodTypeDef,
Input = Output,
>(
Expand Down
11 changes: 7 additions & 4 deletions src/create/schema/parsers/array.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { ZodArray, ZodTypeAny } from 'zod';
import type { ArrayCardinality, ZodArray, ZodTypeAny } from 'zod';

import type { oas31 } from '../../../openapi3-ts/dist';
import { type SchemaState, createSchemaObject } from '../../schema';

export const createArraySchema = (
zodArray: ZodArray<any, any>,
export const createArraySchema = <
T extends ZodTypeAny,
Cardinality extends ArrayCardinality = 'many',
>(
zodArray: ZodArray<T, Cardinality>,
state: SchemaState,
): oas31.SchemaObject => {
const zodType = zodArray._def.type as ZodTypeAny;
const zodType = zodArray._def.type;
const minItems =
zodArray._def.exactLength?.value ?? zodArray._def.minLength?.value;
const maxItems =
Expand Down
11 changes: 7 additions & 4 deletions src/create/schema/parsers/brand.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { ZodBranded, ZodType } from 'zod';
import type { ZodBranded, ZodTypeAny } from 'zod';

import type { oas31 } from '../../../openapi3-ts/dist';
import { type SchemaState, createSchemaObject } from '../../schema';
export const createBrandedSchema = (
zodBranded: ZodBranded<any, any>,
export const createBrandedSchema = <
T extends ZodTypeAny,
B extends string | number | symbol,
>(
zodBranded: ZodBranded<T, B>,
state: SchemaState,
): oas31.SchemaObject | oas31.ReferenceObject =>
createSchemaObject(zodBranded._def.type as ZodType, state, ['brand']);
createSchemaObject(zodBranded._def.type, state, ['brand']);
8 changes: 4 additions & 4 deletions src/create/schema/parsers/catch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ZodCatch, ZodType } from 'zod';
import type { ZodCatch, ZodTypeAny } from 'zod';

import type { oas31 } from '../../../openapi3-ts/dist';
import { type SchemaState, createSchemaObject } from '../../schema';

export const createCatchSchema = (
zodCatch: ZodCatch<any>,
export const createCatchSchema = <T extends ZodTypeAny>(
zodCatch: ZodCatch<T>,
state: SchemaState,
): oas31.SchemaObject | oas31.ReferenceObject =>
createSchemaObject(zodCatch._def.innerType as ZodType, state, ['catch']);
createSchemaObject(zodCatch._def.innerType, state, ['catch']);
13 changes: 5 additions & 8 deletions src/create/schema/parsers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import type { oas31 } from '../../../openapi3-ts/dist';
import { type SchemaState, createSchemaObject } from '../../schema';
import { enhanceWithMetadata } from '../metadata';

export const createDefaultSchema = (
zodDefault: ZodDefault<any>,
export const createDefaultSchema = <T extends ZodTypeAny>(
zodDefault: ZodDefault<T>,
state: SchemaState,
): oas31.SchemaObject | oas31.ReferenceObject => {
const schemaObject = createSchemaObject(
zodDefault._def.innerType as ZodTypeAny,
state,
['default'],
);
const schemaObject = createSchemaObject(zodDefault._def.innerType, state, [
'default',
]);

return enhanceWithMetadata(schemaObject, {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
default: zodDefault._def.defaultValue(),
});
};
14 changes: 9 additions & 5 deletions src/create/schema/parsers/discriminatedUnion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
AnyZodObject,
ZodDiscriminatedUnion,
ZodDiscriminatedUnionOption,
ZodLiteralDef,
ZodRawShape,
} from 'zod';
Expand All @@ -9,11 +10,14 @@ import type { oas31 } from '../../../openapi3-ts/dist';
import { isZodType } from '../../../zodType';
import { type SchemaState, createSchemaObject } from '../../schema';

export const createDiscriminatedUnionSchema = (
zodDiscriminatedUnion: ZodDiscriminatedUnion<any, any>,
export const createDiscriminatedUnionSchema = <
Discriminator extends string,
Options extends Array<ZodDiscriminatedUnionOption<Discriminator>>,
>(
zodDiscriminatedUnion: ZodDiscriminatedUnion<Discriminator, Options>,
state: SchemaState,
): oas31.SchemaObject => {
const options = zodDiscriminatedUnion.options as AnyZodObject[];
const options = zodDiscriminatedUnion.options;
const schemas = options.map((option, index) =>
createSchemaObject(option, state, [`discriminated union option ${index}`]),
);
Expand All @@ -30,7 +34,7 @@ export const createDiscriminatedUnionSchema = (
};

export const mapDiscriminator = (
schemas: (oas31.SchemaObject | oas31.ReferenceObject)[],
schemas: Array<oas31.SchemaObject | oas31.ReferenceObject>,
zodObjects: AnyZodObject[],
discriminator: unknown,
state: SchemaState,
Expand All @@ -41,7 +45,7 @@ export const mapDiscriminator = (

const mapping: NonNullable<oas31.DiscriminatorObject['mapping']> = {};
for (const [index, zodObject] of zodObjects.entries()) {
const schema = schemas[index]!;
const schema = schemas[index] as oas31.SchemaObject | oas31.ReferenceObject;
const componentSchemaRef = '$ref' in schema ? schema?.$ref : undefined;
if (!componentSchemaRef) {
return undefined;
Expand Down
5 changes: 2 additions & 3 deletions src/create/schema/parsers/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import type { ZodEnum } from 'zod';

import type { oas31 } from '../../../openapi3-ts/dist';

export const createEnumSchema = (
zodEnum: ZodEnum<any>,
export const createEnumSchema = <T extends [string, ...string[]]>(
zodEnum: ZodEnum<T>,
): oas31.SchemaObject => ({
type: 'string',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
enum: zodEnum._def.values,
});
2 changes: 1 addition & 1 deletion src/create/schema/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { createUnionSchema } from './union';
import { createUnknownSchema } from './unknown';

export const createSchemaSwitch = <
Output = any,
Output = unknown,
Def extends ZodTypeDef = ZodTypeDef,
Input = Output,
>(
Expand Down
15 changes: 8 additions & 7 deletions src/create/schema/parsers/intersection.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type { ZodIntersection, ZodType } from 'zod';
import type { ZodIntersection, ZodTypeAny } from 'zod';

import type { oas31 } from '../../../openapi3-ts/dist';
import { type SchemaState, createSchemaObject } from '../../schema';

export const createIntersectionSchema = (
zodIntersection: ZodIntersection<any, any>,
export const createIntersectionSchema = <
T extends ZodTypeAny,
U extends ZodTypeAny,
>(
zodIntersection: ZodIntersection<T, U>,
state: SchemaState,
): oas31.SchemaObject | oas31.ReferenceObject => ({
allOf: [
createSchemaObject(zodIntersection._def.left as ZodType, state, [
'intersection left',
]),
createSchemaObject(zodIntersection._def.right as ZodType, state, [
createSchemaObject(zodIntersection._def.left, state, ['intersection left']),
createSchemaObject(zodIntersection._def.right, state, [
'intersection right',
]),
],
Expand Down
8 changes: 4 additions & 4 deletions src/create/schema/parsers/lazy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ZodLazy, ZodType } from 'zod';
import type { ZodLazy, ZodTypeAny } from 'zod';

import type { oas31 } from '../../../openapi3-ts/dist';
import { type SchemaState, createSchemaObject } from '../../schema';

export const createLazySchema = (
zodLazy: ZodLazy<any>,
export const createLazySchema = <T extends ZodTypeAny>(
zodLazy: ZodLazy<T>,
state: SchemaState,
): oas31.ReferenceObject | oas31.SchemaObject => {
const innerSchema = zodLazy._def.getter() as ZodType;
const innerSchema = zodLazy._def.getter();
return createSchemaObject(innerSchema, state, ['lazy schema']);
};
2 changes: 1 addition & 1 deletion src/create/schema/parsers/literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ZodLiteral } from 'zod';
import type { oas31 } from '../../../openapi3-ts/dist';

export const createLiteralSchema = (
zodLiteral: ZodLiteral<any>,
zodLiteral: ZodLiteral<unknown>,
): oas31.SchemaObject => ({
type: typeof zodLiteral.value as oas31.SchemaObject['type'],
enum: [zodLiteral._def.value],
Expand Down
Loading

0 comments on commit 7faf986

Please sign in to comment.