Skip to content

Commit

Permalink
Allow to add a dot in query parameters (airtasker#1370)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thodin3 committed May 4, 2021
1 parent 03b3062 commit 9a025c1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EndpointWithQueryParams {
@queryParams
queryParams: {
country: String;
postcode?: String;
"post.code"?: String;
}
) {}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/generators/openapi2/openapi2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe("OpenAPI 2 generator", () => {
type: expect.anything()
},
{
name: "postcode",
name: "post.code",
in: "query",
required: false,
type: expect.anything()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\\": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EndpointWithQueryParams {
@queryParams
queryParams: {
country: String;
postcode?: String;
"post.code"?: String;
}
) {}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/generators/openapi3/openapi3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe("OpenAPI 3 generator", () => {
schema: expect.anything()
},
{
name: "postcode",
name: "post.code",
in: "query",
required: false,
schema: expect.anything()
Expand Down
1 change: 1 addition & 0 deletions lib/src/parsers/__spec-examples__/query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class QueryParamsClass {
objectProp: string;
};
arrayProperty: string[];
"property.with.dots": string;
},
@queryParams
interfaceQueryParams: IQueryParams,
Expand Down
11 changes: 10 additions & 1 deletion lib/src/parsers/query-params-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -112,6 +112,15 @@ 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", () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/parsers/query-params-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ function extractQueryParamName(
propertySignature: PropertySignature
): Result<string, ParserError> {
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()
Expand Down

0 comments on commit 9a025c1

Please sign in to comment.