Skip to content

[typescript-angular] Fix typescript model kebab-cased filenames #5085

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

Merged
merged 1 commit into from
Jan 24, 2020
Merged

[typescript-angular] Fix typescript model kebab-cased filenames #5085

merged 1 commit into from
Jan 24, 2020

Conversation

roddy
Copy link
Contributor

@roddy roddy commented Jan 23, 2020

When using "kebab-case" file names, the typescript-angular client generator would create model files with repeating dashes in the filenames, but the import statements would have single dashes. This was caused by the Inline Model Resolver naming the resolved models by concatenating the parent name to the child model name with an underscore separator; if the child model name had a leading underscore, this would cause a double underscore in the new model name. When this model name was converted to kebab case for the file name, each individual underscore was converted to a dash, resulting in a filename with repeated dashes.

To address, updated the dashize method in StringUtils to collapse multiple consecutive whitespace and/or underscores to a single dash. This shouldn't be a breaking change, but if need be the fix could easily be amended to make the collapsing part of the operation optional using a boolean parameter and an overloaded method call.

Added test cases to the StringUtils unit tests, Angular Typescript client code gen tests, and Angular Typescript model tests. Ran all of the tests in the project using mvn test; no failures. There were no changes to the petstore APIs or templates. Built the project and verified using the YML and commandline arguments from #5073 (yml included at bottom of PR).

Fixes #5073

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11)

Verification

Sample YML for verification (make sure to set fileNaming to "kebab-case"):

openapi: 3.0.0
info:
  title: Example API
  description: An Example API
  version: "1.0"
paths:
  /hello:
    get:
      summary: Example endpoint
      operationId: get_hello
      responses:
        200:
          description: Example response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FooResponse'
components:
  schemas:
    FooResponse:
      type: object
      properties:
        _links:
          required:
            - collection
            - self
          type: object
          properties:
            collection:
              type: string
              format: uri
            self:
              type: string
              format: uri

Previous behavior would generate files ./models/foo-response.ts and ./models/foo-response--links.ts. New behavior is to generate ./models/foo-response-links.ts (other file unchanged).

Updated StringUtils to collapse consecutive underscores and/or whitespace into a single dash when "dashizing".
@auto-labeler
Copy link

auto-labeler bot commented Jan 23, 2020

👍 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.

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@macjohnny
Copy link
Member

thanks for the PR and the tests!

@macjohnny macjohnny added this to the 4.2.3 milestone Jan 23, 2020
@macjohnny macjohnny changed the title [typescript-angular] Fix typescript model kebab-cased filenames #5073 [typescript-angular] Fix typescript model kebab-cased filenames Jan 23, 2020
@macjohnny macjohnny merged commit 524ef63 into OpenAPITools:master Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG][typescript-angular] Model properties with underscore prefix generates invalid file names/imports using kebab-case file naming
2 participants