Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/npm-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ jobs:
npm_test:
if: "!contains(github.event.head_commit.message, 'skip ci')"
name: Run NPM lint
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 16
cache: "yarn"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/npm-semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
publish:
if: "!contains(github.event.head_commit.message, 'skip ci')"
name: Release
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ jobs:
npm_test:
if: "!contains(github.event.head_commit.message, 'skip ci')"
name: Run NPM Test
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 16
cache: "yarn"
Expand Down
2 changes: 1 addition & 1 deletion apps/example-todo-app/pages/api/todo/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const commonParams = z.object({
})

export const route_spec = checkRouteSpec({
methods: ["GET"],
methods: ["GET", "POST"],
auth: "auth_token",
commonParams,
jsonResponse: z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,56 @@ test("generateOpenAPI correctly parses nested object description", async (t) =>
t.is(testArrayDescription.items.description, "This is an object.")
t.is(testArrayDescription.items["x-title"], "Nested Object Description")
})

test("generateOpenAPI includes GET even when POST is defined", async (t) => {
const openapiJson = JSON.parse(
await generateOpenAPI({
packageDir: ".",
})
)

const methods = Object.keys(openapiJson.paths["/api/todo/list"])
t.is(2, methods.length)

// GET includes parameters
t.deepEqual(
{
name: "ids",
in: "query",
required: true,
schema: {
items: {
format: "uuid",
type: "string",
},
type: "array",
},
},
openapiJson.paths["/api/todo/list"].get.parameters[0]
)

t.falsy(openapiJson.paths["/api/todo/list"].get.requestBody)

// POST route has request body

t.deepEqual(
{
properties: {
ids: {
items: {
format: "uuid",
type: "string",
},
type: "array",
},
},
required: ["ids"],
type: "object",
},
openapiJson.paths["/api/todo/list"].post.requestBody.content[
"application/json"
].schema
)

t.falsy(openapiJson.paths["/api/todo/list"].post.parameters)
})
4 changes: 3 additions & 1 deletion packages/nextlove/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ if (argv._[0] === "generate-openapi") {
if (!argv["packageDir"]) throw new Error("Missing --packageDir")

if (argv["allowed-import-patterns"]) {
argv.allowedImportPatterns = Array.isArray(argv["allowed-import-patterns"]) ? argv["allowed-import-patterns"] : [argv["allowed-import-patterns"]]
argv.allowedImportPatterns = Array.isArray(argv["allowed-import-patterns"])
? argv["allowed-import-patterns"]
: [argv["allowed-import-patterns"]]
}

require("./dist/generators")
Expand Down
Loading