Skip to content
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

[Java] OpenAPI-Spec v3: requestBody schema not used correctly #394

Open
janssen92 opened this issue Jun 25, 2018 · 1 comment
Open

[Java] OpenAPI-Spec v3: requestBody schema not used correctly #394

janssen92 opened this issue Jun 25, 2018 · 1 comment

Comments

@janssen92
Copy link
Contributor

janssen92 commented Jun 25, 2018

Description

When using a requestBody with a type X and a response with type Y in the generated source type Y is used as method parameter as well as method return type.

E.g.:
This method signature is generated:

default ResponseEntity<GetProofingConfigDto> patchProofingConfig(
    @ApiParam(value = "ID of model to return",required=true) @PathVariable("id") String id,
    @ApiParam(value = "Authorization: adminToken for the specific config" ,required=true)
    @RequestHeader(value="Authorization", required=true) String authorization,
    @ApiParam(value = "ProofingFeedback Object" ,required=true )  
    @Valid @RequestBody GetProofingConfigDto UNKNOWN_BASE_TYPE) {

from this specification:

 "patch" : {
        "tags" : [ "proofingConfig" ],
        "summary" : "Patch a ProofingConfig",
        "operationId" : "patchProofingConfig",
        "parameters" : [ {
          "name" : "id",
          ....
          }
        }, {
          "name" : "Authorization",
         ....
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "successful operation",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/GetProofingConfigDto"
                }
              }
            }
          }
        },
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/PatchProofingConfigDto"
              }
            }
          }
        }
openapi-generator version

3.0.2 (an Master on June 25)

OpenAPI declaration file content or url

https://github.com/janssen92/swagger-feedback-service-api/blob/testOpenApiGenerator/swagger-feedback.json
https://github.com/janssen92/swagger-feedback-service-api/blob/testOpenApiGenerator/swagger-feedback-conf.json

Command line used for generation

java -jar ~/git/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i swagger-feedback.json -g spring -o ~/testOpenApiGen --library spring-boot --config swagger-feedback-conf.json
But also same result with less parameters:
java -jar ~/git/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i swagger-feedback.json -g spring -o ~/testOpenApiGen

Steps to reproduce
  • Checkout file(s)
  • Generate Code
@jmini
Copy link
Member

jmini commented Jun 25, 2018

I had a look at your specification, your request body PatchProofingConfigDto is defined like this:

"components" : {
  "schemas" : {
      "PatchProofingConfigDto" : {
        "allOf" : [ {
          "$ref" : "#/components/schemas/GetProofingConfigDto"
        } ]
      },
      ...
  }
}

I think this is a duplicate of #192 solved in 3.0.3-SNAPSHOT by #358.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants