swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.37k stars 2.17k forks source link

BUG Spec generator should ignore org.glassfish.jersey.media.multipart.MultiPart #4661

Open AlexanderSchuetz97 opened 5 months ago

AlexanderSchuetz97 commented 5 months ago

I have a jaxrs endpoint which has to accept a complicated multipart message using Jersey. This is the endpoint:

    @POST
    @Consumes("multipart/mixed")
    @Produces("application/json")
    @Path("tool/{id}/pipelineparams")
    @Operation(summary = "Does something",
            requestBody = @RequestBody(content = @Content(schema = @Schema(type = "string", format = "binary"))),
            responses = {
            @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SomeModelClass.class))),
            @ApiResponse(responseCode = "422", description = "Can happen"),
            @ApiResponse(responseCode = "404", description = "Can happen"),
            @ApiResponse(responseCode = "409", description = "Can happen"),
    })
    public Response doSomething(@PathParam("id") String id,  MultiPart multiPart) throws IOException {

The swagger generator plugin will correctly understand that it should treat this endpoint as a "binary" endpoint. (The other side will have to manually craft the message which I handwrite in the client anyways)

MultiPart is org.glassfish.jersey.media.multipart.MultiPart

For some reason the generator decides to include Model Spec of org.glassfish.jersey.media.multipart.MultiPart. Due to me overriding the requestBody the Model of MultiPart is not used anywhere but it is still included in the spec. This is not desired as it generates a few very confusing Model Classes in any client generating a client from the spec.

This is one such model that should really not be generated:

      "MultiPart" : {
        "type" : "object",
        "properties" : {
          "bodyParts" : {
            "type" : "array",
            "items" : {
              "$ref" : "#/components/schemas/BodyPart"
            }
          },
          "contentDisposition" : {
            "$ref" : "#/components/schemas/ContentDisposition"
          },
          "entity" : {
            "type" : "object"
          },
          "headers" : {
            "type" : "object",
            "additionalProperties" : {
              "type" : "array",
              "items" : {
                "type" : "string"
              }
            },
            "properties" : {
              "empty" : {
                "type" : "boolean"
              }
            }
          },
          "mediaType" : {
            "$ref" : "#/components/schemas/MediaType"
          },
          "messageBodyWorkers" : {
            "$ref" : "#/components/schemas/MessageBodyWorkers"
          },
          "parameterizedHeaders" : {
            "type" : "object",
            "additionalProperties" : {
              "type" : "array",
              "items" : {
                "$ref" : "#/components/schemas/ParameterizedHeader"
              }
            },
            "properties" : {
              "empty" : {
                "type" : "boolean"
              }
            }
          },
          "parent" : {
            "$ref" : "#/components/schemas/MultiPart"
          },
          "providers" : {
            "$ref" : "#/components/schemas/Providers"
          }
        }
      },

The genrate should completly ignore any "models" in the org.glassfish.jersey.media.multipart and treat them as If they were "InputStream".