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

fix: separated strings are not restored correctly #112

Merged
merged 6 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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 src/code-templates/_shared/MethodBody/PathParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export const generateUrlTemplateExpression = (
Object.keys(patternMap).forEach(pathParameterName => {
if (new RegExp(pathParameterName).test(replacedText)) {
const { text, escaped } = escapeText(patternMap[pathParameterName]);
const variableDeclaraText = escaped ? `params.parameter[${text}]` : `params.parameter.${text}`;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

replacedText = replacedText.replace(new RegExp(pathParameterName, "g"), variableDeclaraText);
const variableDeclareText = escaped ? `params.parameter[${text}]` : `params.parameter.${text}`;
replacedText = replacedText.replace(new RegExp(pathParameterName, "g"), variableDeclareText);
}
});
return replacedText === text ? undefined : replacedText;
Expand Down Expand Up @@ -111,7 +111,7 @@ export const generateUrlTemplateExpression = (
} else {
urlTemplate.push({
type: "string",
value: value.startsWith("/") ? value : "/" + value,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root cause

value: value,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ describe("PathParameter Test", () => {
expect(generate("/a/{b}/c/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c/`;" + EOL);
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}`;" + EOL);
expect(generate("/a/b/{c}/", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}/`;" + EOL);
expect(generate("/a/b/{c}.json", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}.json`;" + EOL);
expect(generate("/{a}.json/{a}.json/{a}.json", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}.json/${params.parameter.a}.json/${params.parameter.a}.json`;" + EOL);
expect(generate("/.json.{a}.json/{a}.json.{a}", [{ in: "path", name: "a", required: true }])).toBe("`/.json.${params.parameter.a}.json/${params.parameter.a}.json.${params.parameter.a}`;" + EOL);

expect(
generate("/{a}/{b}", [
Expand Down
5 changes: 5 additions & 0 deletions src/code-templates/_shared/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ describe("Utils", () => {
},
]);
});

test("multiSplitStringToArray", () => {
expect(Utils.multiSplitStringToArray("/{a}/b/{a}/c{a}/", ["{a}"])).toStrictEqual(["/", "{a}", "/b/", "{a}", "/c", "{a}", "/"]);
expect(Utils.multiSplitStringToArray("/a/b/{c}.json", ["{c}"])).toStrictEqual(["/a/b/", "{c}.json"]);
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,15 @@ export interface Response$createPublisherV2$Status$200 {
status?: string;
};
}
export interface Parameter$getBookById {
/** Author ID */
authorId: string;
/** Book ID */
bookId: string;
}
export interface Response$getBookById$Status$200 {
"application/json": Schemas.Book;
}
export type ResponseContentType$getBook = keyof Response$getBook$Status$200;
export interface Params$getBook {
parameter: Parameter$getBook;
Expand Down Expand Up @@ -1378,6 +1387,10 @@ export interface Params$createPublisherV2<T extends RequestContentType$createPub
};
requestBody: RequestBody$createPublisherV2[T];
}
export type ResponseContentType$getBookById = keyof Response$getBookById$Status$200;
export interface Params$getBookById {
parameter: Parameter$getBookById;
}
export type HttpMethod = "GET" | "PUT" | "POST" | "DELETE" | "OPTIONS" | "HEAD" | "PATCH" | "TRACE";
export interface ObjectLike {
[key: string]: any;
Expand All @@ -1390,14 +1403,15 @@ export interface QueryParameter {
export interface QueryParameters {
[key: string]: QueryParameter;
}
export type SuccessResponses = Response$getBook$Status$200 | Response$getDescription$Status$200 | Response$getAuthor$Status$200 | Response$getPublisher$Status$200 | Response$createPublisher$Status$200 | Response$createPublisherV2$Status$200;
export type SuccessResponses = Response$getBook$Status$200 | Response$getDescription$Status$200 | Response$getAuthor$Status$200 | Response$getPublisher$Status$200 | Response$createPublisher$Status$200 | Response$createPublisherV2$Status$200 | Response$getBookById$Status$200;
export namespace ErrorResponse {
export type getBook = void;
export type getDescription = void;
export type getAuthor = void;
export type getPublisher = void;
export type createPublisher = void;
export type createPublisherV2 = void;
export type getBookById = void;
}
export interface Encoding {
readonly contentType?: string;
Expand Down Expand Up @@ -1514,6 +1528,17 @@ export class Client<RequestOption> {
requestBodyEncoding: requestEncodings[params.headers["Content-Type"]]
}, option);
}
public async getBookById(params: Params$getBookById, option?: RequestOption): Promise<Response$getBookById$Status$200["application/json"]> {
const url = this.baseUrl + \`/author/author-\${params.parameter.authorId}.a.\${params.parameter.bookId}.b/book/\${params.parameter.bookId}.json\`;
const headers = {
Accept: "application/json"
};
return this.apiClient.request({
httpMethod: "GET",
url,
headers
}, option);
}
}
"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,15 @@ export interface Response$createPublisherV2$Status$200 {
status?: string;
};
}
export interface Parameter$getBookById {
/** Author ID */
authorId: string;
/** Book ID */
bookId: string;
}
export interface Response$getBookById$Status$200 {
"application/json": Schemas.Book;
}
export type ResponseContentType$getBook = keyof Response$getBook$Status$200;
export interface Params$getBook {
parameter: Parameter$getBook;
Expand Down Expand Up @@ -1389,6 +1398,10 @@ export interface Params$createPublisherV2<T extends RequestContentType$createPub
};
requestBody: RequestBody$createPublisherV2[T];
}
export type ResponseContentType$getBookById = keyof Response$getBookById$Status$200;
export interface Params$getBookById {
parameter: Parameter$getBookById;
}
export type HttpMethod = "GET" | "PUT" | "POST" | "DELETE" | "OPTIONS" | "HEAD" | "PATCH" | "TRACE";
export interface ObjectLike {
[key: string]: any;
Expand All @@ -1401,14 +1414,15 @@ export interface QueryParameter {
export interface QueryParameters {
[key: string]: QueryParameter;
}
export type SuccessResponses = Response$getBook$Status$200 | Response$getDescription$Status$200 | Response$getAuthor$Status$200 | Response$getPublisher$Status$200 | Response$createPublisher$Status$200 | Response$createPublisherV2$Status$200;
export type SuccessResponses = Response$getBook$Status$200 | Response$getDescription$Status$200 | Response$getAuthor$Status$200 | Response$getPublisher$Status$200 | Response$createPublisher$Status$200 | Response$createPublisherV2$Status$200 | Response$getBookById$Status$200;
export namespace ErrorResponse {
export type getBook = void;
export type getDescription = void;
export type getAuthor = void;
export type getPublisher = void;
export type createPublisher = void;
export type createPublisherV2 = void;
export type getBookById = void;
}
export interface Encoding {
readonly contentType?: string;
Expand Down Expand Up @@ -1524,6 +1538,17 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
requestBody: params.requestBody,
requestBodyEncoding: requestEncodings[params.headers["Content-Type"]]
}, option);
},
getBookById: (params: Params$getBookById, option?: RequestOption): Promise<Response$getBookById$Status$200["application/json"]> => {
const url = _baseUrl + \`/author/author-\${params.parameter.authorId}.a.\${params.parameter.bookId}.b/book/\${params.parameter.bookId}.json\`;
const headers = {
Accept: "application/json"
};
return apiClient.request({
httpMethod: "GET",
url,
headers
}, option);
}
};
};
Expand Down
26 changes: 26 additions & 0 deletions test/ref.access/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,29 @@ paths:
properties:
status:
type: string

/author/author-{authorId}.a.{bookId}.b/book/{bookId}.json:
parameters:
- name: authorId
in: path
required: true
description: Author ID
schema:
type: string
format: uuid
- name: bookId
in: path
required: true
description: Book ID
schema:
type: string
format: uuid
get:
operationId: getBookById
responses:
200:
description: Get Books
content:
application/json:
schema:
$ref: "#/components/schemas/Book"