From 9603bec6d10bec8fb6c4b20b70497e88af8eea2e Mon Sep 17 00:00:00 2001 From: Karl von Randow Date: Thu, 22 Aug 2024 23:02:16 +1200 Subject: [PATCH] Use `LinkedHashSet` for arrays with `uniqueItems` --- .changeset/brave-buttons-worry.md | 5 +++++ packages/java-jaxrs-common/src/index.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/brave-buttons-worry.md diff --git a/.changeset/brave-buttons-worry.md b/.changeset/brave-buttons-worry.md new file mode 100644 index 00000000..3f167450 --- /dev/null +++ b/.changeset/brave-buttons-worry.md @@ -0,0 +1,5 @@ +--- +"@openapi-generator-plus/java-jaxrs-generator-common": minor +--- + +Use `LinkedHashSet` for arrays with `uniqueItems` diff --git a/packages/java-jaxrs-common/src/index.ts b/packages/java-jaxrs-common/src/index.ts index 5ccd99eb..f32bec9f 100644 --- a/packages/java-jaxrs-common/src/index.ts +++ b/packages/java-jaxrs-common/src/index.ts @@ -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, {