Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Generating code and running TSC errors with TS2742 #118

Open
sourceful-mia opened this issue May 20, 2024 · 1 comment
Open

Generating code and running TSC errors with TS2742 #118

sourceful-mia opened this issue May 20, 2024 · 1 comment

Comments

@sourceful-mia
Copy link

sourceful-mia commented May 20, 2024

Describe the bug
When I run TSC after running codegen on a simple open api spec, I get error TS2742. It seems that this lib is missing some typings in the generated code.

To Reproduce
Steps to reproduce the behavior:

Generated code with the attached swagger file, and run TSC on it.

OpenAPI spec file
If possible, please upload the OpenAPI spec file.

{
	"openapi": "3.0.0",
	"components": {
		"examples": {},
		"headers": {},
		"parameters": {},
		"requestBodies": {},
		"responses": {},
		"schemas": {
			"UUID": {
				"type": "string",
				"description": "Stringified UUIDv4.\nSee [RFC 4112](https://tools.ietf.org/html/rfc4122)"
			},
			"Project": {
				"properties": {
					"shared_with_client": {
						"type": "boolean"
					},
					"updated_by": {
						"$ref": "#/components/schemas/UUID"
					},
					"last_updated": {
						"type": "string"
					},
					"date_created": {
						"type": "string"
					},
					"name": {
						"type": "string"
					},
					"id": {
						"$ref": "#/components/schemas/UUID"
					}
				},
				"required": [
					"shared_with_client",
					"updated_by",
					"last_updated",
					"date_created",
					"name",
					"id"
				],
				"type": "object"
			},
			"ApiInternalError": {
				"properties": {
					"message": {
						"type": "string"
					}
				},
				"required": [
					"message"
				],
				"type": "object"
			},
			"ApiResponseListMeta": {
				"properties": {
					"total": {
						"type": "number",
						"format": "double"
					}
				},
				"required": [
					"total"
				],
				"type": "object",
				"additionalProperties": false
			},
			"ApiResponseList_Project_": {
				"properties": {
					"data": {
						"items": {
							"$ref": "#/components/schemas/Project"
						},
						"type": "array"
					},
					"errors": {
						"items": {
							"$ref": "#/components/schemas/ApiInternalError"
						},
						"type": "array"
					},
					"meta": {
						"$ref": "#/components/schemas/ApiResponseListMeta"
					}
				},
				"required": [
					"data",
					"errors"
				],
				"type": "object",
				"additionalProperties": false
			},
			"ApiResponse_Project_": {
				"properties": {
					"data": {
						"$ref": "#/components/schemas/Project"
					},
					"errors": {
						"items": {
							"$ref": "#/components/schemas/ApiInternalError"
						},
						"type": "array"
					},
					"meta": {
						"type": "number",
						"enum": [
							null
						],
						"nullable": true
					}
				},
				"required": [
					"data",
					"errors"
				],
				"type": "object",
				"additionalProperties": false
			},
			"ProjectCreateParams": {
				"properties": {
					"name": {
						"type": "string"
					}
				},
				"required": [
					"name"
				],
				"type": "object",
				"additionalProperties": false
			}
		},
		"securitySchemes": {
			"bearerAuth": {
				"type": "http",
				"scheme": "bearer",
				"bearerFormat": "JWT"
			}
		}
	},
	"info": {
		"title": "projects-api",
		"version": "1.0.0",
		"description": "Projects backend for frontend",
		"license": {
			"name": "ISC"
		},
		"contact": {}
	},
	"paths": {
		"/v1/projects": {
			"get": {
				"operationId": "GetProjects",
				"responses": {
					"200": {
						"description": "Ok",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/ApiResponseList_Project_"
								}
							}
						}
					}
				},
				"security": [
					{
						"bearerAuth": []
					}
				],
				"parameters": []
			},
			"post": {
				"operationId": "CreateProject",
				"responses": {
					"201": {
						"description": "Created",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/ApiResponse_Project_"
								}
							}
						}
					}
				},
				"security": [
					{
						"bearerAuth": []
					}
				],
				"parameters": [],
				"requestBody": {
					"required": true,
					"content": {
						"application/json": {
							"schema": {
								"$ref": "#/components/schemas/ProjectCreateParams"
							}
						}
					}
				}
			}
		}
	},
	"servers": [
		{
			"url": "/projects-api"
		}
	]
}

Expected behavior
TSC should not error on generated files

Screenshots
image

  • OS: Mac OS Ventura 13.2
  • Version: v1.4.0
  • Typescript Version: 5.2.2

Additional context
Add any other context about the problem here.

@7nohe
Copy link
Owner

7nohe commented May 21, 2024

@sourceful-mia
I tried the spec file provided in the following repository, and there were no errors. Are there any other options needed?

https://github.com/7nohe/orqc-repro-118

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants