Skip to content

Recognize Swagger Api annotation as RestController contract #801

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion typescript-generator-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import cz.habarta.typescript.generator.util.Pair;
import cz.habarta.typescript.generator.util.Utils;
import static cz.habarta.typescript.generator.util.Utils.getInheritanceChain;
import io.swagger.annotations.Api;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
Expand Down Expand Up @@ -123,7 +124,8 @@ public JaxrsApplicationParser.Result tryParse(SourceType<?> sourceType) {

// controller
final Component component = AnnotationUtils.findAnnotation(cls, Component.class);
if (component != null) {
final Api api = AnnotationUtils.findAnnotation(cls, Api.class);
if (component != null || api != null) {
TypeScriptGenerator.getLogger().verbose("Parsing Spring component: " + cls.getName());
final JaxrsApplicationParser.Result result = new JaxrsApplicationParser.Result();
final RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(cls, RequestMapping.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cz.habarta.typescript.generator.TypeScriptFileType;
import cz.habarta.typescript.generator.TypeScriptGenerator;
import cz.habarta.typescript.generator.util.Utils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -488,4 +489,27 @@ public String shouldBeExcluded() {
}
}

@Api(value = "customer")
public interface OpenApiGeneratorCreatedApi {

@RequestMapping(
method = RequestMethod.GET,
value = "/generated/api",
produces = {"application/json"}
)
ResponseEntity<String> getGeneratedApi();
}

@Test
void testOpenApiGeneratorCreatedInterfacesAreIncluded() {
final Settings settings = TestUtils.settings();
settings.outputFileType = TypeScriptFileType.implementationFile;
settings.generateSpringApplicationClient = true;
final String output = new TypeScriptGenerator(settings).generateTypeScript(
Input.from(OpenApiGeneratorCreatedApi.class));
Assertions.assertTrue(output.contains(
"getGeneratedApi(): RestResponse<string> {\n"
+ " return this.httpClient.request({ method: \"GET\", url: uriEncoding`generated/api` });\n"
+ " }"));
}
}