Skip to content

Commit

Permalink
wip openapi generation test
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Oct 13, 2023
1 parent cb5772d commit e3f404b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
34 changes: 32 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@semantic-release/git": "10.0.1",
"cpy-cli": "^4.2.0",
"eslint-config-custom": "*",
"mock-fs": "^5.2.0",
"prettier": "^2.7.1",
"semantic-release": "19.0.5",
"turbo": "latest"
Expand All @@ -34,7 +35,6 @@
"npm": ">=7.0.0",
"node": ">=14.0.0"
},
"dependencies": {},
"packageManager": "yarn@1.22.17",
"repository": "https://github.com/seamapi/nextlove"
}
2 changes: 1 addition & 1 deletion packages/nextlove/src/generators/generate-openapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ParameterObject,
} from "openapi3-ts/oas31"
import { SetupParams } from "../../types"
import chalk from "chalk"
import { z } from "zod"
import { parseRoutesInPackage } from "../lib/parse-routes-in-package"
import { embedSchemaReferences } from "./embed-schema-references"
Expand Down Expand Up @@ -79,6 +78,7 @@ interface GenerateOpenAPIOpts {
* "build:openapi" package.json script.
*/
export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
const chalk = (await import("chalk")).default
const { outputFile, tags = [] } = opts

const filepathToRouteFn = await parseRoutesInPackage(opts)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import chalk from "chalk"
import path from "node:path"
import { globby } from "globby"
import { RouteSpec, SetupParams } from "../../types"
import { defaultMapFilePathToHTTPRoute } from "./default-map-file-path-to-http-route"

Expand All @@ -17,6 +15,8 @@ export const parseRoutesInPackage = async (opts: {
apiPrefix?: string
mapFilePathToHTTPRoute?: (file_path: string) => string
}): Promise<Map<string, RouteInfo>> => {
const chalk = (await import("chalk")).default
const globby = (await import("globby")).globby
const {
packageDir,
pathGlob = "/pages/api/**/*.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import test from "ava"
import { generateOpenAPI } from "../../src/generators/generate-openapi"
// import mockFs from "mock-fs"

// test.before((t) => {
// // Setup mock file system
// mockFs({
// "/testdir": {
// "package.json": "",
// "src/pages": {
// "health.ts": `

// `
// }
// },
// })
// })

// test.after.always((t) => {
// // Restore file system
// mockFs.restore()
// })

test("should generate openapi", async (t) => {
const openapiFile = await generateOpenAPI({
packageDir: "../../apps/example-todo-app",
})

console.log(openapiFile)
})
11 changes: 8 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3091,7 +3091,7 @@ eslint-plugin-jsx-a11y@^6.5.1:
object.fromentries "^2.0.6"
semver "^6.3.0"

eslint-plugin-nextlove@*, "eslint-plugin-nextlove@file:/Users/pawelstepniak/Desktop/programming/seam/nextlove/packages/eslint-plugin":
eslint-plugin-nextlove@*, "eslint-plugin-nextlove@file:/Users/seve/workspace/seam/nextlove/packages/eslint-plugin":
version "0.0.1"
resolved "file:packages/eslint-plugin"
dependencies:
Expand Down Expand Up @@ -3378,7 +3378,7 @@ esutils@^2.0.2, esutils@^2.0.3:
resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

"example-todo-app@file:/Users/pawelstepniak/Desktop/programming/seam/nextlove/apps/example-todo-app":
"example-todo-app@file:/Users/seve/workspace/seam/nextlove/apps/example-todo-app":
version "0.1.0"
resolved "file:apps/example-todo-app"
dependencies:
Expand Down Expand Up @@ -5672,6 +5672,11 @@ mkdirp@1.0.4:
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mock-fs@^5.2.0:
version "5.2.0"
resolved "https://registry.npmjs.org/mock-fs/-/mock-fs-5.2.0.tgz"
integrity sha512-2dF2R6YMSZbpip1V1WHKGLNjr/k48uQClqMVb5H3MOvwc9qhYis3/IWbj02qIg/Y8MDXKFF4c5v0rxx2o6xTZw==

modify-values@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz"
Expand Down Expand Up @@ -5794,7 +5799,7 @@ nextjs-server-modules@^2.1.0:
serve-handler "^6.1.3"
yargs "^17.3.1"

nextlove@*, "nextlove@file:/Users/pawelstepniak/Desktop/programming/seam/nextlove/packages/nextlove":
nextlove@*, "nextlove@file:/Users/seve/workspace/seam/nextlove/packages/nextlove":
version "2.7.0"
resolved "file:packages/nextlove"
dependencies:
Expand Down

0 comments on commit e3f404b

Please sign in to comment.