OpenAPITools / OpenAPITools/openapi-generator
[BUG] Generation of test cases are failing for spring.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
OpenAPI generator is not generating Integration test cases for spring API's
Using the following generator to generate spring based code from openAPI specification.
<openapi-generator-maven-plugin.version>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.
I don't know if it is a bug or test case generation is not supported for spring in openapi-generator.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the JavaSpring spring-mvc templates under modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc and compare them with the linked swagger-codegen templates, especially api_test.mustache. Reproduce generation with petstore.yaml and openapi-generator 4.0.2, then verify that the generated project includes the expected integration test under src/test and that it can run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100