-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: dynamically determine mime types from application context
This is closer how Spring WebMVC/WebFlux actually negotiate and convert content types (aka mime types aka media types).
- Loading branch information
Showing
66 changed files
with
779 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
.../qaware/openapigeneratorforspring/common/operation/mimetype/ConsumesMimeTypeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.qaware.openapigeneratorforspring.common.operation.mimetype; | ||
|
||
import de.qaware.openapigeneratorforspring.common.paths.HandlerMethod; | ||
import de.qaware.openapigeneratorforspring.common.util.OpenApiOrderedUtils; | ||
import org.springframework.util.MimeType; | ||
|
||
import java.util.Set; | ||
|
||
public interface ConsumesMimeTypeProvider extends OpenApiOrderedUtils.DefaultOrdered { | ||
Set<MimeType> findConsumesMimeTypes(HandlerMethod handlerMethod); | ||
} |
10 changes: 10 additions & 0 deletions
10
...openapigeneratorforspring/common/operation/mimetype/ConsumesMimeTypeProviderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.qaware.openapigeneratorforspring.common.operation.mimetype; | ||
|
||
import de.qaware.openapigeneratorforspring.common.paths.HandlerMethod; | ||
import org.springframework.util.MimeType; | ||
|
||
import java.util.Set; | ||
|
||
public interface ConsumesMimeTypeProviderStrategy { | ||
Set<MimeType> getConsumesMimeTypes(HandlerMethod handlerMethod); | ||
} |
11 changes: 11 additions & 0 deletions
11
.../qaware/openapigeneratorforspring/common/operation/mimetype/ProducesMimeTypeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.qaware.openapigeneratorforspring.common.operation.mimetype; | ||
|
||
import de.qaware.openapigeneratorforspring.common.paths.HandlerMethod; | ||
import de.qaware.openapigeneratorforspring.common.util.OpenApiOrderedUtils; | ||
import org.springframework.util.MimeType; | ||
|
||
import java.util.Set; | ||
|
||
public interface ProducesMimeTypeProvider extends OpenApiOrderedUtils.DefaultOrdered { | ||
Set<MimeType> findProducesMimeTypes(HandlerMethod handlerMethod); | ||
} |
10 changes: 10 additions & 0 deletions
10
...openapigeneratorforspring/common/operation/mimetype/ProducesMimeTypeProviderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.qaware.openapigeneratorforspring.common.operation.mimetype; | ||
|
||
import de.qaware.openapigeneratorforspring.common.paths.HandlerMethod; | ||
import org.springframework.util.MimeType; | ||
|
||
import java.util.Set; | ||
|
||
public interface ProducesMimeTypeProviderStrategy { | ||
Set<MimeType> getProducesMimeTypes(HandlerMethod handlerMethod); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...generatorforspring/common/operation/mimetype/DefaultConsumesMimeTypeProviderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package de.qaware.openapigeneratorforspring.common.operation.mimetype; | ||
|
||
import de.qaware.openapigeneratorforspring.common.paths.HandlerMethod; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.util.MimeType; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@RequiredArgsConstructor | ||
public class DefaultConsumesMimeTypeProviderStrategy implements ConsumesMimeTypeProviderStrategy { | ||
|
||
private final List<ConsumesMimeTypeProvider> providers; | ||
|
||
@Override | ||
public Set<MimeType> getConsumesMimeTypes(HandlerMethod handlerMethod) { | ||
return providers.stream() | ||
.map(provider -> provider.findConsumesMimeTypes(handlerMethod)) | ||
.filter(mimeTypes -> !mimeTypes.isEmpty()) | ||
.findFirst() | ||
.orElseGet(Collections::emptySet); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...generatorforspring/common/operation/mimetype/DefaultProducesMimeTypeProviderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.qaware.openapigeneratorforspring.common.operation.mimetype; | ||
|
||
import de.qaware.openapigeneratorforspring.common.paths.HandlerMethod; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.util.MimeType; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
public class DefaultProducesMimeTypeProviderStrategy implements ProducesMimeTypeProviderStrategy { | ||
|
||
private final List<ProducesMimeTypeProvider> providers; | ||
|
||
@Override | ||
public Set<MimeType> getProducesMimeTypes(HandlerMethod handlerMethod) { | ||
return providers.stream() | ||
.map(provider -> provider.findProducesMimeTypes(handlerMethod)) | ||
// Produces mime types end up as response body keys in model and must be concrete (aka no wildcards!) | ||
.map(mimeTypes -> mimeTypes.stream().filter(MimeType::isConcrete).collect(Collectors.toSet())) | ||
.filter(mimeTypes -> !mimeTypes.isEmpty()) | ||
.findFirst() | ||
.orElseGet(Collections::emptySet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...r-for-spring-test/src/test/java/de/qaware/openapigeneratorforspring/test/app55/App55.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.qaware.openapigeneratorforspring.test.app55; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
class App55 { | ||
public static void main(String[] args) { | ||
SpringApplication.run(App55.class, args); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ng-test/src/test/java/de/qaware/openapigeneratorforspring/test/app55/App55Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package de.qaware.openapigeneratorforspring.test.app55; | ||
|
||
import lombok.Value; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class App55Controller { | ||
|
||
@GetMapping | ||
public SomeDto getJson() { | ||
return new SomeDto("some-value"); | ||
} | ||
|
||
@Value | ||
private static class SomeDto { | ||
String someProperty; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...r-spring-test/src/test/java/de/qaware/openapigeneratorforspring/test/app55/App55Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.qaware.openapigeneratorforspring.test.app55; | ||
|
||
import de.qaware.openapigeneratorforspring.test.AbstractOpenApiGeneratorWebMvcIntTest; | ||
|
||
class App55Test extends AbstractOpenApiGeneratorWebMvcIntTest { | ||
|
||
} |
Oops, something went wrong.