From 3448666630c5382f120af691f0cc342a29877494 Mon Sep 17 00:00:00 2001 From: Thodin3 <30184721+Thodin3@users.noreply.github.com> Date: Tue, 13 Apr 2021 18:35:09 +0200 Subject: [PATCH 1/2] airtasker#1368 Allow to add a dot in query parameters --- .../openapi3/__snapshots__/openapi3.spec.ts.snap | 2 +- .../__spec-examples__/contract-with-query-params.ts | 2 +- lib/src/generators/openapi3/openapi3.spec.ts | 2 +- lib/src/parsers/__spec-examples__/query-params.ts | 1 + lib/src/parsers/query-params-parser.spec.ts | 12 +++++++++++- lib/src/parsers/query-params-parser.ts | 4 ++-- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/src/generators/openapi3/__snapshots__/openapi3.spec.ts.snap b/lib/src/generators/openapi3/__snapshots__/openapi3.spec.ts.snap index 28fd4c92c..83bec86d7 100644 --- a/lib/src/generators/openapi3/__snapshots__/openapi3.spec.ts.snap +++ b/lib/src/generators/openapi3/__snapshots__/openapi3.spec.ts.snap @@ -885,7 +885,7 @@ exports[`OpenAPI 3 generator query params endpoint with query params 1`] = ` } }, { - \\"name\\": \\"postcode\\", + \\"name\\": \\"post.code\\", \\"in\\": \\"query\\", \\"required\\": false, \\"schema\\": { diff --git a/lib/src/generators/openapi3/__spec-examples__/contract-with-query-params.ts b/lib/src/generators/openapi3/__spec-examples__/contract-with-query-params.ts index eeb2182cb..f22e8c082 100644 --- a/lib/src/generators/openapi3/__spec-examples__/contract-with-query-params.ts +++ b/lib/src/generators/openapi3/__spec-examples__/contract-with-query-params.ts @@ -21,7 +21,7 @@ class EndpointWithQueryParams { @queryParams queryParams: { country: String; - postcode?: String; + "post.code"?: String; } ) {} diff --git a/lib/src/generators/openapi3/openapi3.spec.ts b/lib/src/generators/openapi3/openapi3.spec.ts index 72e7275c3..fa8c0bda0 100644 --- a/lib/src/generators/openapi3/openapi3.spec.ts +++ b/lib/src/generators/openapi3/openapi3.spec.ts @@ -170,7 +170,7 @@ describe("OpenAPI 3 generator", () => { schema: expect.anything() }, { - name: "postcode", + name: "post.code", in: "query", required: false, schema: expect.anything() diff --git a/lib/src/parsers/__spec-examples__/query-params.ts b/lib/src/parsers/__spec-examples__/query-params.ts index 03e271d71..db8464b24 100644 --- a/lib/src/parsers/__spec-examples__/query-params.ts +++ b/lib/src/parsers/__spec-examples__/query-params.ts @@ -27,6 +27,7 @@ class QueryParamsClass { objectProp: string; }; arrayProperty: string[]; + "property.with.dots": string; }, @queryParams interfaceQueryParams: IQueryParams, diff --git a/lib/src/parsers/query-params-parser.spec.ts b/lib/src/parsers/query-params-parser.spec.ts index 7b0120116..938bc2f5e 100644 --- a/lib/src/parsers/query-params-parser.spec.ts +++ b/lib/src/parsers/query-params-parser.spec.ts @@ -26,7 +26,7 @@ describe("query params parser", () => { typeTable, lociTable ).unwrapOrThrow(); - expect(result).toHaveLength(7); + expect(result).toHaveLength(8); expect(result[0]).toStrictEqual({ description: undefined, examples: undefined, @@ -112,6 +112,16 @@ describe("query params parser", () => { }, optional: false }); + expect(result[7]).toStrictEqual({ + description: undefined, + examples: undefined, + name: "property.with.dots", + type: { + kind: TypeKind.STRING + }, + optional: false + }); + }); test("parses @queryParams as interface parameter", () => { diff --git a/lib/src/parsers/query-params-parser.ts b/lib/src/parsers/query-params-parser.ts index e2a44a7c8..433ea32b3 100644 --- a/lib/src/parsers/query-params-parser.ts +++ b/lib/src/parsers/query-params-parser.ts @@ -70,10 +70,10 @@ function extractQueryParamName( propertySignature: PropertySignature ): Result { const name = getPropertyName(propertySignature); - if (!/^[\w-]*$/.test(name)) { + if (!/^[\w-.]*$/.test(name)) { return err( new ParserError( - "@queryParams property name may only contain alphanumeric, underscore and hyphen characters", + "@queryParams property name may only contain alphanumeric, underscore, dot and hyphen characters", { file: propertySignature.getSourceFile().getFilePath(), position: propertySignature.getPos() From d0c4d123fec2afdd706c9a5e52c54eb5c2cc4899 Mon Sep 17 00:00:00 2001 From: Thodin3 <30184721+Thodin3@users.noreply.github.com> Date: Tue, 13 Apr 2021 18:46:38 +0200 Subject: [PATCH 2/2] airtasker#1368 Add tests for OASv2 --- lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap | 2 +- .../openapi2/__spec-examples__/contract-with-query-params.ts | 2 +- lib/src/generators/openapi2/openapi2.spec.ts | 2 +- lib/src/parsers/query-params-parser.spec.ts | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap b/lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap index de7ee3d18..8ac3d51a7 100644 --- a/lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap +++ b/lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap @@ -692,7 +692,7 @@ exports[`OpenAPI 2 generator query params endpoint with query params 1`] = ` \\"type\\": \\"string\\" }, { - \\"name\\": \\"postcode\\", + \\"name\\": \\"post.code\\", \\"in\\": \\"query\\", \\"required\\": false, \\"type\\": \\"string\\" diff --git a/lib/src/generators/openapi2/__spec-examples__/contract-with-query-params.ts b/lib/src/generators/openapi2/__spec-examples__/contract-with-query-params.ts index eeb2182cb..f22e8c082 100644 --- a/lib/src/generators/openapi2/__spec-examples__/contract-with-query-params.ts +++ b/lib/src/generators/openapi2/__spec-examples__/contract-with-query-params.ts @@ -21,7 +21,7 @@ class EndpointWithQueryParams { @queryParams queryParams: { country: String; - postcode?: String; + "post.code"?: String; } ) {} diff --git a/lib/src/generators/openapi2/openapi2.spec.ts b/lib/src/generators/openapi2/openapi2.spec.ts index 716f221f8..640a07029 100644 --- a/lib/src/generators/openapi2/openapi2.spec.ts +++ b/lib/src/generators/openapi2/openapi2.spec.ts @@ -152,7 +152,7 @@ describe("OpenAPI 2 generator", () => { type: expect.anything() }, { - name: "postcode", + name: "post.code", in: "query", required: false, type: expect.anything() diff --git a/lib/src/parsers/query-params-parser.spec.ts b/lib/src/parsers/query-params-parser.spec.ts index 938bc2f5e..c75346a24 100644 --- a/lib/src/parsers/query-params-parser.spec.ts +++ b/lib/src/parsers/query-params-parser.spec.ts @@ -121,7 +121,6 @@ describe("query params parser", () => { }, optional: false }); - }); test("parses @queryParams as interface parameter", () => {