-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Given this test:
const expected = `function makeQueries(requests: Requests) {
return {
useGetPets: (status_in?: string[], options?: Omit<UseQueryOptions<Response<"getPets">, unknown, Response<"getPets">, ReturnType<QueryKeys["getPets"]>>, "queryKey" | "queryFn">): UseQueryResult<Response<"getPets">, unknown> => useQuery({ queryKey: queryKeys.getPets(status_in), queryFn: () => requests.getPets(status_in), ...options })
} as const;
}
`;
it("generates queries for every GET path with query parameters", () => {
const doc: OpenAPIV3.Document = {
openapi: "3.0.0",
info: {
title: "Test",
version: "1.0.0",
},
paths: {
"/pets": {
get: {
operationId: "getPets",
parameters: [
{
in: "query",
name: "status.in",
required: false,
schema: {
description: "Return the page of entries after this one.",
items: {
type: "string",
},
type: "array",
},
},
],
responses: {
default: {
description: "anything",
content: {
"application/json": {
schema: {
$ref: "",
},
},
},
},
},
},
},
},
};
const str = compile([makeQueries({} as any, doc.paths)]);
expect(str).toBe(expected);
});The generated output is:
function makeQueries(requests: Requests) {
return {
useGetPets: (status.in?: string[], options?: Omit<UseQueryOptions<Response<"getPets">, unknown, Response<"getPets">, ReturnType<QueryKeys["getPets"]>>, "queryKey" | "queryFn">): UseQueryResult<Response<"getPets">, unknown> => useQuery({ queryKey: queryKeys.getPets(status.in), queryFn: () => requests.getPets(status.in), ...options })
} as const;
}(Note the invalid parameter name status.in. This is valid in an OpenAPI spec.)
The period needs to be escaped using some strategy. I think ideally it would be transformed to something like:
status.in → statusIn
Metadata
Metadata
Assignees
Labels
No labels