Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BUG][typescript-angular] Incorrect import path when using prefix/suffix for model names #2560

Closed
5 of 6 tasks
jahow opened this issue Apr 1, 2019 · 2 comments · Fixed by #2590
Closed
5 of 6 tasks

Comments

@jahow
Copy link
Contributor

jahow commented Apr 1, 2019

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?
  • [Optional] Bounty to sponsor the fix (example)
Description

When generating code for the typescript-angular language and specifying either --model-name-prefix or --model-name-suffix, the paths used for importing models are wrong (missing said prefix/suffix).

Using the spec & command given below, a model file called model/testSchema.ts is generated,:

/**
 * blah
 */
export interface TestSchemaModel { 
    description?: string;
    creationDate?: Date;
    code?: string;
}

The import for this model in api/default.service.ts is as follow:

...

import { TestSchemaModel } from '../model/testSchemaModel';

...

The path is wrong and should be ../model/testSchema (or alternatively the name of the model file is wrong).

openapi-generator version

master and 4.0.0-beta2.

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: Sample API
  version: "1.0.0"
  contact:
    email: you@your-company.com
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'

paths:
  /TestSchema/{id}:
    parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
          format: int64
    get:
      operationId: find
      responses:
        200:
          description: returns something
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestSchema'

components:
  schemas:

    TestSchema:
      description: blah
      allOf:
        - type: object
          properties:
            description:
              type: string
            creation_date:
                type: string
                format: 'date-time'
            code:
              type: string
Command line used for generation
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i schema.yaml -g typescript-angular -o testoutput --model-name-suffix=model
Related issues/PRs
Suggest a fix

I've looked into the source code but have not yet found what would be the cause of this behaviour. Will create a PR if I ever find a fix for this on my own (if that's okay?).

Thanks a lot for this great project!

@auto-labeler
Copy link

auto-labeler bot commented Apr 1, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@macjohnny
Copy link
Member

@jahow a PR with a fix is highly appreciated.
I guess the starting point is here:

tsImport.put("classname", im);
tsImport.put("filename", toModelFilename(removeModelSuffixIfNecessary(im)));

which is then imported here
{{#imports}}
import { {{classname}} } from '../{{filename}}';
{{/imports}}

Moreover, the removeModelSuffixIfNecessary() should also handle prefixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants