Skip to content

Commit

Permalink
Merge branch 'master' into feat/process-meta-annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0r040 authored Nov 24, 2023
2 parents 7f007f8 + 6b7d4b0 commit 8577201
Show file tree
Hide file tree
Showing 87 changed files with 996 additions and 1,591 deletions.
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ Contributing follows mostly the following steps:

1. For bigger changes, open an [issue](https://github.com/springwolf/springwolf-core/issues) and/or drop by on our discord so that we can coordinate.
2. Fork the repository
- Create a new branch
3. Apply your changes
- Add/Adapt tests as necessary
4. Run the tests
- Run tests locally via `./gradlew test`
- Run tests locally via `./gradlew test` (includes `unitTest` and `integrationTest` targets, which executes faster)
5. Run the code formatter
- We use the palantir code style and disallow wildcard imports
- Run `./gradlew spotlessApply` to fix most things automatically
6. Commit your changes & push
7. Open a Pull-Request against the springwolf repository
- Use the provided template to briefly describe why the changes should be included
8. Update the [documentation](https://github.com/springwolf/springwolf.github.io) as necessary
9. Add yourself to the contributors and your company to the users in [README.md](README.md)

21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

**Automated documentation for event-driven applications built with Spring Boot**

![Last Version](https://img.shields.io/github/tag-pre/springwolf/springwolf-core.svg)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![springwolf-core](https://github.com/springwolf/springwolf-core/actions/workflows/springwolf-core.yml/badge.svg)](https://github.com/springwolf/springwolf-core/actions/workflows/springwolf-core.yml)
[![springwolf-ui](https://github.com/springwolf/springwolf-core/actions/workflows/springwolf-ui.yml/badge.svg)](https://github.com/springwolf/springwolf-core/actions/workflows/springwolf-ui.yml)
Expand All @@ -16,6 +17,7 @@
- [Demo & Documentation](#demo--documentation)
- [Why You Should Use It](#why-you-should-use-it)
- [Usage & Example](#usage--example)
- [Who's Using Springwolf](#whos-using-springwolf)
- [Development](#development)
- [Contributors](#contributors)

Expand All @@ -37,12 +39,12 @@ The documentation and quickstart is available on [springwolf.dev](https://www.sp
Springwolf exploits the fact that you already fully described your consumer endpoint (with listener annotations, such as
`@KafkaListener`, `@RabbitListener`, `@SqsListener`, etc.) and generates the documentation based on this information.

#### Share API Schema Definition
#### 1. Share API Schema Definition

The AsyncAPI conform documentation can be integrated into API hubs (like [backstage](https://backstage.io/docs/features/software-catalog/descriptor-format/))
or be shared as a `json`/`yaml` file with others.

#### UI Based API Testing
#### 2. UI Based API Testing
In projects using asynchronous APIs, you may often find yourself needing to manually send a message to some topic,
whether you are manually testing a new feature, debugging or trying to understand some flow.

Expand All @@ -66,8 +68,22 @@ More details in the documentation.
| [Generic Binding](https://github.com/springwolf/springwolf-core/tree/master/springwolf-add-ons/springwolf-generic-binding) | | ![Maven Central](https://img.shields.io/maven-central/v/io.github.springwolf/springwolf-generic-binding?color=green&label=springwolf-generic-binding&style=plastic) | ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.springwolf/springwolf-generic-binding?label=springwolf-generic-binding&server=https%3A%2F%2Fs01.oss.sonatype.org&style=plastic) |
| [Json Schema](https://github.com/springwolf/springwolf-core/tree/master/springwolf-add-ons/springwolf-json-schema) | | ![Maven Central](https://img.shields.io/maven-central/v/io.github.springwolf/springwolf-json-schema?color=green&label=springwolf-json-schema&style=plastic) | ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.springwolf/springwolf-json-schema?label=springwolf-json-schema&server=https%3A%2F%2Fs01.oss.sonatype.org&style=plastic) |

### Who's Using Springwolf

- [b.well Connected Health](https://www.icanbwell.com/)
- [LVM Versicherung](https://www.lvm.de/privatkunden/)
- [OTTO](https://www.otto.de)
- [Teambank](https://www.teambank.de)

Comment in [this PR](https://github.com/springwolf/springwolf-core/issues/342) to add your company and spread the word

### Development

Check out our [CONTRIBUTING.md](CONTRIBUTING.md) guide.

<details>
<summary>Using SNAPSHOT version</summary>

#### Sonatype snapshots

Add the following to the `repositories` closure in `build.gradle`:
Expand Down Expand Up @@ -100,6 +116,7 @@ Or add the `repository` to your `pom.xml` if you are using maven:
#### Local Snapshot Build

To work with local builds, run the `publishToMavenLocal` task. The current version number is set in [`.env`](.env) file.
</details>

### Contributors

Expand Down
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ buildscript {
plugins {
id 'ca.cutterslade.analyze' version '1.9.1'
id 'io.spring.dependency-management' version '1.1.4' apply false
id 'org.springframework.boot' version '3.1.5' apply false
id 'org.owasp.dependencycheck' version '8.4.2'
id 'org.springframework.boot' version '3.2.0' apply false
id 'org.owasp.dependencycheck' version '8.4.3'
id 'com.diffplug.spotless' version '6.22.0'
id 'com.bmuschko.docker-spring-boot-application' version '9.3.7' apply false
}
Expand Down Expand Up @@ -66,6 +66,9 @@ allprojects {
test {
dependsOn spotlessApply // Automatically fix code formatting if possible

minHeapSize = "128m" // initial heap size
maxHeapSize = "1024m" // maximum heap size

useJUnitPlatform()
testLogging {
// showStandardStreams = true
Expand Down
8 changes: 3 additions & 5 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@
* The dependencies are sorted alphabetically.
*/
ext {
androidJsonVersion = '0.0.20131108.vaadin1'

assertjCoreVersion = '3.24.2'

asyncapiCoreVersion = '1.0.0-EAP-2'

awaitilityVersion = '4.2.0'

commonsLang3Version = '3.13.0'
commonsLang3Version = '3.14.0'

jsr305Version = '3.0.2'

kafkaClientsVersion = '3.6.0'
kafkaStreamsVersion = '3.6.0'

jacksonVersion = '2.15.3'
jacksonVersion = '2.16.0'
jakartaAnnotationApiVersion = '2.1.1'

jsonSchemaValidator = '1.0.87'
Expand All @@ -59,5 +57,5 @@ ext {

swaggerVersion = '2.2.19'

testcontainersVersion = '1.19.1'
testcontainersVersion = '1.19.3'
}
1 change: 0 additions & 1 deletion springwolf-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-params:${junitJupiterVersion}")
testImplementation "org.assertj:assertj-core:${assertjCoreVersion}"
testImplementation "org.awaitility:awaitility:${awaitilityVersion}"
testImplementation "com.vaadin.external.google:android-json:${androidJsonVersion}"
testImplementation "org.mockito:mockito-core:${mockitoCoreVersion}"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "org.springframework:spring-test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.stavshamir.springwolf.asyncapi.DefaultChannelsService;
import io.github.stavshamir.springwolf.asyncapi.SpringwolfInitApplicationListener;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.payload.PayloadClassExtractor;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import io.github.stavshamir.springwolf.configuration.DefaultAsyncApiDocketService;
Expand Down Expand Up @@ -86,4 +87,10 @@ public AsyncApiDocketService asyncApiDocketService(
public ExampleGenerator exampleGenerator() {
return new ExampleJsonGenerator();
}

@Bean
@ConditionalOnMissingBean
public PayloadClassExtractor payloadClassExtractor(SpringwolfConfigProperties springwolfConfigProperties) {
return new PayloadClassExtractor(springwolfConfigProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.ProducerOperationDataScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListenerAnnotationScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisherAnnotationScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.payload.PayloadClassExtractor;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ConfigurationClassScanner;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
Expand Down Expand Up @@ -80,12 +81,14 @@ public AsyncListenerAnnotationScanner asyncListenerAnnotationScanner(
ComponentClassScanner componentClassScanner,
SchemasService schemasService,
AsyncApiDocketService asyncApiDocketService,
PayloadClassExtractor payloadClassExtractor,
List<OperationBindingProcessor> operationBindingProcessors,
List<MessageBindingProcessor> messageBindingProcessors) {
return new AsyncListenerAnnotationScanner(
componentClassScanner,
schemasService,
asyncApiDocketService,
payloadClassExtractor,
operationBindingProcessors,
messageBindingProcessors);
}
Expand All @@ -100,12 +103,14 @@ public AsyncPublisherAnnotationScanner asyncPublisherAnnotationScanner(
ComponentClassScanner componentClassScanner,
SchemasService schemasService,
AsyncApiDocketService asyncApiDocketService,
PayloadClassExtractor payloadClassExtractor,
List<OperationBindingProcessor> operationBindingProcessors,
List<MessageBindingProcessor> messageBindingProcessors) {
return new AsyncPublisherAnnotationScanner(
componentClassScanner,
schemasService,
asyncApiDocketService,
payloadClassExtractor,
operationBindingProcessors,
messageBindingProcessors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.asyncapi.v2.binding.operation.OperationBinding;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelMerger;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.payload.PayloadClassExtractor;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner;
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.Message;
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.PayloadReference;
Expand Down Expand Up @@ -35,7 +36,6 @@
import java.util.stream.Collectors;

import static io.github.stavshamir.springwolf.asyncapi.MessageHelper.toMessageObjectOrComposition;
import static io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.SpringPayloadAnnotationTypeExtractor.getPayloadType;
import static java.util.stream.Collectors.toSet;

@Slf4j
Expand All @@ -48,6 +48,8 @@ public abstract class AbstractClassLevelListenerScanner<

private final SchemasService schemasService;

protected final PayloadClassExtractor payloadClassExtractor;

/**
* This annotation is used on class level
*
Expand Down Expand Up @@ -185,7 +187,7 @@ private Object getMessageObject(Set<Method> methods) {
}

private Message buildMessage(Method method) {
Class<?> payloadType = getPayloadType(method);
Class<?> payloadType = payloadClassExtractor.extractFrom(method);
String modelName = schemasService.register(payloadType);
String headerModelName = schemasService.register(this.buildHeaders(method));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private List<Map.Entry<String, ChannelItem>> mapToChannels(Set<Class<?>> compone
* @param method The listener method.
* @return The class object of the payload received by the listener.
*/
// TODO: Inject SpringPayloadAnnotationTypeExtractor here with default implementation?
protected abstract Class<?> getPayloadType(Method method);

private Set<Method> getAnnotatedMethods(Class<?> type) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.asyncapi.v2.binding.operation.OperationBinding;
import io.github.stavshamir.springwolf.asyncapi.scanners.bindings.MessageBindingProcessor;
import io.github.stavshamir.springwolf.asyncapi.scanners.bindings.OperationBindingProcessor;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.SpringPayloadAnnotationTypeExtractor;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.AbstractOperationDataScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.payload.PayloadClassExtractor;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner;
import io.github.stavshamir.springwolf.asyncapi.types.ConsumerData;
import io.github.stavshamir.springwolf.asyncapi.types.OperationData;
Expand Down Expand Up @@ -40,8 +40,9 @@ public class AsyncListenerAnnotationScanner extends AbstractOperationDataScanner
private final SchemasService schemasService;
private final AsyncApiDocketService asyncApiDocketService;

private final List<OperationBindingProcessor> operationBindingProcessors;
private final PayloadClassExtractor payloadClassExtractor;

private final List<OperationBindingProcessor> operationBindingProcessors;
private final List<MessageBindingProcessor> messageBindingProcessors;

@Override
Expand Down Expand Up @@ -108,10 +109,8 @@ private ConsumerData toConsumerData(
Message message,
AsyncListener annotation) {
AsyncOperation op = annotation.operation();
Class<?> payloadType = op.payloadType() != Object.class
? op.payloadType()
: SpringPayloadAnnotationTypeExtractor.getPayloadType(method);

Class<?> payloadType =
op.payloadType() != Object.class ? op.payloadType() : payloadClassExtractor.extractFrom(method);
return ConsumerData.builder()
.channelName(resolver.resolveStringValue(op.channelName()))
.description(resolver.resolveStringValue(op.description()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.asyncapi.v2.binding.operation.OperationBinding;
import io.github.stavshamir.springwolf.asyncapi.scanners.bindings.MessageBindingProcessor;
import io.github.stavshamir.springwolf.asyncapi.scanners.bindings.OperationBindingProcessor;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.SpringPayloadAnnotationTypeExtractor;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.AbstractOperationDataScanner;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.payload.PayloadClassExtractor;
import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner;
import io.github.stavshamir.springwolf.asyncapi.types.OperationData;
import io.github.stavshamir.springwolf.asyncapi.types.ProducerData;
Expand Down Expand Up @@ -40,8 +40,9 @@ public class AsyncPublisherAnnotationScanner extends AbstractOperationDataScanne
private final SchemasService schemasService;
private final AsyncApiDocketService asyncApiDocketService;

private final List<OperationBindingProcessor> operationBindingProcessors;
private final PayloadClassExtractor payloadClassExtractor;

private final List<OperationBindingProcessor> operationBindingProcessors;
private final List<MessageBindingProcessor> messageBindingProcessors;

@Override
Expand Down Expand Up @@ -108,9 +109,8 @@ private ProducerData toConsumerData(
Message message,
AsyncPublisher annotation) {
AsyncOperation op = annotation.operation();
Class<?> payloadType = op.payloadType() != Object.class
? op.payloadType()
: SpringPayloadAnnotationTypeExtractor.getPayloadType(method);
Class<?> payloadType =
op.payloadType() != Object.class ? op.payloadType() : payloadClassExtractor.extractFrom(method);
return ProducerData.builder()
.channelName(resolver.resolveStringValue(op.channelName()))
.description(resolver.resolveStringValue(op.description()))
Expand Down
Loading

0 comments on commit 8577201

Please sign in to comment.