-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #880: support multiple openapi versions generation.
- Loading branch information
Showing
73 changed files
with
2,250 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { INestiaConfig } from "@nestia/sdk"; | ||
import { INestApplication } from "@nestjs/common"; | ||
import { NestFactory } from "@nestjs/core"; | ||
|
||
import { ApplicationModule } from "./src/modules/ApplicationModule"; | ||
|
||
export const NESTIA_CONFIG: INestiaConfig = { | ||
input: async () => { | ||
const app: INestApplication = await NestFactory.create(ApplicationModule, { | ||
logger: false, | ||
}); | ||
return app; | ||
}, | ||
output: "src/api", | ||
swagger: { | ||
output: "swagger.json", | ||
openapi: "2.0", | ||
security: { | ||
bearer: { | ||
type: "apiKey", | ||
}, | ||
}, | ||
}, | ||
}; | ||
export default NESTIA_CONFIG; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { INestApplication } from "@nestjs/common"; | ||
import { NestFactory } from "@nestjs/core"; | ||
import { Singleton } from "tstl"; | ||
|
||
import { ApplicationModule } from "./modules/ApplicationModule"; | ||
|
||
export class Backend { | ||
public readonly application: Singleton<Promise<INestApplication>> = | ||
new Singleton(() => | ||
NestFactory.create(ApplicationModule, { logger: false }), | ||
); | ||
|
||
public async open(): Promise<void> { | ||
return (await this.application.get()).listen(37_000); | ||
} | ||
|
||
public async close(): Promise<void> { | ||
return (await this.application.get()).close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { HttpError } from "@nestia/fetcher"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type { IConnection } from "@nestia/fetcher"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type { Primitive } from "@nestia/fetcher"; |
204 changes: 204 additions & 0 deletions
204
test/features/openapi_v2/src/api/functional/articles/comments/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
/** | ||
* @packageDocumentation | ||
* @module api.functional.articles.comments | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
//================================================================ | ||
import type { IConnection, Resolved, Primitive } from "@nestia/fetcher"; | ||
import { PlainFetcher } from "@nestia/fetcher/lib/PlainFetcher"; | ||
import type { Format } from "typia/lib/tags/Format"; | ||
|
||
import type { IBbsComment } from "../../../structures/IBbsComment"; | ||
import type { IPage } from "../../../structures/IPage"; | ||
|
||
/** | ||
* @controller BbsCommentsController.index | ||
* @path GET /:section/articles/:articleId/comments | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
export async function index( | ||
connection: IConnection, | ||
section: string, | ||
articleId: string & Format<"uuid">, | ||
query: index.Query, | ||
): Promise<index.Output> { | ||
return PlainFetcher.fetch(connection, { | ||
...index.METADATA, | ||
template: index.METADATA.path, | ||
path: index.path(section, articleId, query), | ||
}); | ||
} | ||
export namespace index { | ||
export type Query = Resolved<IPage.IRequest>; | ||
export type Output = Primitive<IPage<IBbsComment>>; | ||
|
||
export const METADATA = { | ||
method: "GET", | ||
path: "/:section/articles/:articleId/comments", | ||
request: null, | ||
response: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
status: null, | ||
} as const; | ||
|
||
export const path = ( | ||
section: string, | ||
articleId: string & Format<"uuid">, | ||
query: index.Query, | ||
) => { | ||
const variables: URLSearchParams = new URLSearchParams(); | ||
for (const [key, value] of Object.entries(query as any)) | ||
if (undefined === value) continue; | ||
else if (Array.isArray(value)) | ||
value.forEach((elem: any) => variables.append(key, String(elem))); | ||
else variables.set(key, String(value)); | ||
const location: string = `/${encodeURIComponent(section ?? "null")}/articles/${encodeURIComponent(articleId ?? "null")}/comments`; | ||
return 0 === variables.size | ||
? location | ||
: `${location}?${variables.toString()}`; | ||
}; | ||
} | ||
|
||
/** | ||
* @controller BbsCommentsController.at | ||
* @path GET /:section/articles/:articleId/comments/:id | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
export async function at( | ||
connection: IConnection, | ||
section: string, | ||
articleId: string & Format<"uuid">, | ||
id: string & Format<"uuid">, | ||
): Promise<at.Output> { | ||
return PlainFetcher.fetch(connection, { | ||
...at.METADATA, | ||
template: at.METADATA.path, | ||
path: at.path(section, articleId, id), | ||
}); | ||
} | ||
export namespace at { | ||
export type Output = Primitive<IBbsComment>; | ||
|
||
export const METADATA = { | ||
method: "GET", | ||
path: "/:section/articles/:articleId/comments/:id", | ||
request: null, | ||
response: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
status: null, | ||
} as const; | ||
|
||
export const path = ( | ||
section: string, | ||
articleId: string & Format<"uuid">, | ||
id: string & Format<"uuid">, | ||
) => | ||
`/${encodeURIComponent(section ?? "null")}/articles/${encodeURIComponent(articleId ?? "null")}/comments/${encodeURIComponent(id ?? "null")}`; | ||
} | ||
|
||
/** | ||
* @controller BbsCommentsController.store | ||
* @path POST /:section/articles/:articleId/comments | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
export async function store( | ||
connection: IConnection, | ||
section: string, | ||
articleId: string & Format<"uuid">, | ||
input: store.Input, | ||
): Promise<store.Output> { | ||
return PlainFetcher.fetch( | ||
{ | ||
...connection, | ||
headers: { | ||
...connection.headers, | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
{ | ||
...store.METADATA, | ||
template: store.METADATA.path, | ||
path: store.path(section, articleId), | ||
}, | ||
input, | ||
); | ||
} | ||
export namespace store { | ||
export type Input = Primitive<IBbsComment.IStore>; | ||
export type Output = Primitive<IBbsComment>; | ||
|
||
export const METADATA = { | ||
method: "POST", | ||
path: "/:section/articles/:articleId/comments", | ||
request: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
response: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
status: null, | ||
} as const; | ||
|
||
export const path = (section: string, articleId: string & Format<"uuid">) => | ||
`/${encodeURIComponent(section ?? "null")}/articles/${encodeURIComponent(articleId ?? "null")}/comments`; | ||
} | ||
|
||
/** | ||
* @controller BbsCommentsController.update | ||
* @path PUT /:section/articles/:articleId/comments/:id | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
export async function update( | ||
connection: IConnection, | ||
section: string, | ||
articleId: string & Format<"uuid">, | ||
id: string & Format<"uuid">, | ||
input: update.Input, | ||
): Promise<update.Output> { | ||
return PlainFetcher.fetch( | ||
{ | ||
...connection, | ||
headers: { | ||
...connection.headers, | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
{ | ||
...update.METADATA, | ||
template: update.METADATA.path, | ||
path: update.path(section, articleId, id), | ||
}, | ||
input, | ||
); | ||
} | ||
export namespace update { | ||
export type Input = Primitive<IBbsComment.IStore>; | ||
export type Output = Primitive<IBbsComment>; | ||
|
||
export const METADATA = { | ||
method: "PUT", | ||
path: "/:section/articles/:articleId/comments/:id", | ||
request: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
response: { | ||
type: "application/json", | ||
encrypted: false, | ||
}, | ||
status: null, | ||
} as const; | ||
|
||
export const path = ( | ||
section: string, | ||
articleId: string & Format<"uuid">, | ||
id: string & Format<"uuid">, | ||
) => | ||
`/${encodeURIComponent(section ?? "null")}/articles/${encodeURIComponent(articleId ?? "null")}/comments/${encodeURIComponent(id ?? "null")}`; | ||
} |
7 changes: 7 additions & 0 deletions
7
test/features/openapi_v2/src/api/functional/articles/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @packageDocumentation | ||
* @module api.functional.articles | ||
* @nestia Generated by Nestia - https://github.com/samchon/nestia | ||
*/ | ||
//================================================================ | ||
export * as comments from "./comments"; |
Oops, something went wrong.