Skip to content

Commit

Permalink
format, apply lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samchungy committed Dec 20, 2024
1 parent 86c2ad5 commit bde6ef2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@
"entryPoint": "src/index.ts",
"template": "oss-npm-package",
"type": "package",
"version": "9.0.0-main-20240928013837"
"version": "9.1.0"
}
}
18 changes: 11 additions & 7 deletions src/create/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ZodType, ZodTypeDef } from 'zod';

import { currentSymbol, previousSymbol } from '../../extendZodTypes';
import type { oas30, oas31 } from '../../openapi3-ts/dist';
import {
type ComponentsObject,
Expand All @@ -13,7 +14,6 @@ import { enhanceWithMetadata } from './metadata';
import { createSchemaSwitch } from './parsers';
import { verifyEffects } from './parsers/transform';
import type { CreateSchemaOptions } from './single';
import { currentSymbol, previousSymbol } from '../../extendZodTypes';

export type LazyMap = Map<ZodType, true>;

Expand Down Expand Up @@ -222,17 +222,21 @@ export const createSchemaOrRef = <
}

const previous = zodSchema._def.zodOpenApi?.[previousSymbol]
? (createSchemaOrRef(zodSchema._def.zodOpenApi[previousSymbol], state, true) as
| RefObject
| undefined)
? (createSchemaOrRef(
zodSchema._def.zodOpenApi[previousSymbol],
state,
true,
) as RefObject | undefined)
: undefined;

const current =
zodSchema._def.zodOpenApi?.[currentSymbol] &&
zodSchema._def.zodOpenApi[currentSymbol] !== zodSchema
? (createSchemaOrRef(zodSchema._def.zodOpenApi[currentSymbol], state, true) as
| RefObject
| undefined)
? (createSchemaOrRef(
zodSchema._def.zodOpenApi[currentSymbol],
state,
true,
) as RefObject | undefined)
: undefined;

const ref = zodSchema._def.zodOpenApi?.openapi?.ref ?? component?.ref;
Expand Down
4 changes: 3 additions & 1 deletion src/create/schema/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ describe('enhanceWithMetadata', () => {

it('does not fail JSON serialization', () => {
const FooSchema = z.string().openapi({ ref: 'foo' });
expect(()=>{JSON.stringify(FooSchema)}).not.toThrow();
expect(() => {
JSON.stringify(FooSchema);
}).not.toThrow();
});
});
1 change: 0 additions & 1 deletion src/entries/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ import { extendZodWithOpenApi } from '../extendZod';

extendZodWithOpenApi(z);

// eslint-disable-next-line @typescript-eslint/consistent-type-exports
export * from '../extendZodTypes'; // compatibility with < TS 5.0 as the export type * syntax is not supported
3 changes: 2 additions & 1 deletion src/extendZod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('extendZodWithOpenApi', () => {
expect(a._def.zodOpenApi?.openapi?.description).toBe('test');
expect(b._def.zodOpenApi?.openapi?.description).toBe('test2');
expect(
b._def.zodOpenApi?.[previousSymbol]?._def.zodOpenApi?.openapi?.description,
b._def.zodOpenApi?.[previousSymbol]?._def.zodOpenApi?.openapi
?.description,
).toBe('test');
});

Expand Down
1 change: 0 additions & 1 deletion src/extendZod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ZodRawShape, ZodTypeDef, z } from 'zod';

import './extendZodTypes';
import { currentSymbol, previousSymbol } from './extendZodTypes';

type ZodOpenApiMetadataDef = NonNullable<ZodTypeDef['zodOpenApi']>;
Expand Down
4 changes: 2 additions & 2 deletions src/extendZodTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ type SchemaObject = oas30.SchemaObject & oas31.SchemaObject;

type ReplaceDate<T> = T extends Date ? Date | string : T;

export const currentSymbol = Symbol("current");
export const previousSymbol = Symbol("previous");
export const currentSymbol = Symbol('current');
export const previousSymbol = Symbol('previous');

/**
* zod-openapi metadata
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"removeComments": false,
"target": "ES2022"
},
"exclude": ["lib*/**/*", "crackle.config.ts"],
"exclude": ["lib*/**/*", "crackle.config.ts", "dist", "api", "extend"],
"extends": "skuba/config/tsconfig.json"
}

0 comments on commit bde6ef2

Please sign in to comment.