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

Conversation

tjosepo
Copy link
Member

@tjosepo tjosepo commented Jul 15, 2024

Description of changes

Plugin System

This pull-request adds a new plugin system to @workleap/create-schemas. Plugin lets users opt-in to specific features and extend the code generation. The plugin system is also meant to simplify the internals of @workleap/create-schemas, as we can use plugins internally.

The plugin system currently has three hooks, startBuild, transform and buildEnd.

---
title: Generation hooks
---
flowchart TB

    
    classDef parallel fill:#FFB3B3,color:black
    classDef sequential fill:#FFD2B3,color:black

    parallel(parallel):::parallel 
    sequential(sequential):::sequential 

    subgraph generate
        direction TB
        gen_A(startBuild):::parallel 
        --> gen_B(transform):::sequential
        --> gen_C(buildEnd):::parallel
    end

    A[start] --> B(resolveConfig) --> generate  --> E[write files]
Loading

Client plugin

Adds a client plugin called openapiFetchPlugin. This plugin re-exports openapi-fetch.

Config:

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()]
});

Usage

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!`);
}

Breaking changes

  • outfile is now outdir. This change is required to allow the tool to output more than one file.

Additional checks

  • Updated the documentation of the project to reflect the changes
    • No, but soon. Next pull-request will include documentation.
  • Added new tests that cover the code changes

@tjosepo tjosepo requested a review from a team as a code owner July 15, 2024 18:50
packages/create-schemas/tests/e2e.test.ts Outdated Show resolved Hide resolved
packages/create-schemas/tests/e2e.test.ts Outdated Show resolved Hide resolved
packages/create-schemas/package.json Show resolved Hide resolved
packages/create-schemas/src/plugins/types-plugin.ts Outdated Show resolved Hide resolved
@tjosepo tjosepo merged commit dde9873 into main Jul 17, 2024
2 checks passed
@github-actions github-actions bot mentioned this pull request Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants