OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.29k stars 6.44k forks source link

[BUG] Generation of test cases are failing for spring. #3318

Open jskhedkarl opened 5 years ago

jskhedkarl commented 5 years ago

OpenAPI generator is not generating Integration test cases for spring API's Using the following generator to generate spring based code from openAPI specification. 4.0.2</openapi-generator-maven-plugin.version> swagger spec https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml

However, older swagger-codegen is able to generate integration test cases for API's.

1#Code generation using openapi-generator 4.0.2 rm -rf Tester/* && openapi-generator generate -i petstore.yaml -g spring --library spring-mvc -o Tester/ skhedkar@Thanos:~/sandbox/trunk/jhipster$ tree Tester/ Tester/ ├── pom.xml ├── README.md └── src └── main ├── java │   └── org │   └── openapitools │   ├── api │   │   ├── ApiUtil.java │   │   ├── PetsApiController.java │   │   └── PetsApi.java │   ├── configuration │   │   ├── HomeController.java │   │   ├── OpenAPIDocumentationConfig.java │   │   ├── OpenAPIUiConfiguration.java │   │   ├── RFC3339DateFormat.java │   │   ├── WebApplication.java │   │   └── WebMvcConfiguration.java │   └── model │   ├── Error.java │   └── Pet.java └── resources └── application.properties

9 directories, 14 files

2#Code generation using swagger-codegen-cli 3.0.9 rm -rf Tester/* && java -jar swagger-codegen-cli-3.0.9-20190627.154813-43.jar generate -i petstore.yaml -l spring --library spring-mvc -o Tester/

skhedkar@Thanos:~/sandbox/trunk/swagger$ tree Tester/ Tester/ ├── pom.xml ├── README.md └── src ├── main │   ├── java │   │   └── io │   │   └── swagger │   │   ├── api │   │   │   ├── ApiException.java │   │   │   ├── ApiOriginFilter.java │   │   │   ├── ApiResponseMessage.java │   │   │   ├── NotFoundException.java │   │   │   ├── PetsApiController.java │   │   │   └── PetsApi.java │   │   ├── configuration │   │   │   ├── CustomInstantDeserializer.java │   │   │   ├── RFC3339DateFormat.java │   │   │   ├── SwaggerDocumentationConfig.java │   │   │   ├── SwaggerUiConfiguration.java │   │   │   ├── WebApplication.java │   │   │   └── WebMvcConfiguration.java │   │   └── model │   │   ├── Error.java │   │   ├── Pet.java │   │   └── Pets.java │   └── resources │   └── swagger.properties └── test └── java └── io └── swagger └── api └── PetsApiControllerIT.java

Major difference between openapi-generator and swagger-codegen-cli is that template file api_test.mustache is missing in former.

https://github.com/OpenAPITools/openapi-generator/tree/v4.0.2/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc

https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/JavaSpring/libraries/spring-mvc

I don't know if it is a bug or test case generation is not supported for spring in openapi-generator.

auto-labeler[bot] commented 5 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

vanipareek commented 5 years ago

Same issue I m facing, Please resolve this on priority

Zomzog commented 5 years ago

I don't know why they have been removed, but I think more useful test must be generated because previous only assert that we have NOT_IMPLEMENTED default implementation generated and nothing linked to the real API spec.

I've done a quick test and I think it may be possible to generate at least one test per responses of each operation of an API and disable them.

jskhedkarl commented 5 years ago

Thanks for the quick help Thibault,

I tried generating test cases for –g spring –library spring-mvc , but still no luck.

Test templates are missing and I don’t know a way to generate test cases.

If you know a hook or workaround to generate spring based test cases using latest stable version then please let me know. Otherwise I will end up using swagger-codegen-cli which does this job without fail.

Regards,

Suraj Khedkar

From: Thibault Duperron notifications@github.com Sent: 19 July 2019 02:34 To: OpenAPITools/openapi-generator openapi-generator@noreply.github.com Cc: jskhedkarl suraj.khedkar@calsoftinc.com; Author author@noreply.github.com Subject: Re: [OpenAPITools/openapi-generator] [BUG] Generation of test cases are failing for spring. (#3318)

I don't know why they have been removed, but I think more useful test must be generated because previous only assert that we have NOT_IMPLEMENTED default implementation generated and nothing linked to the real API spec.

I've done a quick test and I think it may be possible to generate at least one test per responses of each operation of an API and disable them.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OpenAPITools/openapi-generator/issues/3318?email_source=notifications&email_token=AIMVDCGSSXGAVSAGPEF5OCDQADLFTA5CNFSM4H7E4BJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2JY6PA#issuecomment-512986940 , or mute the thread https://github.com/notifications/unsubscribe-auth/AIMVDCH5MR5IGCPW4GDN77TQADLFTANCNFSM4H7E4BJA .

wolginm commented 9 months ago

Is this bug on any roadmap for development? I am a heavy user of the Openapi-Generator and its a feature that is very much needed by my team.

dbelyaev commented 9 months ago

This has been reported in 2019 and now it is a 2023 and still no fix. Please, put it on the development map as this is a useful feature.

kmatthews812 commented 9 months ago

+1

nitaicharan commented 2 months ago

+1