Skip to content

[IDP-1765] Add client generation & Plugin system#16

Merged
tjosepo merged 12 commits intomainfrom
feature/idp-1765_client_generation
Jul 17, 2024
Merged

[IDP-1765] Add client generation & Plugin system#16
tjosepo merged 12 commits intomainfrom
feature/idp-1765_client_generation

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
heqianwang
heqianwang previously approved these changes Jul 16, 2024
@tjosepo tjosepo merged commit dde9873 into main Jul 17, 2024
@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