mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-24 12:09:17 +00:00
[Java] Handle discriminator mapping non-ref name (#3247)
The `mapping` property of the [Discriminator Object] is "An object to hold mappings between payload values and schema names or references." The subsequent examples in the spec have `mapping`s of both types. The `mapping` support introduced in #536 only supports references. Update the code to support names (identified by lack of `/`) or references and change a test mapping to cover this case. [Discriminator Object]: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#discriminatorObject Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This commit is contained in:
committed by
William Cheng
parent
310f5feda0
commit
2c342cc2b4
@@ -1867,8 +1867,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
discriminator.setMapping(schema.getDiscriminator().getMapping());
|
||||
if (schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) {
|
||||
for (Entry<String, String> e : schema.getDiscriminator().getMapping().entrySet()) {
|
||||
String name = toModelName(ModelUtils.getSimpleRef(e.getValue())); // e.g e.getValue => #/components/schemas/Dog
|
||||
discriminator.getMappedModels().add(new MappedModel(e.getKey(), name));
|
||||
String nameOrRef = e.getValue();
|
||||
String name = nameOrRef.indexOf('/') >= 0 ? ModelUtils.getSimpleRef(nameOrRef) : nameOrRef;
|
||||
String modelName = toModelName(name);
|
||||
discriminator.getMappedModels().add(new MappedModel(e.getKey(), modelName));
|
||||
}
|
||||
} else {
|
||||
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
|
||||
|
||||
Reference in New Issue
Block a user