Document Hashmap with @Schema
See original GitHub issuehi,
how would one describe an api response, that returns Map<String, List<ComplexObject>> using the v2 annotations? Or Map<String, ComplexObject>?
According to OA3 schema it is possible to model like this, using additionalProperties:
openapi: "3.0.0"
info:
title: Swagger Petstore
servers:
- url: http://petstore.swagger.io/v1
paths:
/petGroups:
get:
operationId: listPetGroups
tags:
- pets
responses:
'200':
description: Pets grouped by Ownername
content:
application/json:
schema:
$ref: "#/components/schemas/MapResponse"
components:
schemas:
MapResponse: # <---- dictionary<String,Array<Pet>>
type: object
additionalProperties:
$ref: '#/components/schemas/Pets'
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
But I do not see a way, how to describe this structure on the server side using java annotations, as @Schema does not have additionalProperties.
(end goal is to generate schema from server code, or at least to validate, that the server code matches the schema above) Thanks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Java-to-Schema Examples (The Java EE 5 Tutorial)
The XmlAdapter Field example shows how to use an XmlAdapter for mapping XML content into and out of a (custom) HashMap. The HashMap...
Read more >HashMap in Java GraphQL schema - Stack Overflow
1 Answer 1 ... The simplest way is using a DTO. Using a DTO mapper like mapstruct for example, will allow you to...
Read more >Dictionaries, Hashmaps, Associative Arrays - Swagger
A dictionary (also known as a map, hashmap or associative array) is a set of ... Instead of using an inline schema, additionalProperties...
Read more >Java HashMap - W3Schools
In the ArrayList chapter, you learned that Arrays store items as an ordered collection, and you have to access them with an index...
Read more >2.3.7 The HashMap Class - MySQL :: Developer Zone
The method gets the hash map's schema object version. Signature: virtual int getObjectVersion ( void ) const
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Something like this would be great:
And so would produce the following in swagger ui:
Hi! @frantuma How’s the progress with this one?