@Test public void shouldNotHaveDuplicateOperationParameters() { Oas30Document openApiDoc = new Oas30Document(); openApiDoc.components = openApiDoc.createComponents(); Oas30ParameterDefinition globalParameter = openApiDoc.components.createParameterDefinition("version"); openApiDoc.components.addParameterDefinition("Version", globalParameter); openApiDoc.paths = openApiDoc.createPaths(); Oas30PathItem pathItem = (Oas30PathItem) openApiDoc.paths.createPathItem("/test/{id}"); openApiDoc.paths.addPathItem("test", pathItem); Oas30Parameter pathParameter = (Oas30Parameter) pathItem.createParameter(); pathParameter.$ref = "#components/parameters/Version"; pathItem.addParameter(pathParameter); Oas30Operation operation = (Oas30Operation) pathItem.createOperation("get"); pathItem.get = operation; Oas30Parameter operationParameter = (Oas30Parameter) operation.createParameter(); operationParameter.$ref = "#components/parameters/Version"; operation.addParameter(operationParameter); List<Oas30Parameter> operationParameters = Oas30DataShapeGeneratorHelper.getOperationParameters(openApiDoc, operation); Assertions.assertThat(operationParameters).hasSize(1); Assertions.assertThat(operationParameters).contains(globalParameter); }
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();   }