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

OpenAPI 3.1: Header parameter as ref not generated properly #878

Open
luania opened this issue Jun 14, 2023 · 6 comments
Open

OpenAPI 3.1: Header parameter as ref not generated properly #878

luania opened this issue Jun 14, 2023 · 6 comments
Labels
bug Something isn't working openapi_31 OpenAPI 3.1 related issue

Comments

@luania
Copy link

luania commented Jun 14, 2023

What are the steps to reproduce this issue?

  1. goto https://orval.dev/playground
  2. generate from this openapi.yaml
openapi: 3.1.0
info:
  title: demo
  version: '1.0'
paths:
  /user:
    get:
      operationId: get-user
      parameters:
        - $ref: '#/components/parameters/MyHeader'
components:
  parameters:
    MyHeader:
      name: MyHeader
      in: header
      required: false
      schema:
        type: string

with config file:

{
  "output": {
    "client": "react-query",
    "target": "./src/generated/endpoints.ts",
    "mock": false,
    "headers": true
  },
  "input": {
    "target": "./schema.yaml"
  }
}

What happens?

Cannot find name 'MyHeaderParameter'.

this is the generated code:

/**
 * Generated by orval v6.11.0 🍺
 * Do not edit manually.
 * demo
 * OpenAPI spec version: 1.0
 */
import axios from "axios";
import type { AxiosRequestConfig, AxiosResponse, AxiosError } from "axios";
import { useQuery } from "@tanstack/react-query";
import type {
  UseQueryOptions,
  QueryFunction,
  UseQueryResult,
  QueryKey,
} from "@tanstack/react-query";
/**
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * Cannot find name 'MyHeaderParameter'
 */
export type GetUserHeaders = { MyHeader?: MyHeaderParameter };

type AwaitedInput<T> = PromiseLike<T> | T;

type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;

export const getUser = (
  headers?: GetUserHeaders,
  options?: AxiosRequestConfig
): Promise<AxiosResponse<unknown>> => {
  return axios.get(`/user`, {
    ...options,
    headers: { ...headers, ...options?.headers },
  });
};

export const getGetUserQueryKey = () => [`/user`];

export type GetUserQueryResult = NonNullable<
  Awaited<ReturnType<typeof getUser>>
>;
export type GetUserQueryError = AxiosError<unknown>;

export const useGetUser = <
  TData = Awaited<ReturnType<typeof getUser>>,
  TError = AxiosError<unknown>
>(
  headers?: GetUserHeaders,
  options?: {
    query?: UseQueryOptions<Awaited<ReturnType<typeof getUser>>, TError, TData>;
    axios?: AxiosRequestConfig;
  }
): UseQueryResult<TData, TError> & { queryKey: QueryKey } => {
  const { query: queryOptions, axios: axiosOptions } = options ?? {};

  const queryKey = queryOptions?.queryKey ?? getGetUserQueryKey();

  const queryFn: QueryFunction<Awaited<ReturnType<typeof getUser>>> = ({
    signal,
  }) => getUser(headers, { signal, ...axiosOptions });

  const query = useQuery<Awaited<ReturnType<typeof getUser>>, TError, TData>(
    queryKey,
    queryFn,
    queryOptions
  ) as UseQueryResult<TData, TError> & { queryKey: QueryKey };

  query.queryKey = queryKey;

  return query;
};

What were you expecting to happen?

MyHeaderParameter generated

What versions are you using?

6.11.0 & 6.16.0

@nate-vukovich
Copy link
Contributor

any status on this? is it even getting addressed?

@melloware melloware added the bug Something isn't working label Nov 3, 2023
@melloware

This comment was marked as outdated.

@melloware

This comment was marked as outdated.

@melloware
Copy link
Collaborator

melloware commented Nov 4, 2023

Its a bug in Swagger Validator you can try it here youself: https://apitools.dev/swagger-parser/online/

I opened a ticket: APIDevTools/swagger-parser#251

@melloware melloware added third-party Issue is in upstream third-party library and removed third-party Issue is in upstream third-party library labels Nov 12, 2023
@melloware
Copy link
Collaborator

melloware commented Nov 15, 2023

Actually i see its an OpenAPI 3.1.0 thing. If you delcare yours like this it will work

openapi: 3.0.3
info:
  title: demo
  version: '1.0'
paths:
  /user:
    get:
      operationId: get-user
      parameters:
        - name: MyHeader
          in: header
          required: false
          schema:
            type: string

@melloware melloware changed the title Header parameter not generated OpenAPI 3.1: Header parameter not generated Nov 15, 2023
@melloware melloware added the openapi_31 OpenAPI 3.1 related issue label Nov 15, 2023
@melloware
Copy link
Collaborator

It looks like it is if the Header is a REF its an issue.

@melloware melloware changed the title OpenAPI 3.1: Header parameter not generated OpenAPI 3.1: Header parameter as ref not generated properly Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi_31 OpenAPI 3.1 related issue
Projects
None yet
Development

No branches or pull requests

3 participants