fork of hey-api/openapi-ts because I need some additional things
1import type { SchemaWithType } from '@hey-api/shared';
2
3import { $ } from '../../../../py-dsl';
4import type { NullResolverContext } from '../../resolvers';
5import type { PydanticType } from '../../shared/types';
6import type { PydanticPlugin } from '../../types';
7
8// eslint-disable-next-line @typescript-eslint/no-unused-vars
9function baseNode(_ctx: NullResolverContext): PydanticType {
10 return {
11 type: 'None',
12 };
13}
14
15function nullResolver(ctx: NullResolverContext): PydanticType {
16 return ctx.nodes.base(ctx);
17}
18
19export function nullToType({
20 plugin,
21 schema,
22}: {
23 plugin: PydanticPlugin['Instance'];
24 schema: SchemaWithType<'null'>;
25}): PydanticType {
26 const ctx: NullResolverContext = {
27 $,
28 nodes: {
29 base: baseNode,
30 },
31 plugin,
32 schema,
33 };
34
35 const resolver = plugin.config['~resolvers']?.null;
36 return resolver?.(ctx) ?? nullResolver(ctx);
37}