Ask a Question

How to add Properties[] properties in @Schema annotation?

sebawagner
Occasional Visitor

How to add Properties[] properties in @Schema annotation?

Similar to the post here:

https://community.smartbear.com/t5/Swagger-Open-Source-Tools/How-to-add-Properties-properties-in-Sch...

 

I am not sure how to define the schemas for the Properties in my request parameter schema. Or if a schema is even the right tag for it.

 

                        requestBody = @RequestBody(
				content = @Content(
					mediaType = MediaType.MULTIPART_FORM_DATA,
						schema = @Schema(
							type = "object",
							requiredProperties = { "user", "options" },
                                                        // can't define @Properties here
						)
					)
			),

 

 

Its  not possible to define Properties. The proposed workaround around having another class linked, I don't think that is an actual work around? Cause it would imply a single schema ref, not multiple.

 

What I would like is this definition generated:

 

       "requestBody" : {
          "content" : {
            "multipart/form-data" : {
              "schema" : {
                "required" : [ "options", "user" ],
                "type" : "object",
                "properties" : {
                  "user" : {
                    "$ref" : "#/components/schemas/ExternalUserDTO"
                  },
                  "options" : {
                    "$ref" : "#/components/schemas/RoomOptionsDTO"
                  }
                }
              }
            }
          }
        },

 

 

What would the required annotations look like for this?

 

 

 

 

2 REPLIES 2
ponelat
Staff

Re: How to add Properties[] properties in @Schema annotation?

Hi @sebawagner 

 

I have no idea, but will reach out to see if anyone who works on the Java side might.

frantuma
Staff

Re: How to add Properties[] properties in @Schema annotation?

ATM @Schema annotation doesn't allow to specify properties and additionalProperties part of the schema, if not by referring to an existing class via implementation, as you mentioned. We have this enhancement (annotations + processing) in our roadmap, but for the moment you can either apply the implementation workaround by e.g. defining some POJOs like the following:

 

...
class ExternalUserDTO {
 String foo;
}

class RoomOptionsDTO {
 public String bar;
}

@Schema(requiredProperties = {"user", "options"}
class UserAndRoomDTO {
 public RoomOptionsDTO options;
 public ExternalUserDTO user; 
}

...

requestBody = @RequestBody(
				content = @Content(
					mediaType = MediaType.MULTIPART_FORM_DATA,
						schema = @Schema(
							implementation = UserAndRoomDTO.class)

 

 

or use one of the extension mechanism, e.g. filters (https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Extensions#filters

cancel
Showing results for 
Search instead for 
Did you mean: