openapi-ts: Duplicate identifiers in types.gen.ts
Description
I am still seeing these errors in the generated code
SyntaxError: /usr/dgc-playwright/generated/data-class-client/types.gen.ts: Identifier 'DataClassGroupId' has already been declared. (451:12)
449 | *
450 | */
> 451 | export type DataClassGroupId = string;
| ^
452 |
453 | /**
454 | * The name of a `Data Class`.
at activity/profileActivities.test.ts:451
at Object.<anonymous> (/usr/dgc-playwright/generated/data-class-client/index.ts:10:1)
at Object.<anonymous> (/usr/dgc-playwright/api/clients/clients.ts:6:1)
at Object.<anonymous> (/usr/dgc-playwright/api/core/auth/auth.ts:2:1)
at Object.<anonymous> (/usr/dgc-playwright/fixtures/messaging-eventing/meActivitiesFixture.ts:1:1)
at Object.<anonymous> (/usr/dgc-playwright/tests/activity/profileActivities.test.ts:1:1)
Im my types.gen.ts there are duplicates
export type DataClassDescription = string;
/**
* The status of a `Data Class`.
*
* This attribute allows a `Data Class` to be `ENABLED` or `DISABLED`.
* An `DISABLED` `Data Class` will never be used as part of the classification process.
*
* Possible values:
* - `ENABLED`
* - `DISABLED`
*
*/
export type DataClassStatus = string;
I think this was supposed to be fixed in this ticket - https://github.com/hey-api/openapi-ts/issues/420
OpenAPI specification (optional)
components:
parameters:
listOfValuesId:
name: listOfValuesId
in: path
description: |
The ID of a `List Of Values`.
required: true
schema:
type: string
format: uuid
DataClassIdInPath:
name: dataClassId
in: path
description: |
The ID of a `Data Class`.
required: true
schema:
type: string
format: uuid
DataClassGroupIdInPath:
name: dataClassGroupId
in: path
description: |
The ID of a `Data Class Group`.
required: true
schema:
type: string
format: uuid
DataClassGroupId:
name: dataClassGroupId
in: query
description: |
The ID of a `Data Class Group`.
required: false
schema:
type: string
format: uuid
DataClassName:
name: name
in: query
description: |
The name of a `Data Class`.
The matching logic is case insensitive and supports partial matches.
E.g. A search for `EMAIL` matches `Data Class` name `Email Address`
E.g. A search for `Security` matches `Data Class` name `Social-Security-Number`
required: false
schema:
type: string
DataClassDescription:
name: description
in: query
description: |
The description of a `Data Class`.
The matching logic is case insensitive and supports partial matches.
required: false
schema:
type: string
DataClassGroupName:
name: name
in: query
description: |
The name of a `Data Class Group`.
The matching logic is case insensitive and supports partial matches.
E.g. A search for `PERSONAL` or a search for `Identi` match `Data Class Group` name 'Personal Identifiable Information'
required: false
schema:
type: string
DataClassContainsRules:
name: containsRules
in: query
description: |
Filters the `Data Classes` based on whether or not they contain rules.
If `containsRules=true` is defined as parameter, only the `Data Classes` containing rules are returned.
This can be useful to retrieve only the `Data Classes` that can be used for automated classification.
required: false
example: true
schema:
type: boolean
DataClassStatus:
name: status
in: query
description: |
Applies a filter based on the `status` of the `Data Classes`.
Possible values:
- `ENABLED`
- `DISABLED`
If multiple `status` parameters are provided, the `Data Classes` matching any `status` defined
as parameter are taken into account (OR logic).
required: false
schema:
type: array
items:
type: string
example:
- ENABLED
style: form
explode: true
RuleType:
name: ruleType
in: query
required: false
description: |
Filter based on the `ruleType` of `Classification Rules` defined inside the `Data Class`.
Multiple `ruleType` parameters can be provided.
In this case, the API returns the `DataClasses` containing rules matching any of the defined types (OR logic).
The following values are currently supported:
- `REGULAR_EXPRESSION`
- `LIST_OF_VALUES`
- `CODE_SET`
- `LIKE`
- `GREATER_THAN`
- `LESS_THAN`
- `EQUAL`
- `BETWEEN`
schema:
type: array
items:
type: string
example: LIST_OF_VALUES
style: form
explode: true
Offset:
name: offset
in: query
required: false
description: |
The index of the first result to retrieve.
If not set (offset = `0`), results will be retrieved starting from row `0`.
schema:
type: integer
format: int32
default: 0
Limit:
name: limit
in: query
required: false
description: |
The maximum number of results to retrieve.
If not set, the default limit (limit = `50`) will be used. The maximum value for this parameter is
`1000`.
schema:
type: integer
format: int32
default: 50
maximum: 1000
DataClassView:
name: view
in: query
required: false
description: |
The view of the `Data Class` to return.
Possible values are `basic` or `extended` (case insensitive). The `basic` view does not include the rules, whereas the `extended` view does.
schema:
type: string
default: basic
Cursor:
name: cursor
in: query
required: false
description: |
The cursor pointing to the first resource to be included in the response. This cursor cannot be created and must have been extracted from a response returned by a previous API call.
If this parameter is missing, the API will return the resources starting from the first resource available (index=0).
schema:
type: string
schemas:
ListOfValues:
type: object
properties:
id:
$ref: '#/components/schemas/ListOfValuesId'
valueCount:
$ref: '#/components/schemas/ValueCount'
firstValues:
$ref: '#/components/schemas/FirstValues'
CodeSet:
type: object
description: |
Represents a `Code Set` asset.
required:
- id
properties:
id:
$ref: '#/components/schemas/CodeSetId'
valueCount:
$ref: '#/components/schemas/ValueCount'
DataClass:
type: object
required:
- id
- name
- status
- createdBy
- createdOn
- lastModifiedBy
- lastModifiedOn
properties:
id:
$ref: '#/components/schemas/DataClassId'
name:
$ref: '#/components/schemas/DataClassName'
description:
$ref: '#/components/schemas/DataClassDescription'
status:
$ref: '#/components/schemas/DataClassStatus'
createdBy:
$ref: '#/components/schemas/CreatedBy'
createdOn:
$ref: '#/components/schemas/CreatedOn'
lastModifiedBy:
$ref: '#/components/schemas/LastModifiedBy'
lastModifiedOn:
$ref: '#/components/schemas/LastModifiedOn'
rules:
$ref: '#/components/schemas/ClassificationRules'
DataClassGroup:
type: object
description: |
Group of `Data Classes`.
required:
- id
- name
- dataClasses
properties:
Configuration
/* eslint-disable no-console */
const defaultConfig = {
client: 'axios',
lint: false,
format: false,
};
const config = [
{
name: 'UsageAnalyticsAppUsageClient',
input: './resources/usage-analytics/usage_1.0.yaml',
output: './generated/usage-analytics-client/usage',
},
{
name: 'UsageAnalyticsAppUsersClient',
input: './resources/usage-analytics/users_1.0.yaml',
output: './generated/usage-analytics-client/users',
},
{
name: 'UsageAnalyticsAppEventsClient',
input: './resources/usage-analytics/events_1.0.yaml',
output: './generated/usage-analytics-client/events',
},
{
name: 'ImportAppClient',
input: './resources/dgc-importer-rest.json',
output: './generated/dgc-import-client',
},
{
name: 'CoreAppClient',
input: './resources/dgc-rest.json',
output: './generated/core-client',
},
{
name: 'CorePrivateAppClient',
input: './resources/dgc-private-rest.json',
output: './generated/core-private-client',
},
{
name: 'EdgeAppClient',
input: './resources/edge-management-api.yaml',
output: './generated/edge-client',
},
{
name: 'CloudIngestionsAppClient',
input: './resources/cloud-ingestions-rest.json',
output: './generated/cloud-ingestions-client',
},
{
name: 'DataClassApiClient',
input: './resources/data-class-api.yaml',
output: './generated/data-class-client',
},
{
name: 'DataClassificationAppClient',
input: './resources/data-classification-rest.json',
output: './generated/data-classification-client',
},
{
name: 'ProtectApiClient',
input: './resources/protect-public-api.yaml',
output: './generated/protect-client',
},
].map((c) => ({ ...defaultConfig, ...c }));
async function generateAll() {
const openApiTs = await import('@hey-api/openapi-ts');
for (const c of config) {
await openApiTs.createClient(c);
}
}
generateAll()
.then(() => console.log('Finished generating'))
.catch(console.error);
System information (optional)
MacOS Node 20
About this issue
- Original URL
- State: closed
- Created 2 months ago
- Reactions: 1
- Comments: 19 (8 by maintainers)
@costa-collibra I am going to have this fixed for you in the next release. I tested it with the spec file you provided and it passes. I applied a quick and dirty hack to prefix parameter names under the assumption that people commonly don’t import these types directly in their applications and therefore won’t be breaking their code. Ideal solution would be to properly deduplicate exported types, but that’s a way bigger architectural change that would need to happen
@mrlubos
i can duplicates here but it doesnt cause any issues running the code, this is in the index.ts
No need, I could replicate it myself, but didn’t want to bother haha. I think it used to simply override types when it was generating one file per export, just curious
Can’t currently promise this will be fixed this week, but will try
That sounds like a separate problem, can you open an issue please? And provide your OpenAPI spec + what’s getting generated if relevant?