question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document Hashmap with @Schema

See original GitHub issue

hi,

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:open
  • Created 5 years ago
  • Reactions:12
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

22reactions
ndtrevivcommented, Sep 3, 2020

Something like this would be great:

content = @Content(map = @MapSchema(key = @Schema(implementation = String.class), value = @Schema(implementation = XXX.class)))

And so would produce the following in swagger ui:

{
  "key": XXX > { ... }
}
7reactions
mchmielarzcommented, Nov 3, 2021

Hi! @frantuma How’s the progress with this one?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found