[BUG] [javascript-flowtyped] Add Error to language primitives
Created by: thSoft
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output?
Description
When there is a type named Error in the specification, the generator generates code that does not typecheck.
openapi-generator version
4.3.0
OpenAPI declaration file content or url
openapi: '3.0.0'
info:
version: 0.0.0
title: Bug
paths:
/bug:
get:
responses:
default:
$ref: '#/components/responses/UnexpectedError'
components:
responses:
UnexpectedError:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
schemas:
Error:
properties:
code:
type: integer
format: int32
example: 500
Command line used for generation
openapi-generator generate -i bug.yaml -g javascript-flowtyped -o bug/
Steps to reproduce
- Generate code with the above command line
- Check the generated code with
flow check bug
- You get
Cannot reference type Error [1] from a value position.
62│ * @class RequiredError
63│ * @extends {Error}
64│ */
65│ export class RequiredError extends Error {
66│ name:string = "RequiredError"
67│ constructor(field: string, msg?: string) {
68│ super(msg);
:
[1] 76│ export type Error = {
because JavaScript's built-in Error type conflicts with the generated type alias for the Error record defined in the OpenAPI specification.
Related issues/PRs
I found none.
Suggest a fix
Reject the specification if it contains a type named Error.