Skip to content

Commit

Permalink
feat(core): Skip schema post processor when previous post-processor r…
Browse files Browse the repository at this point in the history
…emoved the current schema

Example: an avro schema is removed. Then the next post-processor (example generator) does not need to be called.
Also, it avoids the error message due to unresolvable avro schemas
  • Loading branch information
timonback committed Feb 9, 2024
1 parent e3bd3ec commit 5f6f1cb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ private <R> R runWithFqnSetting(Function<Void, R> callable) {
}

private void postProcessSchema(Schema schema) {
schemaPostProcessors.forEach(processor -> processor.process(schema, schemas));
for (SchemasPostProcessor processor : schemaPostProcessors) {
processor.process(schema, schemas);

if (!schemas.containsValue(schema)) {
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;

class DefaultSchemasServiceTest {
private final SchemasPostProcessor schemasPostProcessor = Mockito.mock(SchemasPostProcessor.class);
private final SchemasPostProcessor schemasPostProcessor2 = Mockito.mock(SchemasPostProcessor.class);
private final ComponentsService componentsService = new DefaultComponentsService(
List.of(),
List.of(new ExampleGeneratorPostProcessor(new ExampleJsonGenerator()), schemasPostProcessor),
List.of(
new ExampleGeneratorPostProcessor(new ExampleJsonGenerator()),
schemasPostProcessor,
schemasPostProcessor2),
new SwaggerSchemaUtil(),
new SpringwolfConfigProperties());

Expand Down Expand Up @@ -165,6 +171,22 @@ void postProcessorsAreCalled() {
componentsService.registerSchema(FooWithEnum.class);

verify(schemasPostProcessor).process(any(), any());
verify(schemasPostProcessor2).process(any(), any());
}

@Test
void postProcessorIsSkippedWhenSchemaWasRemoved() {
doAnswer(invocationOnMock -> {
Map<String, io.swagger.v3.oas.models.media.Schema> schemas = invocationOnMock.getArgument(1);
schemas.clear();
return null;
})
.when(schemasPostProcessor)
.process(any(), any());

componentsService.registerSchema(FooWithEnum.class);

verifyNoInteractions(schemasPostProcessor2);
}

private String jsonResource(String path) throws IOException {
Expand Down

0 comments on commit 5f6f1cb

Please sign in to comment.