use of org.springdoc.core.SpringDocConfigProperties in project springdoc-openapi by springdoc.
the class AbstractOpenApiResourceTest method preLoadingModeShouldNotOverwriteServers.
@Test
void preLoadingModeShouldNotOverwriteServers() throws InterruptedException {
when(openAPIService.updateServers(any())).thenCallRealMethod();
when(openAPIService.getCachedOpenAPI(any())).thenCallRealMethod();
doAnswer(new CallsRealMethods()).when(openAPIService).setServersPresent(true);
doAnswer(new CallsRealMethods()).when(openAPIService).setServerBaseUrl(any());
doAnswer(new CallsRealMethods()).when(openAPIService).setCachedOpenAPI(any(), any());
String customUrl = "https://custom.com";
String generatedUrl = "https://generated.com";
OpenApiCustomiser openApiCustomiser = openApi -> openApi.setServers(singletonList(new Server().url(customUrl)));
SpringDocConfigProperties properties = new SpringDocConfigProperties();
properties.setPreLoadingEnabled(true);
resource = new EmptyPathsOpenApiResource(GROUP_NAME, openAPIBuilderObjectFactory, requestBuilder, responseBuilder, operationParser, Optional.empty(), Optional.of(singletonList(openApiCustomiser)), Optional.empty(), properties, springDocProviders);
// wait for executor to be done
Thread.sleep(1_000);
// emulate generating base url
openAPIService.setServerBaseUrl(generatedUrl);
openAPIService.updateServers(openAPI);
Locale locale = Locale.US;
OpenAPI after = resource.getOpenApi(locale);
assertThat(after.getServers().get(0).getUrl(), is(customUrl));
}
use of org.springdoc.core.SpringDocConfigProperties in project springdoc-openapi by springdoc.
the class AbstractOpenApiResourceTest method calculatePathFromRouterOperation.
@Test
void calculatePathFromRouterOperation() {
resource = new EmptyPathsOpenApiResource(GROUP_NAME, openAPIBuilderObjectFactory, requestBuilder, responseBuilder, operationParser, Optional.empty(), Optional.empty(), Optional.empty(), new SpringDocConfigProperties(), springDocProviders);
final Parameter refParameter = new Parameter().$ref(PARAMETER_REFERENCE);
final Parameter numberParameterInPath = new Parameter().name(PARAMETER_WITH_NUMBER_SCHEMA_NAME).in(ParameterIn.PATH.toString()).schema(new NumberSchema());
final Parameter parameterWithoutSchema = new Parameter().name(PARAMETER_WITHOUT_SCHEMA_NAME);
final Operation operation = new Operation();
operation.setParameters(asList(refParameter, numberParameterInPath, parameterWithoutSchema));
final RouterOperation routerOperation = new RouterOperation();
routerOperation.setMethods(new RequestMethod[] { GET });
routerOperation.setOperationModel(operation);
routerOperation.setPath(PATH);
resource.calculatePath(routerOperation, Locale.getDefault());
final List<Parameter> parameters = resource.getOpenApi(Locale.getDefault()).getPaths().get(PATH).getGet().getParameters();
assertThat(parameters.size(), is(3));
assertThat(parameters, containsInAnyOrder(refParameter, numberParameterInPath, parameterWithoutSchema));
assertThat(refParameter.getName(), nullValue());
assertThat(refParameter.get$ref(), is(PARAMETER_REFERENCE));
assertThat(refParameter.getSchema(), nullValue());
assertThat(refParameter.getIn(), nullValue());
assertThat(numberParameterInPath.getName(), is(PARAMETER_WITH_NUMBER_SCHEMA_NAME));
assertThat(numberParameterInPath.get$ref(), nullValue());
assertThat(numberParameterInPath.getSchema(), is(new NumberSchema()));
assertThat(numberParameterInPath.getIn(), is(ParameterIn.PATH.toString()));
assertThat(parameterWithoutSchema.getName(), is(PARAMETER_WITHOUT_SCHEMA_NAME));
assertThat(parameterWithoutSchema.get$ref(), nullValue());
assertThat(parameterWithoutSchema.getSchema(), is(new StringSchema()));
assertThat(parameterWithoutSchema.getIn(), is(ParameterIn.QUERY.toString()));
}
use of org.springdoc.core.SpringDocConfigProperties in project jhipster-bom by jhipster.
the class JHipsterSpringDocGroupsConfiguration method openAPIDefaultGroupedOpenAPI.
/**
* OpenApi default group configuration.
*
* @return the GroupedOpenApi configuration
*/
@Bean
@ConditionalOnMissingBean(name = "openAPIDefaultGroupedOpenAPI")
public GroupedOpenApi openAPIDefaultGroupedOpenAPI(List<OpenApiCustomiser> openApiCustomisers, List<OperationCustomizer> operationCustomizers, @Qualifier("apiFirstGroupedOpenAPI") Optional<GroupedOpenApi> apiFirstGroupedOpenAPI, SpringDocConfigProperties springDocConfigProperties) {
log.debug("Initializing JHipster OpenApi default group");
Builder builder = GroupedOpenApi.builder().group(DEFAULT_GROUP_NAME).pathsToMatch(properties.getDefaultIncludePattern());
openApiCustomisers.stream().filter(customiser -> !(customiser instanceof ActuatorOpenApiCustomizer)).forEach(builder::addOpenApiCustomiser);
operationCustomizers.stream().filter(customiser -> !(customiser instanceof ActuatorOperationCustomizer)).forEach(builder::addOperationCustomizer);
apiFirstGroupedOpenAPI.ifPresent(apiFirst -> {
if (apiFirst.getPackagesToScan() != null) {
apiFirst.getPackagesToScan().stream().forEach(builder::packagesToExclude);
}
});
return builder.build();
}
Aggregations