Skip to content

Annotating class with @Schema(additionalProperties = AdditionalPropertiesValue.FALSE) does not produce JSON/YAML with additionalProperties: false #4316

@Shiva-kss

Description

@Shiva-kss

I have this class with annotation:
@Schema(additionalProperties = AdditionalPropertiesValue.FALSE)
public class AuditSearchCriteria implements Serializable {

When looking at JSON/YAML at my
http://localhost:8080/v3/api-docs/groupName
I expect that output for this component will include "additionalProperties: false"
e.g.

components:
  schemas:
    AuditSearchCriteria:
      type: object
      additionalProperties: false
      properties:

But I see

components:
  schemas:
    AuditSearchCriteria:
      type: object
      properties:

To Reproduce
SpringBoot: 2.6.7
springdoc-openapi-ui, springdoc-openapi-hateoas, springdoc-openapi-data-rest, springdoc-openapi-security: all version 1.6.12
swagger-core : 2.2.4

MyController looks where I use AuditSearchCriteria


@RestController
@RequestMapping("/audit")
@Tag(name = "auditLog", description = "Audit Logging API")
@SecurityRequirements({@SecurityRequirement(name = "basicAuthN")})
public class AuditLogController {
....
	@RequestMapping(value = "/search", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
	@PerformanceMetrics(sla = 500)
	@Operation(summary = "Returns List of Audit Log records based on the matching search critera", description = "Returns list of Audit Log records matching the search critera. SLA:500", responses = {
			@ApiResponse(responseCode = "200", description = "Successful retrieval of list of Audit Log records matching the search criteria", content = {
					@Content(mediaType = "application/json", schema = @Schema(implementation = AuditLogDTO.class)) }),
			@ApiResponse(responseCode = "400", description = "Invalid input provided", content = { @Content(mediaType = "application/json")}), 
	        @ApiResponse(responseCode = "401", description = "Unauthorized", content = { @Content(mediaType = "application/json")}),})			
	public List<AuditLogDTO> searchAuditLog(
			@Parameter(description = "Page number for the search results", example = "1", required = false) @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
			@Parameter(description = "Size of the page", example = "1", required = false) @RequestParam(value = "size", defaultValue = "100", required = false) Integer size,
			@Parameter(description = "Audit Search criteria", example = "1", required = true) @RequestBody	@Valid AuditSearchCriteria auditSearchCriteria,
			BindingResult errors, HttpServletRequest request) throws BindException {

Also to simplify things I just took demo project from here: https://github.com/springdoc/springdoc-openapi-demos
and picked this one: springdoc-openapi-book-service

And all I did is in Book.java file changed to this

@Schema(additionalProperties = AdditionalPropertiesValue.FALSE)
public class Book {

And then run application, got to http://localhost:8080/v3/api-docs and expected this (when converting JSON to YAML)


components:
  schemas:
    Book:
      required:
        - author
        - title
      type: object
      additionalProperties: false
      properties:
        id:
          type: integer
          format: int64
        title:
          maxLength: 20
          minLength: 0
          type: string
        author:
          maxLength: 30
          minLength: 0
          type: string

But instead got the same thing w/o additionalProperties


components:
  schemas:
    Book:
      required:
        - author
        - title
      type: object
      properties:
        id:
          type: integer
          format: int64
        title:
          maxLength: 20
          minLength: 0
          type: string
        author:
          maxLength: 30
          minLength: 0
          type: string


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions