Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to add a dot in query parameters #1370

Merged
merged 2 commits into from
Apr 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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