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

[idp-1683] Fix relative path #4

Merged
merged 2 commits into from
Jun 14, 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
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
PrincessMadMath marked this conversation as resolved.
Show resolved Hide resolved
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