Skip to content

Commit

Permalink
use template tags instead of static env
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailkarsli committed Dec 4, 2024
1 parent 9922598 commit ce90157
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .env.example

This file was deleted.

Binary file modified bun.lockb
Binary file not shown.
File renamed without changes.
4 changes: 2 additions & 2 deletions dist/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"openapi": "3.0.3",
"info": {
"title": "Lemmy API",
"version": "0.20.0-reports-combined.2"
"version": "{{LEMMY_VERSION}}"
},
"servers": [
{
"url": "https://lemy.lol/api/v3"
"url": "https://{{LEMMY_INSTANCE}}/api/v3"
}
],
"security": [
Expand Down
4 changes: 2 additions & 2 deletions dist/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
openapi: 3.0.3
info:
title: Lemmy API
version: 0.20.0-reports-combined.2
version: "{{LEMMY_VERSION}}"
servers:
- url: https://lemy.lol/api/v3
- url: https://{{LEMMY_INSTANCE}}/api/v3
security:
- bearerAuth: []
externalDocs:
Expand Down
13 changes: 7 additions & 6 deletions scripts/extract-types.ts → extract-types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { VERSION } from "../lemmy-js-client/src/other_types.ts";
import { VERSION } from "./lemmy-js-client/src/other_types.ts";
import type { OpenAPIV3 } from "openapi-types";
import oxc, { type TSTypeParameterInstantiation } from "oxc-parser";
import { createIs } from "typia";
import { stringify as YAMLStringify } from "yaml";
import { recursiveFind, toPascalCase } from "../utils.ts";
import { recursiveFind, toPascalCase } from "./utils.ts";

const sourceText = await Bun.file("lemmy-js-client/src/http.ts").text();
const parsed = await oxc.parseAsync(sourceText, { sourceFilename: "http.ts", sourceType: "module" });
const parsed = await oxc.parseAsync("http.ts", sourceText, { sourceType: "module" });
await Bun.write("tmp/program.json", JSON.stringify(parsed, null, 2));

interface LemmyMethod {
Expand Down Expand Up @@ -95,7 +95,7 @@ export const components = application<[${imports.join(", ")}], "3.0">().componen
`;
await Bun.write("tmp/components.ts", typesFile);
// @ts-ignore it does not exists initially
const components = await import("../tmp/components.ts");
const components = await import("./tmp/components.ts");
const paths: OpenAPIV3.PathsObject = {};
const tags = new Set<string>();

Expand Down Expand Up @@ -156,9 +156,9 @@ const schema = {
openapi: "3.0.3",
info: {
title: "Lemmy API",
version: process.env.LEMMY_VERSION || "0.0.1",
version: "{{LEMMY_VERSION}}",
},
servers: process.env.LEMMY_URL ? [{ url: `${process.env.LEMMY_URL}/api/${VERSION}` }] : undefined,
servers: [{ url: `https://{{LEMMY_INSTANCE}}/api/${VERSION}` }],
security: [{ bearerAuth: [] }],
externalDocs: {
description: "Official Lemmy documentation",
Expand Down Expand Up @@ -196,3 +196,4 @@ removeNullTypes(schema.components.schemas);

await Bun.write("dist/openapi.json", JSON.stringify(schema, null, 2));
await Bun.write("dist/openapi.yaml", YAMLStringify(schema));
console.info("OpenAPI schema generated and saved to dist/openapi.json and dist/openapi.yaml");
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"module": "index.ts",
"type": "module",
"scripts": {
"generate": "bun run scripts/extract-types.ts"
"generate": "bun run extract-types.ts"
},
"dependencies": {
"@ryoppippi/unplugin-typia": "^1.0.7",
"openapi-types": "^12.1.3",
"oxc-parser": "^0.38.0",
"oxc-parser": "^0.39.0",
"typia": "~7.0.0",
"yaml": "^2.6.1",
"typescript": "~5.7.2",
Expand Down
2 changes: 1 addition & 1 deletion preload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { plugin } from "bun";
import UnpluginTypia from "@ryoppippi/unplugin-typia/bun";

plugin(UnpluginTypia({}));
plugin(UnpluginTypia({ cache: true, log: false }));

0 comments on commit ce90157

Please sign in to comment.