OpenAPITools / OpenAPITools/openapi-generator

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

Open
#3,318 8 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Spring
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.

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.