Skip to content

Commit

Permalink
Use LinkedHashSet for arrays with uniqueItems
Browse files Browse the repository at this point in the history
  • Loading branch information
karlvr committed Aug 22, 2024
1 parent 7d3a2fa commit 9603bec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-buttons-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openapi-generator-plus/java-jaxrs-generator-common": minor
---

Use `LinkedHashSet` for arrays with `uniqueItems`
9 changes: 6 additions & 3 deletions packages/java-jaxrs-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,12 @@ export default function createGenerator(config: CodegenConfig, context: JavaGene
const { componentNativeType, uniqueItems } = options
if (uniqueItems) {
return new context.TransformingNativeType(componentNativeType, {
default: (nativeType) => `java.util.List<${(nativeType.componentType || nativeType).nativeType}>`,
literalType: () => 'java.util.List',
concreteType: (nativeType) => `java.util.ArrayList<${(nativeType.componentType || nativeType).nativeType}>`,
/* We use LinkedHashSet everywhere to make it clear to all users of the API that it's ordered and unique.
This also means we don't need to tell Jackson to use LinkedHashSet when deserializing.
*/
default: (nativeType) => `java.util.LinkedHashSet<${(nativeType.componentType || nativeType).nativeType}>`,
literalType: () => 'java.util.LinkedHashSet',
concreteType: (nativeType) => `java.util.LinkedHashSet<${(nativeType.componentType || nativeType).nativeType}>`,
})
} else {
return new context.TransformingNativeType(componentNativeType, {
Expand Down

0 comments on commit 9603bec

Please sign in to comment.