ilokesto

응답 추론

Typed OpenAPI call에서 ResponsePromise는 inferred JSON type을 갖습니다.

const user = await api
  .get('/users/{id}', {
    params: { path: { id: '42' } },
  })
  .json();

user는 operation response content에서 추론됩니다.

우선 응답 순서

InferJson은 다음 순서로 JSON response content를 선택합니다.

  1. 200
  2. 201
  3. 204
  4. default

JSON response content를 찾지 못하면 inferred type은 unknown으로 fallback합니다.

미디어 타입

JSON content에는 application/json과 custom +json media type 같은 JSON-like suffix가 포함됩니다.

safe 결과

safe도 success branch의 data에 같은 inference를 사용합니다.

const result = await api.safe.get('/users/{id}', {
  params: { path: { id: '42' } },
});

if (result.ok) {
  result.data;
}

목차