Skip to content

[BUG][typescript-angular] Custom typeMapping for file is overriden in generator #3341

@Adelrisk

Description

@Adelrisk

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
    Foo:
      type: object
      properties:
        msg:
          type: string
          format: binary

The generator produces msg with the type Blob.

class Foo {
    msg: Blob;
}

Regardless of the various mappings I attempt to set, I cannot find the correct mapping declaration to ensure that this is instead mapped to string. The obvious typeMapping file=string should work, but it's overriden in code here: https://github.com/OpenAPITools/openapi-generator/blob/v4.0.2/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java#L282

  • Have you validated the input using an OpenAPI validator (example)?
    Yes

  • What's the version of OpenAPI Generator used?
    4.0.2

  • Have you search for related issues/PRs?
    The keyword blob returns too many deep links into github code. So I looked at the code.

  • What's the actual output vs expected output?

I would like to generate the following:

class Foo {
    msg: string;
}

I'm migrating from the io.swagger tool and would like to avoid breaking changes. Blob breaks existing code.

Suggest a fix

If I were to have a stab at this, I think the complete removal of the overriding method would be enough: https://github.com/OpenAPITools/openapi-generator/blob/v4.0.2/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java#L280

    @Override
    public String getTypeDeclaration(Schema p) {
        if (ModelUtils.isFileSchema(p)) {
            return "Blob";
        } else {
            return super.getTypeDeclaration(p);
        }
}

The correct default behaviour should already be provided with the typeMapping in the constructor:

typeMapping.put("file", "Blob");

However, there is so much going on here, I just can't guesstimate what else this might effect. Such as this method:

    @Override
    public boolean isDataTypeFile(final String dataType) {
        return dataType != null && dataType.equals("Blob");
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions