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); } } }
operation.getRequestBody().setContent(content); } else if (parentRequestBody.getContent() != null){ for (String parentMediaType: parentRequestBody.getContent().keySet()) { if (content.get(parentMediaType) == null) { content.addMediaType(parentMediaType, parentRequestBody.getContent().get(parentMediaType)); operation.getResponses().getDefault().content(content); } 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);
private Optional<Pair<String, MediaType>> findApiMediaTypeForRequest(final Request request, @Nullable final RequestBody apiRequestBodyDefinition) { if (apiRequestBodyDefinition == null || apiRequestBodyDefinition.getContent() == null) { return Optional.empty(); } final Optional<String> mostSpecificMatch = findMostSpecificMatch(request, apiRequestBodyDefinition.getContent().keySet()); if (!mostSpecificMatch.isPresent()) { return Optional.empty(); } final MediaType mediaType = apiRequestBodyDefinition.getContent().get(mostSpecificMatch.get()); return Optional.of(Pair.of(mostSpecificMatch.get(), mediaType)); }
@Nonnull private Collection<String> getProduces(final ApiOperation apiOperation) { return apiOperation.getOperation() .getResponses() .values() .stream() .filter(apiResponse -> apiResponse.getContent() != null) .flatMap(apiResponse -> apiResponse.getContent().keySet().stream()) .collect(Collectors.toSet()); }
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(); }
@Nonnull private Collection<String> getResponseMediaTypes(final Response response, final ApiOperation apiOperation) { final ApiResponse apiResponse = getApiResponse(response, apiOperation); if (apiResponse == null) { return emptyList(); } return defaultIfNull(apiResponse.getContent(), new Content()).keySet(); }
protected String getContentType(RequestBody requestBody) { if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) { return null; } return new ArrayList<>(requestBody.getContent().keySet()).get(0); }
protected String getContentType(RequestBody requestBody) { if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) { return null; } return new ArrayList<>(requestBody.getContent().keySet()).get(0); }
protected String getContentType(RequestBody requestBody) { if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) { return null; } return new ArrayList<>(requestBody.getContent().keySet()).get(0); }
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); } } }
@Nonnull private Collection<String> getConsumes(final ApiOperation apiOperation) { if (apiOperation.getOperation().getRequestBody() == null) { return emptyList(); } return defaultIfNull(apiOperation.getOperation().getRequestBody().getContent().keySet(), emptySet()); }
protected void addProducesInfo(ApiResponse response, CodegenOperation codegenOperation) { if(response == null || response.getContent() == null || response.getContent().isEmpty()) { return; } Set<String> produces = response.getContent().keySet(); if(codegenOperation.produces == null) { codegenOperation.produces = new ArrayList<>(); } for (String key : produces) { Map<String, String> mediaType = new HashMap<String, String>(); // escape quotation to avoid code injection if ("*/*".equals(key)) { // "*/*" is a special case, do nothing mediaType.put("mediaType", key); } else { mediaType.put("mediaType", escapeText(escapeQuotationMark(key))); } mediaType.put("hasMore", "true"); codegenOperation.produces.add(mediaType); codegenOperation.getVendorExtensions().put(CodegenConstants.HAS_PRODUCES_EXT_NAME, Boolean.TRUE); } }
protected void addProducesInfo(ApiResponse response, CodegenOperation codegenOperation) { if(response == null || response.getContent() == null || response.getContent().isEmpty()) { return; } Set<String> produces = response.getContent().keySet(); if(codegenOperation.produces == null) { codegenOperation.produces = new ArrayList<>(); } for (String key : produces) { Map<String, String> mediaType = new HashMap<String, String>(); // escape quotation to avoid code injection if ("*/*".equals(key)) { // "*/*" is a special case, do nothing mediaType.put("mediaType", key); } else { mediaType.put("mediaType", escapeText(escapeQuotationMark(key))); } mediaType.put("hasMore", "true"); codegenOperation.produces.add(mediaType); codegenOperation.getVendorExtensions().put(CodegenConstants.HAS_PRODUCES_EXT_NAME, Boolean.TRUE); } }
public static Set<String> getConsumesInfo(OpenAPI openAPI, Operation operation) { RequestBody requestBody = ModelUtils.getReferencedRequestBody(openAPI, operation.getRequestBody()); if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) { return Collections.emptySet(); // return empty set } return requestBody.getContent().keySet(); }
/** * returns the list of MIME types the APIs can produce * * @param openAPI current specification instance * @param operation Operation * @return a set of MIME types */ public static Set<String> getProducesInfo(OpenAPI openAPI, Operation operation) { if (operation.getResponses() == null || operation.getResponses().isEmpty()) { return null; } Set<String> produces = new TreeSet<String>(); for (ApiResponse r : operation.getResponses().values()) { ApiResponse response = ModelUtils.getReferencedApiResponse(openAPI, r); if (response.getContent() != null) { produces.addAll(response.getContent().keySet()); } } return produces; }
protected Set<String> getConsumesInfo(Operation operation) { if(operation.getRequestBody() == null || operation.getRequestBody().getContent() == null || operation.getRequestBody().getContent().isEmpty()) { return null; } return operation.getRequestBody().getContent().keySet(); }
protected Set<String> getConsumesInfo(Operation operation) { if(operation.getRequestBody() == null || operation.getRequestBody().getContent() == null || operation.getRequestBody().getContent().isEmpty()) { return null; } return operation.getRequestBody().getContent().keySet(); }
protected <T> void updateLocalRefs(String file, T result) { if(result instanceof ApiResponse) { ApiResponse response = (ApiResponse) result; if (response.getContent() != null) { for (String mediaType : response.getContent().keySet()) { updateLocalRefs(file, response.getContent().get(mediaType).getSchema()); } } } if(result instanceof Schema && ((Schema)(result)).get$ref() != null) { Schema prop = (Schema) result; updateLocalRefs(file, prop); } else if(result instanceof Schema) { Schema model = (Schema) result; updateLocalRefs(file, model); } }
protected <T> void updateLocalRefs(String file, T result) { if(result instanceof ApiResponse) { ApiResponse response = (ApiResponse) result; if (response.getContent() != null) { for (String mediaType : response.getContent().keySet()) { updateLocalRefs(file, response.getContent().get(mediaType).getSchema()); } } } if(result instanceof Schema && ((Schema)(result)).get$ref() != null) { Schema prop = (Schema) result; updateLocalRefs(file, prop); } else if(result instanceof Schema) { Schema model = (Schema) result; updateLocalRefs(file, model); } }