OpenAPITools / OpenAPITools/openapi-generator

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

Open
#8,258 21 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with api-docs.yaml and config.yaml, then run the validate and generate commands for the typescript-angular generator. Inspect the generated authority field and compare it with the expected Set behavior shown by user.authority.has(UserAuthorityEnum.Admin); done means the reported usage works or the specification limitation is clearly established.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.