Initial commit
This commit is contained in:
36
lib/api-spec/openapi.yaml
Normal file
36
lib/api-spec/openapi.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
# Do not change the title, if the title changes, the import paths will be broken
|
||||
title: Api
|
||||
version: 0.1.0
|
||||
description: API specification
|
||||
servers:
|
||||
- url: /api
|
||||
description: Base API path
|
||||
tags:
|
||||
- name: health
|
||||
description: Health operations
|
||||
paths:
|
||||
/healthz:
|
||||
get:
|
||||
operationId: healthCheck
|
||||
tags: [health]
|
||||
summary: Health check
|
||||
description: Returns server health status
|
||||
responses:
|
||||
"200":
|
||||
description: Healthy
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/HealthStatus"
|
||||
components:
|
||||
schemas:
|
||||
HealthStatus:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
|
||||
69
lib/api-spec/orval.config.ts
Normal file
69
lib/api-spec/orval.config.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { defineConfig, InputTransformerFn } from "orval";
|
||||
import path from "path";
|
||||
|
||||
const root = path.resolve(__dirname, "..", "..");
|
||||
const apiClientReactSrc = path.resolve(root, "lib", "api-client-react", "src");
|
||||
const apiZodSrc = path.resolve(root, "lib", "api-zod", "src");
|
||||
|
||||
// Our exports make assumptions about the title of the API being "Api" (i.e. generated output is `api.ts`).
|
||||
const titleTransformer: InputTransformerFn = (config) => {
|
||||
config.info ??= {};
|
||||
config.info.title = "Api";
|
||||
|
||||
return config;
|
||||
};
|
||||
|
||||
export default defineConfig({
|
||||
"api-client-react": {
|
||||
input: {
|
||||
target: "./openapi.yaml",
|
||||
override: {
|
||||
transformer: titleTransformer,
|
||||
},
|
||||
},
|
||||
output: {
|
||||
workspace: apiClientReactSrc,
|
||||
target: "generated",
|
||||
client: "react-query",
|
||||
mode: "split",
|
||||
baseUrl: "/api",
|
||||
clean: true,
|
||||
prettier: true,
|
||||
override: {
|
||||
fetch: {
|
||||
includeHttpResponseReturnType: false,
|
||||
},
|
||||
mutator: {
|
||||
path: path.resolve(apiClientReactSrc, "custom-fetch.ts"),
|
||||
name: "customFetch",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
zod: {
|
||||
input: {
|
||||
target: "./openapi.yaml",
|
||||
override: {
|
||||
transformer: titleTransformer,
|
||||
},
|
||||
},
|
||||
output: {
|
||||
workspace: apiZodSrc,
|
||||
client: "zod",
|
||||
target: "generated",
|
||||
schemas: { path: "generated/types", type: "typescript" },
|
||||
mode: "split",
|
||||
clean: true,
|
||||
prettier: true,
|
||||
override: {
|
||||
zod: {
|
||||
coerce: {
|
||||
query: ['boolean', 'number', 'string'],
|
||||
param: ['boolean', 'number', 'string'],
|
||||
},
|
||||
},
|
||||
useDates: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
11
lib/api-spec/package.json
Normal file
11
lib/api-spec/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@workspace/api-spec",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"codegen": "orval --config ./orval.config.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"orval": "^8.5.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user