Something went wrong. Try again.
fork of hey-api/openapi-ts because I need some additional things
Something went wrong. Try again.
1.2 kB · 48 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import type { SchemaWithType } from '@hey-api/shared';
// import { $ } from '../../../../py-dsl';import type { Ast, IrSchemaToAstOptions } from '../../shared/types';
export function stringToNode({ schema,}: IrSchemaToAstOptions & { schema: SchemaWithType<'string'>;}): Ast { const constraints: Record<string, unknown> = {};
if (schema.minLength !== undefined) { constraints.min_length = schema.minLength; }
if (schema.maxLength !== undefined) { constraints.max_length = schema.maxLength; }
if (schema.pattern !== undefined) { constraints.pattern = schema.pattern; }
if (schema.description !== undefined) { constraints.description = schema.description; }
if (typeof schema.const === 'string') { return { // expression: $.expr(`Literal["${schema.const}"]`), fieldConstraints: constraints, hasLazyExpression: false, models: [], // pipes: [], typeAnnotation: `Literal["${schema.const}"]`, }; }
return { // expression: $.expr('str'), fieldConstraints: constraints, hasLazyExpression: false, models: [], // pipes: [], typeAnnotation: 'str', };}