Openapi-generator: [angular-typescript] Bug generating model with suffix

Created on 3 Sep 2018  路  7Comments  路  Source: OpenAPITools/openapi-generator

Description

Generator tries to insert such import:

import { MapSwagger } from './modelMap';

when suffix is provided (e.g. Swagger)
and model contains map inside (same for services which take map as parameter)

modelMap?: { [key: string]: any; };
openapi-generator version

3.2.2
3.2.3

OpenAPI declaration file content or url
{
  "supportES6": true,
  "providedInRoot": "true",
  "modelSuffix": "Swagger",
  "ngVersion": "6.1.4"
}
Command line used for generation
java -jar openapi-generator-cli.jar generate -g typescript-angular -c openapi-config.json -i $1 -o $2

where $1 and $2 are input and output.

Steps to reproduce
  1. Generate model from json like this:
    "Model": {
      "type": "object",
      "properties": {
        "modelMap": {
          "type": "object",
          "additionalProperties": {
            "type": "object"
          }
        },
      }
    },
  1. Pass any suffix to generator's options
Related issues/PRs
Suggest a fix/enhancement

Exclude native js classes from imports before suffix applied.

TypeScript Bug

Most helpful comment

@Ilya1vanov i filed PR #973 which fixes this issue.

All 7 comments

@Ilya1vanov could you please explain more in detail which part of the output is not correct?
Maybe https://github.com/OpenAPITools/openapi-generator/pull/767 by @softdays resolves your issue?

@macjohnny thank you for your reply. #767 doesn't fix this issue.
import { MapSwagger } from './modelMap';
The problem is that there is no MapSwagger class in my json documentation (./modelMap file doesn't exist as well). I suppose, that it's a native js Map class, but name was changed with suffix and then it wasn't excluded from imports.

@macjohnny I don't think I'm good at Java. I want to ask you to fix it, if you don't mind.

On the face of it, the issue is in statement execution order. Map, Set, etc. (languageSpecificPrimitives array) have to be excluded from tsImports (for model) and imports (for api.service) before suffix is applied. But I'm not sure it is as simple as at first glance. You know code better.

Anyway, thank you a lot. That would be great if you fix it!

@Ilya1vanov i filed PR #973 which fixes this issue.

@macjohnny thank you. You are doing a great job!
Will #973 be added to 3.3.0 release in September? And when 3.3.0 is scheduled?

@Ilya1vanov it looks like this will be added to the 3.3.0 release, due in September 2018 (see https://github.com/OpenAPITools/openapi-generator/issues/956)

Was this page helpful?
0 / 5 - 0 ratings