Skip to content

Commit

Permalink
feat: 内置 helpers,避免从外部导入
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Jul 30, 2024
1 parent df0c7d2 commit d30f674
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/printer/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ export const INTERNAL_NAMES = [
'Blob',
'Array',
'Object',
// client exports
// printer helpers
'OneOf',
'AllOf',
'AnyOf',
'AnyObject',
'AnyArray',
'URL',
'resolveURL',
'BASE_URL',
// config
AXIOS_IMPORT_NAME,
AXIOS_QUEST_CONFIG_TYPE_NAME,
Expand Down
11 changes: 10 additions & 1 deletion test/example-dest/2.0/pet-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ import type {AxiosRequestConfig, AxiosPromise} from "axios";
import type {OneOf, AllOf, AnyOf, AnyObject, AnyArray} from "pkg-name-for-test/client";
import {resolveURL} from "pkg-name-for-test/client";

const BASE_URL="/";


// helpers --- start
export type OneOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A | OneOf<B> : never;
export type AllOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A & AllOf<B> : unknown;
export type AnyOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A | AnyOf<B> | (A & AnyOf<B>) : never;
export type AnyObject = Record<string, any>;
export type AnyArray = any[];
// helpers --- end


export type Order = (({
/**
Expand Down
11 changes: 10 additions & 1 deletion test/example-dest/3.0/pet-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ import type {AxiosRequestConfig, AxiosPromise} from "axios";
import type {OneOf, AllOf, AnyOf, AnyObject, AnyArray} from "pkg-name-for-test/client";
import {resolveURL} from "pkg-name-for-test/client";

const BASE_URL="/";


// helpers --- start
export type OneOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A | OneOf<B> : never;
export type AllOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A & AllOf<B> : unknown;
export type AnyOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A | AnyOf<B> | (A & AnyOf<B>) : never;
export type AnyObject = Record<string, any>;
export type AnyArray = any[];
// helpers --- end


export type Order = (({
/**
Expand Down
11 changes: 10 additions & 1 deletion test/example-dest/3.1/pet-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ import type {AxiosRequestConfig, AxiosPromise} from "axios";
import type {OneOf, AllOf, AnyOf, AnyObject, AnyArray} from "pkg-name-for-test/client";
import {resolveURL} from "pkg-name-for-test/client";

const BASE_URL="/api/v31";


// helpers --- start
export type OneOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A | OneOf<B> : never;
export type AllOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A & AllOf<B> : unknown;
export type AnyOf<T extends unknown[]> = T extends [infer A, ...infer B] ? A | AnyOf<B> | (A & AnyOf<B>) : never;
export type AnyObject = Record<string, any>;
export type AnyArray = any[];
// helpers --- end


/**
* @description Category
Expand Down
13 changes: 13 additions & 0 deletions test/printer/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ test('1路径 + 1请求', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -52,6 +53,7 @@ test('1路径 + 1请求 * module', () => {
printer.print({
module: 'TTT',
hideImports: true,
hideHelpers: true,
}),
).toMatchInlineSnapshot(`
"/* eslint-disable @typescript-eslint/ban-ts-comment */
Expand Down Expand Up @@ -95,6 +97,7 @@ test('1路径 + 2请求', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -155,6 +158,7 @@ test('1路径 + 1请求 + 1query', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -206,6 +210,7 @@ test('1路径 + 1请求 + 1query with duplicate', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -258,6 +263,7 @@ test('1路径 + 1请求 + 1path', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -316,6 +322,7 @@ test('1路径 + 1请求 + 2path', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -381,6 +388,7 @@ test('1路径 + 1请求 + 2query', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -457,6 +465,7 @@ test('1路径 + 1请求 + 2query + 1path', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -544,6 +553,7 @@ test('1路径 + 1请求 + 2query + 1path + 1request primitive', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -639,6 +649,7 @@ test('1路径 + 1请求 + 2query + 1path + 1request object', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -746,6 +757,7 @@ test('1路径 + 1请求 + 2query + 1path + 1request object + 1response primitive
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -871,6 +883,7 @@ test('1路径 + 1请求 + 2query + 1path + 1request object + 1response object',
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down
1 change: 1 addition & 0 deletions test/printer/ref-parameter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test('ref-parameter', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down
1 change: 1 addition & 0 deletions test/printer/ref-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ test('ref-request', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down
2 changes: 2 additions & 0 deletions test/printer/ref-response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ test('ref-response', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -133,6 +134,7 @@ test('ref-response in object', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down
13 changes: 13 additions & 0 deletions test/printer/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test('number', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -53,6 +54,7 @@ test('number enum', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -86,6 +88,7 @@ test('[number, null] enum', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -120,6 +123,7 @@ test('type[]', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -173,6 +177,7 @@ test('AllOf primitive', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -223,6 +228,7 @@ test('explicit array', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -264,6 +270,7 @@ test('generic array', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -315,6 +322,7 @@ test('explicit object', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -364,6 +372,7 @@ test('generic object', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -395,6 +404,7 @@ test('additionalProperties true', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand All @@ -420,6 +430,7 @@ test('additionalProperties false', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -456,6 +467,7 @@ test('additionalProperties schema type', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down Expand Up @@ -505,6 +517,7 @@ test('additionalProperties schema ref', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down
1 change: 1 addition & 0 deletions test/printer/unique-name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ test('unique name', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down
1 change: 1 addition & 0 deletions test/printer/v31.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test('v3.1 schema', () => {
expect(
printer.print({
hideHeaders: true,
hideHelpers: true,
hideInfo: true,
hideImports: true,
}),
Expand Down

0 comments on commit d30f674

Please sign in to comment.