Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add orphan Type to IJSONApplication to save types #1210

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function application(): never;
export function application<
Types extends unknown[],
Version extends "3.0" | "3.1" = "3.1",
>(): IJsonApplication<Version>;
>(): IJsonApplication<Version, Types>;

/**
* @internal
Expand Down
12 changes: 7 additions & 5 deletions src/programmers/json/JsonApplicationProgrammer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenApi, OpenApiV3 } from "@samchon/openapi";

import { IJsonApplication } from "../../schemas/json/IJsonApplication";
import { IJsonApplication, type tag as IJSONTag } from "../../schemas/json/IJsonApplication";
import { Metadata } from "../../schemas/metadata/Metadata";

import { TransformerError } from "../../transformers/TransformerError";
Expand Down Expand Up @@ -44,7 +44,7 @@ export namespace JsonApplicationProgrammer {
const components: OpenApiV3.IComponents = {};
const generator = (meta: Metadata): OpenApiV3.IJsonSchema | null =>
application_v30_schema(true)(components)({})(meta);
return {
const schema = ({
version: "3.0",
components,
schemas: metadatas.map((meta, i) => {
Expand All @@ -56,7 +56,8 @@ export namespace JsonApplicationProgrammer {
});
return schema;
}),
};
} satisfies Omit<IJsonApplication<"3.0">, typeof IJSONTag>); // check types before as assertion
return schema as IJsonApplication<"3.0">;
};

const v31 = (metadatas: Array<Metadata>): IJsonApplication<"3.1"> => {
Expand All @@ -65,7 +66,7 @@ export namespace JsonApplicationProgrammer {
};
const generator = (meta: Metadata): OpenApi.IJsonSchema | null =>
application_v31_schema(true)(components)({})(meta);
return {
const schema = ({
version: "3.1",
components,
schemas: metadatas.map((meta, i) => {
Expand All @@ -77,6 +78,7 @@ export namespace JsonApplicationProgrammer {
});
return schema;
}),
};
} satisfies Omit<IJsonApplication<"3.1">, typeof IJSONTag>); // check types before as assertion
return schema as IJsonApplication<"3.1">;
};
}
12 changes: 8 additions & 4 deletions src/schemas/json/IJsonApplication.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type { OpenApi, OpenApiV3 } from "@samchon/openapi";

export type IJsonApplication<Version extends "3.0" | "3.1" = "3.1"> =
Version extends "3.0" ? IJsonApplication.IV3_0 : IJsonApplication.IV3_1;
export declare const tag: unique symbol;

export type IJsonApplication<Version extends "3.0" | "3.1" = "3.1", Types = unknown[]> =
Version extends "3.0" ? IJsonApplication.IV3_0<Types> : IJsonApplication.IV3_1<Types>;
export namespace IJsonApplication {
export interface IV3_0 {
export interface IV3_0<Types = unknown[]> {
[tag]: Types;
version: "3.0";
schemas: OpenApiV3.IJsonSchema[];
components: OpenApiV3.IComponents;
}
export interface IV3_1 {
export interface IV3_1<Types = unknown[]> {
[tag]: Types;
version: "3.1";
components: OpenApi.IComponents;
schemas: OpenApi.IJsonSchema[];
Expand Down
Loading