@Test public void shouldGetOperationParameterFromFormData() { Oas30Document openApiDoc = new Oas30Document(); openApiDoc.paths = openApiDoc.createPaths(); Oas30PathItem pathItem = (Oas30PathItem) openApiDoc.paths.createPathItem("/test/{id}"); openApiDoc.paths.addPathItem("test", pathItem); Oas30Operation operation = (Oas30Operation) pathItem.createOperation("get"); operation.requestBody = operation.createRequestBody(); Oas30MediaType formData = operation.requestBody.createMediaType("formData"); formData.schema = formData.createSchema(); formData.schema.addProperty("name", formData.createSchema()); formData.schema.addProperty("age", formData.createSchema()); operation.requestBody.content.put(Oas30FormDataHelper.MediaType.FORM_URLENCODED.mediaType(), formData); pathItem.get = operation; List<Oas30Parameter> operationParameters = Oas30DataShapeGeneratorHelper.getOperationParameters(openApiDoc, operation); Assertions.assertThat(operationParameters).hasSize(2); Assertions.assertThat(operationParameters).allMatch(p -> "formData".equals(p.in)); Assertions.assertThat(operationParameters).anyMatch(p -> "name".equals(p.name)); Assertions.assertThat(operationParameters).anyMatch(p -> "age".equals(p.name)); }
static List<Oas30Parameter> getOperationParameters(Oas30Document openApiDoc, Oas30Operation operation) { final List<Oas30Parameter> operationParameters = getParameters(openApiDoc, operation); OasPathItem parent = ofNullable(operation.parent()) .filter(OasPathItem.class::isInstance) .map(OasPathItem.class::cast) .orElse(null); final List<Oas30Parameter> pathParameters = getParameters(openApiDoc, parent); operationParameters.addAll(pathParameters); return operationParameters .stream() .distinct() .collect(Collectors.toList()); }
Oas30DataShapeGeneratorHelper { static List<Oas30Parameter> getOperationParameters(Oas30Document openApiDoc, Oas30Operation operation) { final List<Oas30Parameter> operationParameters = getParameters(openApiDoc, operation); OasPathItem parent = ofNullable(operation.parent()) .filter(OasPathItem.class::isInstance) .map(OasPathItem.class::cast) .orElse(null); final List<Oas30Parameter> pathParameters = getParameters(openApiDoc, parent); operationParameters.addAll(pathParameters); return operationParameters .stream() .distinct() .collect(Collectors.toList()); } }
Oas30DataShapeGeneratorHelper { static List<Oas30Parameter> getOperationParameters(Oas30Document openApiDoc, Oas30Operation operation) { final List<Oas30Parameter> operationParameters = getParameters(openApiDoc, operation); OasPathItem parent = ofNullable(operation.parent()) .filter(OasPathItem.class::isInstance) .map(OasPathItem.class::cast) .orElse(null); final List<Oas30Parameter> pathParameters = getParameters(openApiDoc, parent); operationParameters.addAll(pathParameters); return operationParameters .stream() .distinct() .collect(Collectors.toList()); } private  Oas30DataShapeGeneratorHelper(); }
Oas30DataShapeGeneratorHelper { static List<Oas30Parameter> getOperationParameters(Oas30Document openApiDoc, Oas30Operation operation) { final List<Oas30Parameter> operationParameters = getParameters(openApiDoc, operation); OasPathItem parent = ofNullable(operation.parent()) .filter(OasPathItem.class::isInstance) .map(OasPathItem.class::cast) .orElse(null); final List<Oas30Parameter> pathParameters = getParameters(openApiDoc, parent); operationParameters.addAll(pathParameters); return operationParameters .stream() .distinct() .collect(Collectors.toList()); } private  Oas30DataShapeGeneratorHelper();  }
Oas30DataShapeGeneratorHelper { static List<Oas30Parameter> getOperationParameters(Oas30Document openApiDoc, Oas30Operation operation) { final List<Oas30Parameter> operationParameters = getParameters(openApiDoc, operation); OasPathItem parent = ofNullable(operation.parent()) .filter(OasPathItem.class::isInstance) .map(OasPathItem.class::cast) .orElse(null); final List<Oas30Parameter> pathParameters = getParameters(openApiDoc, parent); operationParameters.addAll(pathParameters); return operationParameters .stream() .distinct() .collect(Collectors.toList()); } private  Oas30DataShapeGeneratorHelper();   }