Skip to content

Parameters containing "." are not properly escaped. #59

@pifantastic

Description

@pifantastic

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions