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

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

Closed
Shiva-kss opened this issue Nov 23, 2022 · 0 comments
Labels

Comments

@Shiva-kss
Copy link

Shiva-kss commented Nov 23, 2022

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


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

No branches or pull requests

2 participants