Skip to content

Commit 7052ac5

Browse files
PrincessMadMathMathieu Gamache
andauthored
[idp-1683] Fix relative path (#4)
* Fix relative path + try improve debug * Cleanup --------- Co-authored-by: Mathieu Gamache <[email protected]>
1 parent b9fbfc3 commit 7052ac5

File tree

6 files changed

+111
-3
lines changed

6 files changed

+111
-3
lines changed

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Debug Create-Schemas",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"program": "${workspaceFolder}/packages/create-schemas/src/bin.ts",
15+
"args": [
16+
"${workspaceFolder}\\debug\\v1.yaml",
17+
"-o ${workspaceFolder}\\debug\\schema.ts"
18+
],
19+
"stopOnEntry": false,
20+
"outputCapture": "std",
21+
}
22+
]
23+
}

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ create-schemas [path_to_openapi_documents] -o [output-path]
3232

3333
### Debug
3434

35-
In VSCode, after building the package you can debug it by using the command `debug` inside `packages/create-schemas/package.json`.
35+
1. Execute the command `pnpm dev` to have hot-reload of changes
36+
2. Add breakpoints
37+
3. In VSCode use the launch settings `Debug Create-Schemas`
38+
3639

3740
## How to release packages
3841

debug/schema.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
export interface paths {
2+
"/good-vibes-points/{userId}": {
3+
parameters: {
4+
query?: never;
5+
header?: never;
6+
path?: never;
7+
cookie?: never;
8+
};
9+
/** Get the current number of good vibe for a user */
10+
get: operations["GetGoodVibesPoint"];
11+
put?: never;
12+
post?: never;
13+
delete?: never;
14+
options?: never;
15+
head?: never;
16+
patch?: never;
17+
trace?: never;
18+
};
19+
}
20+
export type webhooks = Record<string, never>;
21+
export interface components {
22+
schemas: {
23+
GetGoodVibePointsResult: {
24+
/** Format: int32 */
25+
point: number;
26+
};
27+
ProblemDetails: {
28+
type?: string | null;
29+
title?: string | null;
30+
/** Format: int32 */
31+
status?: number | null;
32+
detail?: string | null;
33+
instance?: string | null;
34+
[key: string]: unknown;
35+
};
36+
};
37+
responses: never;
38+
parameters: never;
39+
requestBodies: never;
40+
headers: never;
41+
pathItems: never;
42+
}
43+
export type $defs = Record<string, never>;
44+
export interface operations {
45+
GetGoodVibesPoint: {
46+
parameters: {
47+
query?: never;
48+
header?: never;
49+
path: {
50+
userId: string;
51+
};
52+
cookie?: never;
53+
};
54+
requestBody?: never;
55+
responses: {
56+
/** @description Success */
57+
200: {
58+
headers: {
59+
[name: string]: unknown;
60+
};
61+
content: {
62+
"application/json": components["schemas"]["GetGoodVibePointsResult"];
63+
};
64+
};
65+
/** @description Bad Request */
66+
400: {
67+
headers: {
68+
[name: string]: unknown;
69+
};
70+
content: {
71+
"application/json": components["schemas"]["ProblemDetails"];
72+
};
73+
};
74+
};
75+
};
76+
}
77+
export type GetGoodVibePointsResult = components["schemas"]["GetGoodVibePointsResult"];
78+
export type ProblemDetails = components["schemas"]["ProblemDetails"];
79+
80+
export type Endpoints = keyof paths;
File renamed without changes.

packages/create-schemas/src/argsHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function getOutputPath(args: string[]): string {
99
}
1010
});
1111

12-
return flags.output || "openapi-types.ts";
12+
return (flags.output || "openapi-types.ts").trim();
1313
}
1414

1515
export function getOpenApiTsOptionForArgs(args: string[]): OpenAPITSOptions {

packages/create-schemas/src/openapiTypescriptHelper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import openapiTS, { astToString, type OpenAPITSOptions } from "openapi-typescrip
22
import { generateExportEndpointsTypeDeclaration, generateExportSchemaTypeDeclaration, getSchemaNames } from "./astHelper.ts";
33

44
export async function generateSchemas(openApiPath: string, outputPath: string, openApiTsOptions: OpenAPITSOptions): Promise<string> {
5+
const CWD = new URL(`file://${process.cwd()}/`);
6+
57
// Create a TypeScript AST from the OpenAPI schema
6-
const ast = await openapiTS(new URL(openApiPath), openApiTsOptions);
8+
const ast = await openapiTS(new URL(openApiPath, CWD), openApiTsOptions);
79

810
// Find the node where all the DTOs are defined, and extract their names
911
const schemaNames = getSchemaNames(ast);

0 commit comments

Comments
 (0)