Skip to content

Commit

Permalink
[idp-1683] Fix relative path (#4)
Browse files Browse the repository at this point in the history
* Fix relative path + try improve debug

* Cleanup

---------

Co-authored-by: Mathieu Gamache <[email protected]>
  • Loading branch information
PrincessMadMath and Mathieu Gamache authored Jun 14, 2024
1 parent b9fbfc3 commit 7052ac5
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 3 deletions.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Create-Schemas",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/packages/create-schemas/src/bin.ts",
"args": [
"${workspaceFolder}\\debug\\v1.yaml",
"-o ${workspaceFolder}\\debug\\schema.ts"
],
"stopOnEntry": false,
"outputCapture": "std",
}
]
}
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ create-schemas [path_to_openapi_documents] -o [output-path]

### Debug

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


## How to release packages

Expand Down
80 changes: 80 additions & 0 deletions debug/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
export interface paths {
"/good-vibes-points/{userId}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Get the current number of good vibe for a user */
get: operations["GetGoodVibesPoint"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
}
export type webhooks = Record<string, never>;
export interface components {
schemas: {
GetGoodVibePointsResult: {
/** Format: int32 */
point: number;
};
ProblemDetails: {
type?: string | null;
title?: string | null;
/** Format: int32 */
status?: number | null;
detail?: string | null;
instance?: string | null;
[key: string]: unknown;
};
};
responses: never;
parameters: never;
requestBodies: never;
headers: never;
pathItems: never;
}
export type $defs = Record<string, never>;
export interface operations {
GetGoodVibesPoint: {
parameters: {
query?: never;
header?: never;
path: {
userId: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Success */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["GetGoodVibePointsResult"];
};
};
/** @description Bad Request */
400: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ProblemDetails"];
};
};
};
};
}
export type GetGoodVibePointsResult = components["schemas"]["GetGoodVibePointsResult"];
export type ProblemDetails = components["schemas"]["ProblemDetails"];

export type Endpoints = keyof paths;
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/create-schemas/src/argsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function getOutputPath(args: string[]): string {
}
});

return flags.output || "openapi-types.ts";
return (flags.output || "openapi-types.ts").trim();
}

export function getOpenApiTsOptionForArgs(args: string[]): OpenAPITSOptions {
Expand Down
4 changes: 3 additions & 1 deletion packages/create-schemas/src/openapiTypescriptHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import openapiTS, { astToString, type OpenAPITSOptions } from "openapi-typescrip
import { generateExportEndpointsTypeDeclaration, generateExportSchemaTypeDeclaration, getSchemaNames } from "./astHelper.ts";

export async function generateSchemas(openApiPath: string, outputPath: string, openApiTsOptions: OpenAPITSOptions): Promise<string> {
const CWD = new URL(`file://${process.cwd()}/`);

// Create a TypeScript AST from the OpenAPI schema
const ast = await openapiTS(new URL(openApiPath), openApiTsOptions);
const ast = await openapiTS(new URL(openApiPath, CWD), openApiTsOptions);

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

0 comments on commit 7052ac5

Please sign in to comment.