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-1765] Add client generation & Plugin system #16

Merged
merged 12 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
5 changes: 5 additions & 0 deletions .changeset/great-swans-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workleap/create-schemas": minor
---

[BREAKING] `outfile` option is now `outdir`
6 changes: 6 additions & 0 deletions .changeset/silver-moose-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@workleap/create-schemas": minor
---

Add `openapiFetchPlugin` plugin for client generation (requires `openapi-fetch`
package)
5 changes: 5 additions & 0 deletions .changeset/small-lizards-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workleap/create-schemas": minor
---

Add a new plugin system
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ yarn-error.log*
.idea

# project
dist
dist
8 changes: 8 additions & 0 deletions debug/create-schemas.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "@workleap/create-schemas";
import { openapiFetchPlugin } from "@workleap/create-schemas/plugins";

export default defineConfig({
input: "v1.yaml",
outdir: "src/codegen/v1",
plugins: [openapiFetchPlugin()]
});
16 changes: 6 additions & 10 deletions debug/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
{
"name": "debug",
"type": "module",
"private": true,
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"run": "create-schemas args1 args2"
"dev": "create-schemas"
},
"devDependencies": {
"@workleap/create-schemas": "workspace:*"
},
"keywords": [],
"author": "",
"license": "ISC"
"dependencies": {
"@workleap/create-schemas": "workspace:*",
"openapi-fetch": "^0.10.2"
}
}
14 changes: 14 additions & 0 deletions debug/src/code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createClient } from "./codegen/v1/client.ts";

const client = createClient({ baseUrl: "https://api.example.com" });

const { data, error } = await client.GET("/good-vibes-points/{userId}", { params: { path: { userId: "123" } } });

if (error) {
console.error(error.title);
console.error(error.detail);
}

if (data?.point) {
console.log(`You have ${data.point} good vibes points!`);
}
5 changes: 5 additions & 0 deletions debug/src/codegen/v1/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** Do not modify. This file has been generated by @workleap/create-schemas */
import type { paths } from "./types.ts";
import _createClient from "openapi-fetch";

export const createClient = _createClient as typeof _createClient<paths, "application/json">;
3 changes: 2 additions & 1 deletion debug/schema.ts → debug/src/codegen/v1/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** Do not modify. This file has been generated by @workleap/create-schemas */
export interface paths {
"/good-vibes-points/{userId}": {
parameters: {
Expand Down Expand Up @@ -74,7 +75,7 @@ export interface operations {
};
};
}

export type GetGoodVibePointsResult = components["schemas"]["GetGoodVibePointsResult"];
export type ProblemDetails = components["schemas"]["ProblemDetails"];

export type Endpoints = keyof paths;
116 changes: 58 additions & 58 deletions debug/v1.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
openapi: 3.0.1
info:
title: OfficeVice.GoodVibe.WebApi
version: '1.0'
title: OfficeVice.GoodVibe.WebApi
version: "1.0"
paths:
/good-vibes-points/{userId}:
get:
tags:
- GoodVibesBank
summary: Get the current number of good vibe for a user
operationId: GetGoodVibesPoint
parameters:
- name: userId
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/GetGoodVibePointsResult'
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetails'
/good-vibes-points/{userId}:
get:
tags:
- GoodVibesBank
summary: Get the current number of good vibe for a user
operationId: GetGoodVibesPoint
parameters:
- name: userId
in: path
required: true
schema:
type: string
format: uuid
responses:
"200":
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/GetGoodVibePointsResult"
"400":
description: Bad Request
content:
application/json:
schema:
$ref: "#/components/schemas/ProblemDetails"
components:
schemas:
GetGoodVibePointsResult:
required:
- point
type: object
properties:
point:
type: integer
format: int32
additionalProperties: false
ProblemDetails:
type: object
properties:
type:
type: string
nullable: true
title:
type: string
nullable: true
status:
type: integer
format: int32
nullable: true
detail:
type: string
nullable: true
instance:
type: string
nullable: true
additionalProperties: { }
schemas:
GetGoodVibePointsResult:
required:
- point
type: object
properties:
point:
type: integer
format: int32
additionalProperties: false
ProblemDetails:
type: object
properties:
type:
type: string
nullable: true
title:
type: string
nullable: true
status:
type: integer
format: int32
nullable: true
detail:
type: string
nullable: true
instance:
type: string
nullable: true
additionalProperties: {}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@workleap/eslint-plugin": "3.2.2",
"@workleap/typescript-configs": "3.0.2",
"eslint": "8.57.0",
"typescript": "5.4.5"
"typescript": "5.5.3"
},
"engines": {
"node": ">=18.0.0"
Expand Down
9 changes: 6 additions & 3 deletions packages/create-schemas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./plugins": {
"import": "./dist/plugins/index.js",
"types": "./dist/plugins/index.d.ts"
}
},
"scripts": {
Expand All @@ -34,7 +38,6 @@
"@workleap/tsup-configs": "3.0.6",
"eslint": "8.57.0",
"tsup": "8.1.0",
"typescript": "5.4.5",
"vitest": "1.6.0"
},
"engines": {
Expand All @@ -45,8 +48,8 @@
"chokidar": "3.6.0",
"commander": "12.1.0",
"kleur": "4.1.5",
"openapi-typescript": "7.0.0-rc.0",
heqianwang marked this conversation as resolved.
Show resolved Hide resolved
"typescript": "5.4.5",
"openapi-typescript": "7.0.2",
"typescript": "5.5.3",
"zod": "3.23.8"
}
}
59 changes: 0 additions & 59 deletions packages/create-schemas/src/astHelper.ts

This file was deleted.

Loading