private void addContentSchemaRef(Content content, Set<String> referencedDefinitions) { if (content != null) { for (String keyBodyContent : content.keySet()) { MediaType mediaType = content.get(keyBodyContent); addSchemaRef(mediaType.getSchema(), referencedDefinitions); } } }
@Test(description = "it should deserialize a read only parameter") public void deserializeReadOnlyParameter() throws IOException { final String json = "{\"in\":\"path\"," + "\"content\":{" + " \"*/*\":{" + " \"schema\":{" + " \"type\":\"string\"," + " \"readOnly\":true}}}}"; final Parameter p = m.readValue(json, Parameter.class); assertTrue(p.getContent().get("*/*").getSchema().getReadOnly()); }
@Test(description = "it should deserialize a boolean additionalProperties") public void testBooleanAdditionalPropertiesDeserialization() throws Exception { Operation operation = Json.mapper().readValue(jsonAdditionalPropertiesBoolean, Operation.class); ApiResponse response = operation.getResponses().get("200"); assertNotNull(response); Schema responseSchema = response.getContent().get("*/*").getSchema(); assertNotNull(responseSchema); assertTrue(responseSchema instanceof ObjectSchema); assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean); }
@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); }
@Test(description = "vendor extensions should be included with object type") public void testMapDeserializationVendorExtensions() 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); MapSchema mp = (MapSchema) responseSchema; assertTrue(mp.getExtensions().size() > 0); assertNotNull(mp.getExtensions().get("x-foo")); assertEquals(mp.getExtensions().get("x-foo"), "vendor x"); }
@Test(description = "it should includes the example in the arrayproperty") public void testArrayDeserialization() throws Exception { Operation operation = Yaml.mapper().readValue(yaml, Operation.class); ApiResponse response = operation.getResponses().get("200"); assertNotNull(response); MediaType media = response.getContent().get("*/*"); Schema responseSchema = media.getSchema(); assertTrue(media.getExamples().size() == 2); assertNotNull(responseSchema); assertTrue(responseSchema instanceof ArraySchema); ArraySchema mp = (ArraySchema) responseSchema; assertEquals(mp.getMinItems(), new Integer(3)); assertEquals(mp.getMaxItems(), new Integer(100)); } }
@Test(description = "it should read an example within an inlined schema") public void testIssue1261InlineSchemaExample() throws Exception { Operation operation = Yaml.mapper().readValue( " responses:\n" + " 200:\n" + " content:\n" + " '*/*':\n" + " description: OK\n" + " schema:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int32\n" + " name:\n" + " type: string\n" + " required: [id, name]\n" + " example: ok", Operation.class); ApiResponse response = operation.getResponses().get("200"); assertNotNull(response); Schema schema = response.getContent().get("*/*").getSchema(); Object example = schema.getExample(); assertNotNull(example); assertTrue(example instanceof String); assertEquals(example, "ok"); } }
if (paramSchema == null) { if (parameter.getContent() != null && parameter.getContent().values().size() > 0) { paramSchema = parameter.getContent().values().iterator().next().getSchema();
if (requestBodyParameter.getSchema() != null) { for (MediaType mediaType : requestBody.getContent().values()) { if (mediaType.getSchema() == null) { if (requestBodyParameter.getSchema() == null) { mediaType.setSchema(new Schema()); if (StringUtils.isBlank(mediaType.getSchema().getType())) { mediaType.getSchema().setType(requestBodyParameter.getSchema().getType());
@Test(description = "it should serialize a boolean additionalProperties") public void testBooleanAdditionalPropertiesSerialization() throws Exception { Operation operation = Json.mapper().readValue(json, Operation.class); ApiResponse response = operation.getResponses().get("200"); assertNotNull(response); Schema responseSchema = response.getContent().get("*/*").getSchema(); Schema schema = new ObjectSchema().additionalProperties(true); assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : true\n" + "}"); schema = new ObjectSchema().additionalProperties(responseSchema); assertEquals(normalizeLineEnds(Json.pretty(schema)), "{\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : {\n" + " \"type\" : \"object\",\n" + " \"additionalProperties\" : {\n" + " \"type\" : \"integer\",\n" + " \"format\" : \"int32\"\n" + " },\n" + " \"x-foo\" : \"vendor x\"\n" + " }\n" + "}"); }
} else { for (String key : operation.getResponses().getDefault().getContent().keySet()) { if (operation.getResponses().getDefault().getContent().get(key).getSchema() == null) { operation.getResponses().getDefault().getContent().get(key).setSchema(returnTypeSchema);
protected void updateLocalRefs(RequestBody body, String pathRef) { if(body.getContent() != null) { Map<String, MediaType> content = body.getContent(); for (String key: content.keySet()) { MediaType mediaType = content.get(key); if (mediaType.getSchema() != null) { updateLocalRefs(mediaType.getSchema(), pathRef); } } }else if(body.get$ref() != null){ } }
protected void updateLocalRefs(RequestBody body, String pathRef) { if(body.getContent() != null) { Map<String, MediaType> content = body.getContent(); for (String key: content.keySet()) { MediaType mediaType = content.get(key); if (mediaType.getSchema() != null) { updateLocalRefs(mediaType.getSchema(), pathRef); } } }else if(body.get$ref() != null){ } }
private static Schema getSchemaFromContent(Content content) { if (content == null || content.isEmpty()) { return null; } if (content.size() > 1) { LOGGER.warn("Multiple schemas found, returning only the first one"); } MediaType mediaType = content.values().iterator().next(); return mediaType.getSchema(); }
protected Schema getSchemaFromBody(RequestBody requestBody) { String contentType = new ArrayList<>(requestBody.getContent().keySet()).get(0); MediaType mediaType = requestBody.getContent().get(contentType); return mediaType.getSchema(); }
protected Schema getSchemaFromBody(RequestBody requestBody) { String contentType = new ArrayList<>(requestBody.getContent().keySet()).get(0); MediaType mediaType = requestBody.getContent().get(contentType); return mediaType.getSchema(); }
private void addContentSchemaRef(Content content, Set<String> referencedDefinitions) { if (content != null) { for (String keyBodyContent : content.keySet()) { MediaType mediaType = content.get(keyBodyContent); addSchemaRef(mediaType.getSchema(), referencedDefinitions); } } }
protected Schema getSchemaFromResponse(ApiResponse response) { if (response.getContent() == null || response.getContent().isEmpty()) { return null; } Schema schema = null; for (MediaType mediaType : response.getContent().values()) { schema = mediaType.getSchema(); break; } return schema; }
protected Schema getSchemaFromResponse(ApiResponse response) { if (response.getContent() == null || response.getContent().isEmpty()) { return null; } Schema schema = null; for (MediaType mediaType : response.getContent().values()) { schema = mediaType.getSchema(); break; } return schema; }
@Override public BallerinaMediaType buildContext(MediaType mediaType, OpenAPI openAPI) throws BallerinaOpenApiException { this.example = mediaType.getExample(); this.extensions = mediaType.getExtensions(); this.encoding = mediaType.getEncoding(); this.examples = mediaType.getExamples(); this.schema = new BallerinaSchema().buildContext(mediaType.getSchema(), openAPI); return this; }