OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Spring] -Dmodels="" causes different API generated output
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I would like to generate spring server only API (with out model). And I have found out that generated V1Api.java interface have different content depending of presens system property -Dmodels=""
openapi-generator version
3.3.4
OpenAPI declaration file content
openapi: 3.0.1
info:
title: asd
version: "1.2"
paths:
/v1/cancellation-authorisations:
get:
summary: aaa
description: bbb
operationId: methodGet
responses:
'200':
description: OK
content:
application/json:
schema:
description: descr resource.
type: array
items:
$ref: "#/components/schemas/cancellationId"
components:
schemas:
cancellationId:
description: Identification for cancellation resource
type: string
Command line used for generation
java -jar openapi-generator-cli.jar generate -g spring -Dapis="",supportingFiles="ApiUtil.java" --additional-properties sourceFolder=,interfaceOnly=true -i /path/to/my/yaml -v -o output_path
or
java -jar openapi-generator-cli.jar generate -g spring -Dapis="",supportingFiles="ApiUtil.java",models="" --additional-properties sourceFolder=,interfaceOnly=true -i /path/to/my/yaml -v -o output_path
Steps to reproduce
run 2 commands and compare method "methodGet" signature in V1Api.java
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Validated
@Api(value = "v1", description = "the v1 API")
public interface V1Api {
default Optional<NativeWebRequest> getRequest() {
return Optional.empty();
}
@ApiOperation(value = "aaa", nickname = "methodGet", notes = "bbb", response = String.class, responseContainer = "List", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = String.class, responseContainer = "List") })
@RequestMapping(value = "/v1/cancellation-authorisations",
produces = { "application/json" },
method = RequestMethod.GET)
default ResponseEntity<List<String>> methodGet() {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
ApiUtil.setExampleResponse(request, "application/json", "null");
break;
}
}
});
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
}
and
package lv.citadele.psd2.api;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Validated
@Api(value = "v1", description = "the v1 API")
public interface V1Api {
default Optional<NativeWebRequest> getRequest() {
return Optional.empty();
}
@ApiOperation(value = "aaa", nickname = "methodGet", notes = "bbb", response = String.class, responseContainer = "List", tags={ })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = String.class, responseContainer = "List") })
@RequestMapping(value = "/v1/cancellation-authorisations",
produces = { "application/json" },
method = RequestMethod.GET)
default ResponseEntity<List<CancellationId>> methodGet() {
getRequest().ifPresent(request -> {
for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
ApiUtil.setExampleResponse(request, "application/json", "null");
break;
}
}
});
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
}
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 by running the two documented openapi-generator 3.3.4 commands against the supplied YAML and compare the generated V1Api.java methodGet signatures. Trace the Spring generator's handling of the models property, then verify that both invocations produce a consistent intended signature.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100