@Test(description = "it should deserialize a response per #1349") public void testMapDeserialization() throws Exception { Operation operation = Json.mapper().readValue(json, Operation.class); ApiResponse response = operation.getResponses().get("200"); assertNotNull(response); Schema responseSchema = response.getContent().get("*/*").getSchema(); assertNotNull(responseSchema); assertTrue(responseSchema instanceof MapSchema); MapSchema mp = (MapSchema) responseSchema; assertTrue(mp.getAdditionalProperties() instanceof IntegerSchema); }
assertNotNull(items); assertEquals(items.getClass(), MapSchema.class); Schema stringProperty = (Schema)((MapSchema) items).getAdditionalProperties(); assertNotNull(stringProperty); assertEquals(stringProperty.getClass(), StringSchema.class); assertNotNull(items); assertEquals(items.getClass(), MapSchema.class); Schema additionalProperty = (Schema)((MapSchema) items).getAdditionalProperties(); assertNotNull(additionalProperty); assertNotNull(additionalProperty.get$ref());
private static Object generateExampleForMapProperty(MapSchema property, MarkupDocBuilder markupDocBuilder) { if (property.getExample() != null) { return property.getExample(); } Map<String, Object> exampleMap = new LinkedHashMap<>(); Schema valueProperty = (Schema) property.getAdditionalProperties(); if (valueProperty.getExample() != null) { return valueProperty.getExample(); } exampleMap.put("string", PropertyAdapter.generateExample(valueProperty, markupDocBuilder)); return exampleMap; }
@Override public String toInstantiationType(Schema schema) { if (schema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) schema; String inner = getSchemaType((Schema) mapSchema.getAdditionalProperties()); return inner; } else if (schema instanceof ArraySchema) { ArraySchema arraySchema = (ArraySchema) schema; String inner = getSchemaType(arraySchema.getItems()); return "[" + inner + "]"; } return null; }
@Override public String toInstantiationType(Schema schema) { if (schema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) schema; String inner = getSchemaType((Schema) mapSchema.getAdditionalProperties()); return inner; } else if (schema instanceof ArraySchema) { ArraySchema arraySchema = (ArraySchema) schema; String inner = getSchemaType(arraySchema.getItems()); return "[" + inner + "]"; } return null; }
@Override public String getTypeDeclaration(Schema propertySchema) { if (propertySchema instanceof ArraySchema) { ArraySchema arraySchema = (ArraySchema) propertySchema; Schema inner = arraySchema.getItems(); return "[" + getTypeDeclaration(inner) + "]"; } else if (propertySchema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) propertySchema; Schema inner = (Schema) mapSchema.getAdditionalProperties(); return "[String:" + getTypeDeclaration(inner) + "]"; } return super.getTypeDeclaration(propertySchema); }
@Override public String getTypeDeclaration(Schema propertySchema) { if (propertySchema instanceof ArraySchema) { ArraySchema arraySchema = (ArraySchema) propertySchema; Schema inner = arraySchema.getItems(); return "[" + getTypeDeclaration(inner) + "]"; } else if (propertySchema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) propertySchema; Schema inner = (Schema) mapSchema.getAdditionalProperties(); return "[String:" + getTypeDeclaration(inner) + "]"; } return super.getTypeDeclaration(propertySchema); }
@Override public String getTypeDeclaration(Schema propertySchema) { if (propertySchema instanceof ArraySchema) { ArraySchema arraySchema = (ArraySchema) propertySchema; Schema inner = arraySchema.getItems(); if (inner == null) { LOGGER.warn(arraySchema.getName() + "(array property) does not have a proper inner type defined"); return ""; } return getTypeDeclaration(inner) + "[]"; } else if (propertySchema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) propertySchema; Schema inner = (Schema) mapSchema.getAdditionalProperties(); if (inner == null) { LOGGER.warn(propertySchema.getName() + "(map property) does not have a proper inner type defined"); return ""; } return getSchemaType(propertySchema) + "[string," + getTypeDeclaration(inner) + "]"; } return super.getTypeDeclaration(propertySchema); }
@Override public String getTypeDeclaration(Schema propertySchema) { if (propertySchema instanceof ArraySchema) { ArraySchema arraySchema = (ArraySchema) propertySchema; Schema inner = arraySchema.getItems(); if (inner == null) { LOGGER.warn(arraySchema.getName() + "(array property) does not have a proper inner type defined"); return ""; } return getTypeDeclaration(inner) + "[]"; } else if (propertySchema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) propertySchema; Schema inner = (Schema) mapSchema.getAdditionalProperties(); if (inner == null) { LOGGER.warn(propertySchema.getName() + "(map property) does not have a proper inner type defined"); return ""; } return getSchemaType(propertySchema) + "[string," + getTypeDeclaration(inner) + "]"; } else if (StringUtils.isNotBlank(propertySchema.get$ref())) { String type = super.getTypeDeclaration(propertySchema); return (!languageSpecificPrimitives.contains(type)) ? "\\" + modelPackage + "\\" + type : type; } return super.getTypeDeclaration(propertySchema); }
@Override public String getTypeDeclaration(Schema propertySchema) { if (propertySchema instanceof ArraySchema) { ArraySchema arraySchema = (ArraySchema) propertySchema; Schema inner = arraySchema.getItems(); if (inner == null) { LOGGER.warn(arraySchema.getName() + "(array property) does not have a proper inner type defined"); return ""; } return getTypeDeclaration(inner) + "[]"; } else if (propertySchema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) propertySchema; Schema inner = (Schema) mapSchema.getAdditionalProperties(); if (inner == null) { LOGGER.warn(propertySchema.getName() + "(map property) does not have a proper inner type defined"); return ""; } return getSchemaType(propertySchema) + "[string," + getTypeDeclaration(inner) + "]"; } else if (StringUtils.isNotBlank(propertySchema.get$ref())) { String type = super.getTypeDeclaration(propertySchema); return (!languageSpecificPrimitives.contains(type)) ? "\\" + modelPackage + "\\" + type : type; } return super.getTypeDeclaration(propertySchema); }
@Override public String getTypeDeclaration(Schema propertySchema) { if (propertySchema instanceof ArraySchema) { ArraySchema arraySchema = (ArraySchema) propertySchema; Schema inner = arraySchema.getItems(); if (inner == null) { LOGGER.warn(arraySchema.getName() + "(array property) does not have a proper inner type defined"); return ""; } return getTypeDeclaration(inner) + "[]"; } else if (propertySchema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) propertySchema; Schema inner = (Schema) mapSchema.getAdditionalProperties(); if (inner == null) { LOGGER.warn(propertySchema.getName() + "(map property) does not have a proper inner type defined"); return ""; } return getSchemaType(propertySchema) + "[string," + getTypeDeclaration(inner) + "]"; } return super.getTypeDeclaration(propertySchema); }
} else if (responseSchema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) responseSchema; CodegenProperty innerProperty = fromProperty("response", (Schema) mapSchema.getAdditionalProperties()); codegenOperation.returnBaseType = innerProperty.baseType; } else {
} else if (responseSchema instanceof MapSchema) { MapSchema mapSchema = (MapSchema) responseSchema; CodegenProperty innerProperty = fromProperty("response", (Schema) mapSchema.getAdditionalProperties()); codegenOperation.returnBaseType = innerProperty.baseType; } else {
} else if (property instanceof MapSchema) { MapSchema mapProperty = (MapSchema) property; Schema additionalProperties = (Schema) mapProperty.getAdditionalProperties(); if (additionalProperties == null) type = new MapType(mapProperty.getTitle(), new ObjectType(null, null)); // FIXME : Workaround for Swagger parser issue with composed models (https://github.com/Swagger2Markup/swagger2markup/issues/150)