Skip to content

Incorrect RequestBody type on schema/ui if class implements Map #1428

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

Closed
infoShare opened this issue Jan 7, 2022 · 1 comment
Closed

Incorrect RequestBody type on schema/ui if class implements Map #1428

infoShare opened this issue Jan 7, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@infoShare
Copy link

infoShare commented Jan 7, 2022

Describe the bug

  • When using complex on Spring REST API - type is incorrectly defined on the API schema (type = object instead of $ref) if it implements Map interface

To Reproduce
Steps to reproduce the behavior:

  • Try to use complex model object as RequestBody with @Schema definitions.
  • On the API schema we have:
    "requestBody":{"content":{"application/json":{"schema":{"type":"object","additionalProperties":{"type":"object","description":"Body","example":{"key":"value"}},"description":"Body","example":{"key":"value"}}}},"required":true}
    instead of
    "requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Body"}}},"required":true}

Expected behavior

  • Type should be properly marked on schema/ui with $ref instead of type=object
  • Schema model should be available on "Models" section on UI
  • No need for additional schema definition on RequestBody annotation

Repository with example
https://github.com/infoShare/swagger-requestbody-schema

image

P.S.
It there any option to hide interface methods on the API without custom code (check MapExclusion interface and usage on example repository which is used to hide isEmpty() method from the API schema)

@infoShare infoShare changed the title Inforrect RequestBody type on schema/ui Inforrect RequestBody type on schema/ui if implements Map interface Jan 7, 2022
@infoShare infoShare changed the title Inforrect RequestBody type on schema/ui if implements Map interface Incorrect RequestBody type on schema/ui if class implements Map Jan 7, 2022
@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 9, 2022
@infoShare
Copy link
Author

Thanks @bnasslahsen !

mpleine pushed a commit to mpleine/springdoc-openapi that referenced this issue May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants