Skip to content

Commit

Permalink
Merge pull request #8784 from hicommonwealth/rotorsoft/openapi-generator
Browse files Browse the repository at this point in the history
Creates api-client generator
  • Loading branch information
Rotorsoft authored Aug 9, 2024
2 parents 46ce1d5 + 89e8298 commit 58b7e86
Show file tree
Hide file tree
Showing 20 changed files with 11,209 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libs/adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"redis": "4.2.0",
"rollbar": "^2.6.1",
"sequelize": "^6.32.1",
"trpc-openapi": "1.1.2",
"trpc-swagger": "^1.2.6",
"typescript-logging": "^0.6.4",
"zod": "^3.22.4"
},
Expand Down
27 changes: 20 additions & 7 deletions libs/adapters/src/trpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
type GenerateOpenApiDocumentOptions,
type OpenApiMeta,
type OpenApiRouter,
} from 'trpc-openapi';
} from 'trpc-swagger';
import { ZodSchema, ZodUndefined, z } from 'zod';
import { config } from '../config';

Expand Down Expand Up @@ -136,9 +136,16 @@ export const command = <
.meta({
openapi: {
method: 'POST',
path: `/${tag.toLowerCase()}/{id}/${factory.name}`,
path: `/${factory.name}/{id}`,
tags: [tag],
headers: [{ name: 'address_id' }],
headers: [
{
in: 'header',
name: 'address_id',
required: true,
schema: { type: 'string' },
},
],
protect: md.secure,
},
})
Expand Down Expand Up @@ -181,7 +188,7 @@ export const event = <
.meta({
openapi: {
method: 'POST',
path: `/${tag.toLowerCase()}/${factory.name}`,
path: `/${factory.name}`,
tags: [tag],
},
})
Expand All @@ -205,14 +212,20 @@ export const query = <Input extends ZodSchema, Output extends ZodSchema>(
factory: () => QueryMetadata<Input, Output>,
) => {
const md = factory();
//const input = md.input.extend({ address_id: z.string().optional() });
return trpc.procedure
.meta({
openapi: {
method: 'GET',
path: `/${Tag.Query.toLowerCase()}/${factory.name}`,
path: `/${factory.name}`,
tags: [Tag.Query],
headers: [{ name: 'address_id' }],
headers: [
{
in: 'header',
name: 'address_id',
required: false,
schema: { type: 'string' },
},
],
},
protect: md.secure,
})
Expand Down
7 changes: 7 additions & 0 deletions libs/api-client/openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.7.0"
}
}
34 changes: 34 additions & 0 deletions libs/api-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@hicommonwealth/api-client",
"version": "1.0.0",
"type": "module",
"description": "Common Client Proxy",
"files": [
"build"
],
"exports": {
".": {
"default": "./build/index.js",
"devmode": "./src/index.ts"
}
},
"scripts": {
"build": "tsc -b ./tsconfig.build.json",
"clean": "rm -rf build && rm -rf coverage",
"run-test": "tsx ./test/index.ts",
"check-types": "tsc --noEmit",
"generate-client": "openapi-generator-cli generate -i http://localhost:8080/api/v1/openapi.json -g typescript-axios -o ./src --skip-validate-spec"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.3.4",
"moment": "^2.23.0"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.13.4",
"@types/moment": "^2.13.0",
"tsx": "^4.7.2"
}
}
4 changes: 4 additions & 0 deletions libs/api-client/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist
1 change: 1 addition & 0 deletions libs/api-client/src/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
23 changes: 23 additions & 0 deletions libs/api-client/src/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
8 changes: 8 additions & 0 deletions libs/api-client/src/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gitignore
.npmignore
api.ts
base.ts
common.ts
configuration.ts
git_push.sh
index.ts
1 change: 1 addition & 0 deletions libs/api-client/src/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.7.0
Loading

0 comments on commit 58b7e86

Please sign in to comment.