-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[Spring] Add apiFirst option #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
47f9683
[Spring] Add apiFirst option
cbornet 6a5c7d8
Git diff to see what's wrong
cbornet 1d804f4
Git diff to see what's wrong
cbornet 2eed9e1
Merge remote-tracking branch 'origin/master' into pull_184
jmini 7882c18
Update bin/ensure-up-to-date
jmini 5041987
Run bin/ensure-up-to-date
jmini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
88 changes: 88 additions & 0 deletions
88
modules/openapi-generator/src/main/resources/JavaSpring/homeController.mustache
This file contains hidden or 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,88 @@ | ||
package {{configPackage}}; | ||
|
||
{{^useSpringfox}} | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.core.io.Resource; | ||
{{/useSpringfox}} | ||
import org.springframework.stereotype.Controller; | ||
{{^useSpringfox}} | ||
import org.springframework.util.StreamUtils; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
{{/useSpringfox}} | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
{{^useSpringfox}} | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
{{/useSpringfox}} | ||
{{#reactive}} | ||
import org.springframework.web.reactive.function.server.RouterFunction; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
{{/reactive}} | ||
|
||
{{^useSpringfox}} | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
{{/useSpringfox}} | ||
{{#reactive}} | ||
import java.net.URI; | ||
{{/reactive}} | ||
{{^useSpringfox}} | ||
import java.nio.charset.Charset; | ||
{{/useSpringfox}} | ||
{{#reactive}} | ||
|
||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET; | ||
import static org.springframework.web.reactive.function.server.RouterFunctions.route; | ||
{{/reactive}} | ||
|
||
/** | ||
* Home redirection to OpenAPI api documentation | ||
*/ | ||
@Controller | ||
public class HomeController { | ||
|
||
{{^useSpringfox}} | ||
private static YAMLMapper yamlMapper = new YAMLMapper(); | ||
|
||
@Value("classpath:/openapi.yaml") | ||
private Resource openapi; | ||
|
||
@Bean | ||
public String openapiContent() throws IOException { | ||
try(InputStream is = openapi.getInputStream()) { | ||
return StreamUtils.copyToString(is, Charset.defaultCharset()); | ||
} | ||
} | ||
|
||
@GetMapping(value = "/openapi.yaml", produces = "application/vnd.oai.openapi") | ||
@ResponseBody | ||
public String openapiYaml() throws IOException { | ||
return openapiContent(); | ||
} | ||
|
||
@GetMapping(value = "/openapi.json", produces = "application/json") | ||
@ResponseBody | ||
public Object openapiJson() throws IOException { | ||
return yamlMapper.readValue(openapiContent(), Object.class); | ||
} | ||
|
||
{{/useSpringfox}} | ||
{{#reactive}} | ||
@Bean | ||
RouterFunction<ServerResponse> index() { | ||
return route( | ||
GET("/"), | ||
req -> ServerResponse.temporaryRedirect(URI.create("{{#useSpringfox}}swagger-ui.html{{/useSpringfox}}{{^useSpringfox}}swagger-ui/index.html?url=../openapi.json{{/useSpringfox}}")).build() | ||
); | ||
} | ||
{{/reactive}} | ||
{{^reactive}} | ||
@RequestMapping("/") | ||
public String index() { | ||
return "redirect:{{#useSpringfox}}swagger-ui.html{{/useSpringfox}}{{^useSpringfox}}swagger-ui/index.html?url=../openapi.json{{/useSpringfox}}"; | ||
} | ||
{{/reactive}} | ||
|
||
|
||
} |
File renamed without changes.
This file contains hidden or 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
2 changes: 2 additions & 0 deletions
2
...resources/JavaSpring/application.mustache → ...ibraries/spring-boot/application.mustache
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{{#useSpringfox}} | ||
springfox.documentation.swagger.v2.path=/api-docs | ||
{{/useSpringfox}} | ||
server.port={{serverPort}} | ||
spring.jackson.date-format={{basePackage}}.RFC3339DateFormat | ||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have let this 3 lines (
echo
,git diff
andgit status
) inside the if... We do not need them in the OK case.