diff --git a/src/subcommands/path.ts b/src/subcommands/path.ts index 8e1293c..ca3cb3a 100644 --- a/src/subcommands/path.ts +++ b/src/subcommands/path.ts @@ -1,4 +1,4 @@ -import { dirname, relative } from 'path'; +import { dirname, join, relative } from 'path'; import { CliArg, CliExit, GlobalOptions, SubcommandGenerator, buildHelpFromOpts, parseCliArgs } from '../cli'; import { GenerationTask, logger } from '../generate'; import { argname, camelCase, capitalize, dashCase, description, getRootRef, singular } from '../lib'; @@ -192,6 +192,11 @@ export const getPathTasks = (options: PathGenerationOptions): GenerationTask[] = rootRef, ); const paramRefs = mapParamRefs(otherPathParams, dirname(filename), rootRef); + const relativeParams = relative(`src/paths/${normalizedBaseFilepath}`, 'src/components/parameters/'); + paramRefs.push( + { $ref: getRootRef(join(relativeParams, 'queryLimit.yml'), '#/components/parameters/QueryLimit', rootRef) }, + { $ref: getRootRef(join(relativeParams, 'queryOffset.yml'), '#/components/parameters/QueryOffset', rootRef) }, + ); tasks.push( { diff --git a/test/e2e.spec.ts b/test/e2e.spec.ts index 1df6c47..3a31ee1 100644 --- a/test/e2e.spec.ts +++ b/test/e2e.spec.ts @@ -357,6 +357,9 @@ describe('e2e.spec.ts', async () => { trimIndent`\ summary: "List users" description: "List users" + parameters: + - $ref: "#/components/parameters/QueryLimit" + - $ref: "#/components/parameters/QueryOffset" responses: "200": description: "Success" @@ -444,6 +447,8 @@ describe('e2e.spec.ts', async () => { description: "List photos" parameters: - $ref: "#/components/parameters/PathUserId" + - $ref: "#/components/parameters/QueryLimit" + - $ref: "#/components/parameters/QueryOffset" responses: "200": description: "Success" @@ -606,6 +611,9 @@ describe('e2e.spec.ts', async () => { trimIndent`\ summary: "List users" description: "List users" + parameters: + - $ref: "#/components/parameters/QueryLimit" + - $ref: "#/components/parameters/QueryOffset" responses: "200": description: "Success" @@ -693,6 +701,8 @@ describe('e2e.spec.ts', async () => { description: "List photos" parameters: - $ref: "#/components/parameters/PathUserId" + - $ref: "#/components/parameters/QueryLimit" + - $ref: "#/components/parameters/QueryOffset" responses: "200": description: "Success" @@ -1111,6 +1121,9 @@ describe('e2e.spec.ts', async () => { trimIndent`\ summary: List users description: List users + parameters: + - $ref: ../../components/parameters/queryLimit.yml + - $ref: ../../components/parameters/queryOffset.yml responses: "200": description: Success @@ -1203,6 +1216,8 @@ describe('e2e.spec.ts', async () => { description: List photos parameters: - $ref: ../../../../components/parameters/pathUserId.yml + - $ref: ../../../../components/parameters/queryLimit.yml + - $ref: ../../../../components/parameters/queryOffset.yml responses: "200": description: Success diff --git a/test/fixtures/e2e/gen1/src/paths/albums/get.yml b/test/fixtures/e2e/gen1/src/paths/albums/get.yml index 264f9c9..b442064 100644 --- a/test/fixtures/e2e/gen1/src/paths/albums/get.yml +++ b/test/fixtures/e2e/gen1/src/paths/albums/get.yml @@ -1,5 +1,8 @@ summary: "List albums" description: "List albums" +parameters: + - $ref: "../../components/parameters/queryLimit.yml" + - $ref: "../../components/parameters/queryOffset.yml" responses: "200": description: "Success" diff --git a/test/fixtures/e2e/gen1/src/paths/albums/{albumId}/songs/get.yml b/test/fixtures/e2e/gen1/src/paths/albums/{albumId}/songs/get.yml index ee86c50..760a39a 100644 --- a/test/fixtures/e2e/gen1/src/paths/albums/{albumId}/songs/get.yml +++ b/test/fixtures/e2e/gen1/src/paths/albums/{albumId}/songs/get.yml @@ -2,6 +2,8 @@ summary: "List songs" description: "List songs" parameters: - $ref: "../../../../components/parameters/pathAlbumId.yml" + - $ref: "../../../../components/parameters/queryLimit.yml" + - $ref: "../../../../components/parameters/queryOffset.yml" responses: "200": description: "Success" diff --git a/test/fixtures/e2e/gen2/src/paths/users/get.yml b/test/fixtures/e2e/gen2/src/paths/users/get.yml index c54ee4e..5826c98 100644 --- a/test/fixtures/e2e/gen2/src/paths/users/get.yml +++ b/test/fixtures/e2e/gen2/src/paths/users/get.yml @@ -1,5 +1,8 @@ summary: "List users" description: "List users" +parameters: + - $ref: "../../components/parameters/queryLimit.yml" + - $ref: "../../components/parameters/queryOffset.yml" responses: "200": description: "Success" diff --git a/test/fixtures/e2e/gen2/src/paths/users/{userId}/addresses/get.yml b/test/fixtures/e2e/gen2/src/paths/users/{userId}/addresses/get.yml index 10283f5..ba1238a 100644 --- a/test/fixtures/e2e/gen2/src/paths/users/{userId}/addresses/get.yml +++ b/test/fixtures/e2e/gen2/src/paths/users/{userId}/addresses/get.yml @@ -2,6 +2,8 @@ summary: "List addresses" description: "List addresses" parameters: - $ref: "../../../../components/parameters/pathUserId.yml" + - $ref: "../../../../components/parameters/queryLimit.yml" + - $ref: "../../../../components/parameters/queryOffset.yml" responses: "200": description: "Success" diff --git a/test/fixtures/spec/album-api.json b/test/fixtures/spec/album-api.json index c6a5c34..f72886b 100644 --- a/test/fixtures/spec/album-api.json +++ b/test/fixtures/spec/album-api.json @@ -27,6 +27,14 @@ "summary": "List albums", "description": "List albums", "operationId": "albumsGet", + "parameters": [ + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" + } + ], "responses": { "200": { "description": "Success", @@ -81,6 +89,12 @@ "parameters": [ { "$ref": "#/components/parameters/PathAlbumId" + }, + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" } ], "responses": { diff --git a/test/fixtures/spec/custom-multi.json b/test/fixtures/spec/custom-multi.json index 0a13775..0a3d54f 100644 --- a/test/fixtures/spec/custom-multi.json +++ b/test/fixtures/spec/custom-multi.json @@ -5,6 +5,14 @@ "get": { "summary": "from src/paths/users/get.yml", "description": "pluralName users", + "parameters": [ + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" + } + ], "responses": { "200": { "description": "Success", diff --git a/test/fixtures/spec/custom.json b/test/fixtures/spec/custom.json index 4b9cbfe..1d54d59 100644 --- a/test/fixtures/spec/custom.json +++ b/test/fixtures/spec/custom.json @@ -5,6 +5,14 @@ "get": { "summary": "from src/paths/albums/get.yml", "description": "pluralName albums", + "parameters": [ + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" + } + ], "responses": { "200": { "description": "Success", @@ -46,6 +54,12 @@ "parameters": [ { "$ref": "#/components/parameters/PathAlbumId" + }, + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" } ], "responses": { diff --git a/test/fixtures/spec/path-deep.json b/test/fixtures/spec/path-deep.json index c29ec68..72de07a 100644 --- a/test/fixtures/spec/path-deep.json +++ b/test/fixtures/spec/path-deep.json @@ -30,6 +30,12 @@ "parameters": [ { "$ref": "#/components/parameters/PathUserId" + }, + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" } ], "responses": { diff --git a/test/fixtures/spec/path.json b/test/fixtures/spec/path.json index feb1a05..40d080d 100644 --- a/test/fixtures/spec/path.json +++ b/test/fixtures/spec/path.json @@ -27,6 +27,14 @@ "summary": "List users", "description": "List users", "operationId": "usersGet", + "parameters": [ + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" + } + ], "responses": { "200": { "description": "Success", diff --git a/test/fixtures/spec/user-api.json b/test/fixtures/spec/user-api.json index 159bb24..830987e 100644 --- a/test/fixtures/spec/user-api.json +++ b/test/fixtures/spec/user-api.json @@ -109,6 +109,14 @@ "summary": "List users", "description": "List users", "operationId": "usersGet", + "parameters": [ + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" + } + ], "responses": { "200": { "description": "Success", @@ -166,6 +174,12 @@ "parameters": [ { "$ref": "#/components/parameters/PathUserId" + }, + { + "$ref": "#/components/parameters/QueryLimit" + }, + { + "$ref": "#/components/parameters/QueryOffset" } ], "responses": { diff --git a/test/path.spec.ts b/test/path.spec.ts index 7a31312..d795bb1 100644 --- a/test/path.spec.ts +++ b/test/path.spec.ts @@ -215,6 +215,9 @@ describe('path.spec.ts', async () => { trimIndent`\ summary: "List users" description: "List users" + parameters: + - $ref: "../../components/parameters/queryLimit.yml" + - $ref: "../../components/parameters/queryOffset.yml" responses: "200": description: "Success" @@ -490,6 +493,8 @@ describe('path.spec.ts', async () => { description: "List photos" parameters: - $ref: "../../../../components/parameters/pathUserId.yml" + - $ref: "../../../../components/parameters/queryLimit.yml" + - $ref: "../../../../components/parameters/queryOffset.yml" responses: "200": description: "Success"