[BUG][typescript-fetch] runtime.ts does not compile with noUncheckedIndexedAccess since 7.26.0 (TS2345/TS2532)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 80/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- backend
Línea de trabajo
Empieza por modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache, la plantilla mencionada en la issue, e inspecciona los tres accesos indexados a las capturas de regex en decodeExtValue y parseHeaderParameters. Genera la spec mínima descrita en la issue y ejecuta su comprobación de TypeScript con --noUncheckedIndexedAccess. Se considera terminado cuando el runtime.ts generado compila con esa opción y conserva el comportamiento de análisis descrito.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Since 7.26.0 the generated runtime.ts no longer compiles in a project that enables the TypeScript compiler option noUncheckedIndexedAccess. The Content-Disposition parsing added in #24957 and #24974 reads regex capture groups by index without a guard, and under this option every indexed access has the type string | undefined.
runtime.ts(536,43): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
runtime.ts(552,22): error TS2532: Object is possibly 'undefined'.
runtime.ts(554,90): error TS2532: Object is possibly 'undefined'.
The three lines are:
return match ? decodeURIComponent(match[1]) : undefined; // decodeExtValue
const name = match[1].toLowerCase(); // parseHeaderParameters
params.set(name, match[2] !== undefined ? match[2].replace(/\\(.)/g, '$1') : match[3].trim()); // parseHeaderParameters
The generated client is compiled as part of the consuming project, so the project's compiler options apply to it. The runtime compiled cleanly under this option up to 7.25.0, so the update breaks the build of such projects.
openapi-generator version
Regression. 7.25.0 compiles. 7.26.0, 7.27.0 and 7.28.0-SNAPSHOT (build 20261111.130840-62) fail.
OpenAPI declaration file content or url
Any spec reproduces it, because the code is in the static runtime.
openapi: 3.0.3
info:
title: runtime strictness
version: 1.0.0
paths:
/ping:
get:
operationId: ping
responses:
'204':
description: No content
Generation Details
java -jar openapi-generator-cli.jar generate -i spec.yaml -g typescript-fetch -o out
npx -p [email protected] tsc --ignoreConfig --noEmit --strict --noUncheckedIndexedAccess \
--target es2020 --module esnext --moduleResolution bundler --lib es2020,dom out/runtime.ts
Steps to reproduce
- Generate with the spec and command above.
- Type-check
out/runtime.tswith thetsccommand above.
Expected: no errors, as with 7.25.0. Actual: the three errors above. Without --noUncheckedIndexedAccess the file compiles.
Related issues/PRs
- #24957 and #24974 added the code (feature request #24956). I found no existing report.
Suggest a fix
Guard the three accesses in typescript-fetch/runtime.mustache. The following compiles with and without the option and keeps the behaviour, because the groups in question always participate in a successful match:
return match?.[1] !== undefined ? decodeURIComponent(match[1]) : undefined;
const name = (match[1] ?? '').toLowerCase();
if (!params.has(name)) {
params.set(name, match[2] !== undefined ? match[2].replace(/\\(.)/g, '$1') : (match[3] ?? '').trim());
}
It may also be worth enabling noUncheckedIndexedAccess in the tsconfig.json of one typescript-fetch sample, so that CI catches this class of error.
- Lenguaje dominante
- Java
- Estrellas
- 26.9k
- Forks
- 7.8k
- Merge medio
- 2 d 10 h
- PR fusionados (30 d)
- 180
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de OpenAPITools/openapi-generator
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
OpenAPITools/openapi-generator#25640 ·
Los mantenedores suelen responder en 1 día
-
[BUG][JAVA] Deprecated properties only get @Deprecated on the getter (base, feign, native, microprofile)Posiblemente ocupada @Inf1mum la tomó hace 2 días. AbiertoIssue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
OpenAPITools/openapi-generator#25567 ·
Los mantenedores suelen responder en 1 día
-
[BUG][KOTLIN-SERVER] typeInfoAnnotation.mustache uses As.PROPERTY → discriminator property serialized twicePosiblemente ocupada @Inf1mum la tomó hace 9 días. AbiertoIssue: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
OpenAPITools/openapi-generator#25524 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[REQ][JAVA][resteasy] Support for Jackson 3 / useJackson3Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. AbiertoEnhancement: Feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
OpenAPITools/openapi-generator#25364 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
OpenAPITools/openapi-generator#25237 ·
Los mantenedores suelen responder en 1 día
Todos los issues de OpenAPITools/openapi-generator
Issues similares
-
bug emitter:client:csharp
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/typespec#12572 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
GCC 15.2: -Wcast-qual warning - cast discards const qualifier from pointer target type (H5trace.c)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 1 día
-
[Bug] RemotingHelper.connect swaps the socket send and receive buffer configurationPosiblemente ocupada @amalsaidov la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
needs-area-label
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
area/ai area/backend component/zeebe kind/task
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día