@Override public APIResponse filterAPIResponse(APIResponse apiResponse) { if("subscription successfully created".equals(apiResponse.getDescription())){ apiResponse.setDescription("filterAPIResponse - subscription successfully created"); } // testing child before parent filtering Content content = apiResponse.getContent(); if (content != null) { if (content.hasMediaType("application/json")) { Schema schema = content.getMediaType("application/json").getSchema(); if ("child - id of the new review".equals(schema.getDescription())) { schema.setDescription("parent - id of the new review"); } } } return apiResponse; }
checkSameObject(response, response.addHeader(headerKey, headerValue)); checkMapEntry(response.getHeaders(), headerKey, headerValue); assertEquals(response.getHeaders().size(), 1, "The map is expected to contain one entry."); response.removeHeader(headerKey); assertEquals(response.getHeaders().size(), 0, "The map is expected to be empty."); response.setHeaders(Collections.singletonMap(headerKey2, headerValue2)); checkMapEntry(response.getHeaders(), headerKey2, headerValue2); assertEquals(response.getHeaders().size(), 1, "The map is expected to contain one entry."); checkSameObject(response, response.addHeader(headerKey, headerValue)); checkMapEntry(response.getHeaders(), headerKey, headerValue); assertEquals(response.getHeaders().size(), 2, "The map is expected to contain two entries."); checkSameObject(response, response.addLink(linkKey, linkValue)); checkMapEntry(response.getLinks(), linkKey, linkValue); assertEquals(response.getLinks().size(), 1, "The map is expected to contain one entry."); response.removeLink(linkKey); assertEquals(response.getLinks().size(), 0, "The map is expected to be empty."); Link otherLinkValue = createConstructibleInstance(Link.class); response.setLinks(Collections.singletonMap(linkKey2, linkValue2)); checkMapEntry(response.getLinks(), linkKey2, linkValue2); assertEquals(response.getLinks().size(), 1, "The map is expected to contain one entry."); checkSameObject(response, response.addLink(linkKey, linkValue)); checkMapEntry(response.getLinks(), linkKey, linkValue); assertEquals(response.getLinks().size(), 2, "The map is expected to contain two entries.");
private void filterOperation(final Operation op) { ofNullable(op.getServers()).ifPresent(this::filterServers); ofNullable(op.getRequestBody()).ifPresent(it -> { if (delegate.filterRequestBody(it) == null) { op.requestBody(null); } }); ofNullable(op.getParameters()).ifPresent(this::filterParameters); ofNullable(op.getCallbacks()).ifPresent(this::filterCallbacks); ofNullable(op.getResponses()) .ifPresent(responses -> { responses.entrySet().stream() .filter(it -> delegate.filterAPIResponse(it.getValue()) == null) .map(Map.Entry::getKey) .collect(toList()) .forEach(responses::remove); responses.forEach((rk, response) -> { ofNullable(response.getLinks()).ifPresent(this::filterLinks); ofNullable(response.getContent()) .ifPresent(contents -> contents.values().forEach(content -> { ofNullable(content.getSchema()).ifPresent(schema -> { if (delegate.filterSchema(schema) == null) { content.setSchema(null); } }); })); }); }); }
it -> mapResponse(api.getComponents(), it, produces.orElse(null)), (a, b) -> b))); responses.values().stream() .filter(it -> it.getContent() == null || it.getContent().isEmpty() || it.getContent().values().stream().anyMatch(c -> c.getSchema() == null)) .forEach(v -> { Type returnType = m.getReturnType(); if (returnType == void.class || returnType == Response.class) { if (v.getContent() == null || v.getContent().isEmpty()) { final ContentImpl content = new ContentImpl(); if (Response.class == returnType || v.content(content); schemaProcessor.mapSchemaFromClass( api.getComponents(), returnType); if (v.getContent() == null || v.getContent().isEmpty()) { final ContentImpl content = new ContentImpl(); final MediaTypeImpl mediaType = new MediaTypeImpl(); mediaType.setSchema(schema); content.put("", mediaType); v.content(content); } else { v.getContent().values().stream() .filter(it -> it.getSchema() == null) .forEach(it -> it.schema(schema)); responses.values().stream().filter(r -> r.getContent() != null) .forEach(resp -> ofNullable(resp.getContent().remove("")) .ifPresent(updated -> produces.ifPresent(mt -> mt.forEach(type -> resp.getContent().put(type, updated)))));
.responses(new HashMap<String, APIResponse>()) .addResponse("FoundAirlines", OASFactory.createObject(APIResponse.class) .description("successfully found airlines") .content(OASFactory.createObject(Content.class) .addMediaType("application/json", OASFactory.createObject(MediaType.class) .schema(OASFactory.createObject(Schema.class) .type(Schema.SchemaType.ARRAY))))) .addResponse("FoundBookings", OASFactory.createObject(APIResponse.class) .description("Bookings retrieved") .content(OASFactory.createObject(Content.class) .addMediaType("application/json", OASFactory.createObject(MediaType.class) .schema(OASFactory.createObject(Schema.class) .responses(OASFactory.createObject(APIResponses.class) .addAPIResponse("404", OASFactory.createObject(APIResponse.class) .description("No airlines found") .content(OASFactory.createObject(Content.class) .addMediaType("n/a", OASFactory.createObject(MediaType.class))))))) .addPathItem("/availabilityModel", OASFactory.createObject(PathItem.class) .responses(OASFactory.createObject(APIResponses.class) .addAPIResponse("200", OASFactory.createObject(APIResponse.class) .description("successful operation") .content(OASFactory.createObject(Content.class) .addMediaType("application/json", OASFactory.createObject(MediaType.class) .schema(OASFactory.createObject(Schema.class) .ref("#/components.schemas.Flight"))))) .addAPIResponse("404", OASFactory.createObject(APIResponse.class)
summary("filterPathItem - added put operation") .responses(OASFactory.createObject(APIResponses.class).addAPIResponse("200", OASFactory.createObject(APIResponse.class).description("filterPathItem - successfully put airlines"))));