Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
}
// if this is oneOf interface, make sure we include the necessary imports for it
addImportsToOneOfInterface(modelsImports);
//
// ensure that no JsonTypeName is created when the parent interface has a discriminator mapping
if (cm.discriminator != null && cm.discriminator.getMappedModels() != null && !cm.discriminator.getMappedModels().isEmpty()) {
cm.discriminator.getMappedModels().stream()
.map(MappedModel::getModel)
.filter(Objects::nonNull)
.forEach(model -> model.setHasDiscriminatorWithNonEmptyMapping(true));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8132,4 +8132,21 @@ void schemaMappingWithNullableAllOfRendersNullableJavaProperty() throws IOExcept
JavaFileAssert.assertThat(files.get("MyObject.java"))
.assertProperty("optionalRef").withType("JsonNullable<com.example.ExternalModel>");
}

@Test
void issue24003() throws IOException {
Map<String, File> files = generateFromContract(
"src/test/resources/3_0/spring/issue_24003.yaml", SPRING_BOOT,
Map.of(USE_SPRING_BOOT4, true, MODEL_NAME_SUFFIX, "DTO", INTERFACE_ONLY, "true"));
JavaFileAssert.assertThat(files.get("BrLockDTO.java")).isInterface()
.assertTypeAnnotations()
.containsWithNameAndAttributes("JsonTypeInfo", Map.of("use", "JsonTypeInfo.Id.NAME", "include", "JsonTypeInfo.As.PROPERTY", "property", "\"lockType\"", "visible", "true"))
.containsWithName("JsonSubTypes")
.recursivelyContainsWithNameAndAttributes("JsonSubTypes.Type", Map.of("value", "ComponentBrLockDTO.class", "name", "\"COMPONENT\""))
.recursivelyContainsWithNameAndAttributes("JsonSubTypes.Type", Map.of("value", "UserBrLockDTO.class", "name", "\"USER\""));
JavaFileAssert.assertThat(files.get("ComponentBrLockDTO.java")).implementsInterfaces("BrLockDTO")
.fileDoesNotContain("@JsonTypeName");
JavaFileAssert.assertThat(files.get("UserBrLockDTO.java")).implementsInterfaces("BrLockDTO")
.fileDoesNotContain("@JsonTypeName");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
openapi: 3.0.1
info:
title: x-discriminator-value JsonTypeName bug
version: 1.0.0
paths:
/locks:
get:
operationId: getLocks
responses:
'200':
description: list of locks
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/BrLock'
components:
schemas:
LockType:
type: string
enum:
- USER
- COMPONENT

BrLock:
type: object
required:
- lockType
properties:
lockType:
$ref: '#/components/schemas/LockType'
oneOf:
- $ref: '#/components/schemas/UserBrLock'
- $ref: '#/components/schemas/ComponentBrLock'
discriminator:
propertyName: lockType
mapping:
USER: '#/components/schemas/UserBrLock'
COMPONENT: '#/components/schemas/ComponentBrLock'

BaseBrLock:
type: object
required:
- lockType
properties:
lockType:
$ref: '#/components/schemas/LockType'

UserBrLock:
allOf:
- $ref: '#/components/schemas/BaseBrLock'
- type: object
required:
- userId
properties:
userId:
type: string

ComponentBrLock:
allOf:
- $ref: '#/components/schemas/BaseBrLock'
- type: object
required:
- componentId
properties:
componentId:
type: string
Loading