Description
An OpenAPI schema that includes a const with newlines is not processed correctly. open-api-ts produces an invalid types.gen.ts.
For example, the following schema (at DEFAULT_INSTRUCTIONS):
{
"openapi": "3.1.0",
"info": {
"title": "app",
"version": "0.1.0"
},
"paths": {
"/api/constants/": {
"get": {
"summary": "Get Constants",
"description": "Get constants for the frontend",
"operationId": "get_constants_api_constants__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"properties": {
"DEFAULT_INSTRUCTIONS": {
"const": "First line.\n\nSecond line.\n\nPS: I love you."
}
},
"type": "object"
}
}
}
}
}
}
}
}
}
produces this invalid types.gen.ts file.
// This file is auto-generated by @hey-api/openapi-ts
export type GetConstantsApiConstantsGetResponse = ({
DEFAULT_INSTRUCTIONS?: "First line.
Second line.
PS: I love you.";
});
export type GetConstantsApiConstantsGetError = unknown;
This is invalid because a double-quote quoted string cannot contain newlines in TypeScript.

A fix for this could be using ` backtick characters, which are allowed to contain newlines in TypeScript, rather than " double quotes. If minimising changes to generated files is a goal, this could be done only for those const values which include newlines (leaving others to use double quotes).
Reproducible example or configuration
https://stackblitz.com/edit/hey-api-example-qyowue?file=src%2Fclient%2Ftypes.gen.ts
Description
An OpenAPI schema that includes a
constwith newlines is not processed correctly.open-api-tsproduces an invalidtypes.gen.ts.For example, the following schema (at DEFAULT_INSTRUCTIONS):
{ "openapi": "3.1.0", "info": { "title": "app", "version": "0.1.0" }, "paths": { "/api/constants/": { "get": { "summary": "Get Constants", "description": "Get constants for the frontend", "operationId": "get_constants_api_constants__get", "responses": { "200": { "description": "Successful Response", "content": { "application/json": { "schema": { "properties": { "DEFAULT_INSTRUCTIONS": { "const": "First line.\n\nSecond line.\n\nPS: I love you." } }, "type": "object" } } } } } } } } }produces this invalid
types.gen.tsfile.This is invalid because a double-quote quoted string cannot contain newlines in TypeScript.
A fix for this could be using
`backtick characters, which are allowed to contain newlines in TypeScript, rather than"double quotes. If minimising changes to generated files is a goal, this could be done only for those const values which include newlines (leaving others to use double quotes).Reproducible example or configuration
https://stackblitz.com/edit/hey-api-example-qyowue?file=src%2Fclient%2Ftypes.gen.ts