[Feature] [TYPESCRIPT] Generator parses to Array instead of Set
See original GitHub issueBug 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:
- Created 3 years ago
- Reactions:6
- Comments:18 (9 by maintainers)
Top GitHub Comments
I had the same/similar issue with
typescript-fetch
.--type-mappings=set=Array
worked as a workaround. I have created a PR fortypescript-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 fortypescript-fetch
so far.This will change the interface to
Array
but..FromJSON
function still tries to useSet
, which leads to type mismatch error.