Skip to content

Typescript-Angular2 produces invalid import for self-referencing model  #6201

@psamwel

Description

@psamwel
Description

typescript-angular2 client codegen for a model that references itself (e.g.):

		"APISearchTerm": {
			"description": "Adds generic filter capability to API",
			"type": "object",
			"properties": {
				"field": {
					"description": "Field to compare",
					"type": "string"
				},
				"fieldValue": {
					"description": "Primary value",
					"type": "string"
				},
				"searchOperation": {
					"description": "Operator type",
					"enum": ["Equal",
					"NotEqual",
					"Contains",
					"GreaterThan",
					"GreaterThanOrEqual",
					"LessThan",
					"LessThanOrEqual"],
					"type": "string"
				},
				"and": {
					"description": "For building nested And expressions",
					"type": "array",
					"items": {
						"$ref": "#/definitions/APISearchTerm"
					}
				},
				"or": {
					"description": "For building nested Or expressions",
					"type": "array",
					"items": {
						"$ref": "#/definitions/APISearchTerm"
					}
				}
			}
		}

resulting in:

import { APISearchTerm } from './aPISearchTerm';

export interface APISearchTerm {
    field?: string;
    fieldValue?: string;
    searchOperation?: APISearchTerm.SearchOperationEnum;
    and?: Array<APISearchTerm>;
    or?: Array<APISearchTerm>;
}
...

which produces the following tsc error(s):

[12:04:12]Error at aPISearchTerm.ts:13:10: Individual declarations in merged declaration 'APISearchTerm' must be all exported or all local.
[12:04:12]Error at aPISearchTerm.ts:13:10: Import declaration conflicts with local declaration of 'APISearchTerm'
[12:04:12]Error at aPISearchTerm.ts:46:18: Individual declarations in merged declaration 'APISearchTerm' must be all exported or all local.

Swagger-codegen version

Verified in latest master & 2.3.0 locally.

2.3.0 branch

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i application.json -l typescript-angular2 -o $outputpath/sdk_angular2 -c $clientConfig

where $clientConfig:
{ "modelPropertyNaming": "original" }

Suggest a fix/enhancement

Exclude a classname from its own list of imports.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions