question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] [TYPESCRIPT] Generator parses to Array instead of Set

See original GitHub issue

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What’s the actual output vs expected output?
Description

If I generate a typescript-angular client with the latest 5.0 stable release, query the mentioned endpoint and try to use user.authority.has(UserAuthorityEnum.Admin) within a component I get the following error. (In Both Template/Component the Error occurs)

ERROR TypeError: _angular_core__WEBPACK_IMPORTED_MODULE_0__.ɵɵpipeBind1(...).authority.has is not a function
    at DashboardComponent_Template (main.js:2043)
    at executeTemplate (vendor.js:65785)
    at refreshView (vendor.js:65654)
    at refreshComponent (vendor.js:66801)
    at refreshChildComponents (vendor.js:65460)
    at refreshView (vendor.js:65704)
    at refreshEmbeddedViews (vendor.js:66755)
    at refreshView (vendor.js:65678)
    at refreshComponent (vendor.js:66801)
    at refreshChildComponents (vendor.js:65460)
    at refreshView (vendor.js:65704)
    at refreshEmbeddedViews (vendor.js:66755)
    at refreshView (vendor.js:65678)
    at refreshComponent (vendor.js:66801)
    at refreshChildComponents (vendor.js:65460)

With further investigation it seems like the field authority is an Array instead of a Set. I am not sure if this is a bug or if this is a result of a faulty spec. I validated with the cli validator, as well as the swagger editor and the referenced validator. This behaviour was also present in the 5.0 beta 3 and I hoped it would be solved with the stable release.

Can anyone point me in the right direction? If there are any more specs/configs I can help you with, don’t hesitate to ask for them.

openapi-generator version

Latest stable release (5.0.0)

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Some Api
  description: Some Desc
  version: 0.2.0
servers:
- url: https://sample.url.com
  description: Generated server url
security:
- bearerAuth: []
paths:
  /api/users/me:
    get:
      tags:
      - user-resource
      operationId: getMe
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/User'

components:
  schemas:
    User:
      required:
      - authority
      - firstName
      - id
      - lastName
      - userStatus
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 12
        firstName:
          type: string
          example: Average
        lastName:
          type: string
          example: Joe
        phoneNumber:
          type: string
          example: "01101001001"
        userStatus:
          type: string
          example: ACTIVATED
          enum:
          - UNUSED
          - ACTIVATED
          - BLOCKED
        facilityId:
          type: integer
          format: int64
          example: 13
        authority:
          uniqueItems: true
          type: array
          example: "[CUSTODIAN]"
          items:
            type: string
            example: "[CUSTODIAN]"
            enum:
            - CUSTODIAN
            - EDUCATOR
            - FACILITY_DIRECTOR
            - SUPPORT
            - ADMIN
        childIds:
          uniqueItems: true
          type: array
          example:
          - 1
          - 2
          - 3
          items:
            type: integer
            format: int64
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
Generation Details

config.yaml (string enum doesn’t affect thus error, I tried it with the default value as well)

snapshot: true
npmName: '@repo/api-ts-client'
npmRepository: 'https://repo-url.com/repository/npm-internal/'
stringEnums: true
Steps to reproduce

generate client

java -jar openapi-generator-cli.jar validate -i api-docs.yaml
java -jar openapi-generator-cli.jar generate -o npm-client -g typescript-angular -c config.yaml -i api-docs.yaml
cd npm-client
npm install
npm run build
npm publish dist

install it within your angular project and try to call method and try to call user.authority.has(UserAuthorityEnum.Admin) on a fetched user. You can use this json for as it is my server response

{
"id":1,
"firstName":"Admin",
"lastName":"Admin",
"phoneNumber":"01101001001",
"userStatus":"ACTIVATED",
"facilityId":null,
"authority":["ADMIN"],
"childIds":[]
}

Look in the console and look for the mentioned problem.

Related issues/PRs

I didn’t find any related PR/Issues

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

10reactions
t-h-ecommented, Feb 13, 2021

I had the same/similar issue with typescript-fetch. --type-mappings=set=Array worked as a workaround. I have created a PR for typescript-fetch. I wasn’t sure if I should create a new issue. If referencing this one, was wrong, just let me know. As the different typescript generators all seem somewhat different, I have only fixed it for typescript-fetch so far.

2reactions
xsemancommented, Nov 26, 2021

I had the same/similar issue with typescript-fetch. --type-mappings=set=Array worked as a workaround. I have created a PR for typescript-fetch. I wasn’t sure if I should create a new issue. If referencing this one, was wrong, just let me know. As the different typescript generators all seem somewhat different, I have only fixed it for typescript-fetch so far.

This will change the interface to Array but ..FromJSON function still tries to use Set, which leads to type mismatch error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation for the typescript Generator
Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument. ...
Read more >
Convert ES6 Iterable to Array - javascript - Stack Overflow
Array.from() function, it takes an iterable as in input and returns an array of the iterable. · Spread syntax: ... in combination with...
Read more >
Iterators and generators - JavaScript - MDN Web Docs
The most common iterator in JavaScript is the Array iterator, which returns each value in the associated array in sequence. While it is...
Read more >
The starting point for learning TypeScript
Find TypeScript starter projects: from Angular to React or Node.js and CLIs.
Read more >
Docs - Moment.js
If you want to parse or display a moment in UTC, you can use moment.utc() instead of moment() . This brings us to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found