Java Code Examples for io.swagger.v3.oas.models.media.Discriminator#setMapping()
The following examples show how to use
io.swagger.v3.oas.models.media.Discriminator#setMapping() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 6 votes |
public Discriminator getDiscriminator (ObjectNode node, String location, ParseResult result){ Discriminator discriminator = new Discriminator(); String value = getString("propertyName",node,true,location,result); if (StringUtils.isNotBlank(value)){ discriminator.setPropertyName(value); } ObjectNode mappingNode = getObject("mapping", node,false, location, result); if(mappingNode != null){ Map<String, String> mapping = new LinkedHashMap<>(); Set<String> keys = getKeys(mappingNode); for(String key : keys) { mapping.put(key, mappingNode.get(key).asText()); } discriminator.setMapping(mapping); } return discriminator; }
Example 2
Source File: ComponentSchemaTransformer.java From spring-openapi with MIT License | 5 votes |
private Discriminator createDiscriminator(InheritanceInfo inheritanceInfo) { Map<String, String> discriminatorTypeMapping = inheritanceInfo.getDiscriminatorClassMap().entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); Discriminator discriminator = new Discriminator(); discriminator.setPropertyName(inheritanceInfo.getDiscriminatorFieldName()); discriminator.setMapping(discriminatorTypeMapping); return discriminator; }
Example 3
Source File: SchemaProcessor.java From swagger-parser with Apache License 2.0 | 5 votes |
private void changeDiscriminatorMapping(ComposedSchema composedSchema, String oldRef, String newRef) { Discriminator discriminator = composedSchema.getDiscriminator(); if (!oldRef.equals(newRef) && discriminator != null) { String oldName = RefUtils.computeDefinitionName(oldRef); String newName = RefUtils.computeDefinitionName(newRef); String mappingName = null; if (discriminator.getMapping() != null) { for (String name : discriminator.getMapping().keySet()) { if (oldRef.equals(discriminator.getMapping().get(name))) { mappingName = name; break; } } if (mappingName != null) { discriminator.getMapping().put(mappingName, newRef); } } if (mappingName == null && !oldName.equals(newName)) { if (discriminator.getMapping() == null) { discriminator.setMapping(new HashMap()); } discriminator.getMapping().put(oldName, newRef); } } }