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.

Models: do we need the interfaces extending Map?

See original GitHub issue

There are several model interfaces: Paths, ServerVariables, Content, APIResponses, Scopes, Callback, that extends, Map<String, T>

My points are:

1/ Those Interfaces are really strange, when working with it, you never can not use stuff like:

  • Arrays.asList(..)
  • Streams + Collectors

2/ To implement #240 we might need to remove those interface. How do you create an immutable version of Paths

3/ The KaiZen-Parser models do not use such a construct.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
jminicommented, Oct 13, 2018

PR for 1.1: #283 PR for 2.0: #287

1reaction
jminicommented, Sep 24, 2018

In my opinion we do not need to have both:

Paths addPathItems(Map<String, PathItem> items);
void setPathItems(Map<String, PathItem> items);

This will be confusing.


The builder pattern make sense for the single add item, using this method: addPathItems(String, PathItem)

See this example (from the TCK):

.paths(OASFactory.createObject(Paths.class)
    .addPathItem("/modelReader/airlines", OASFactory.createObject(PathItem.class)
        .GET(OASFactory.createObject(Operation.class)
            .summary("Retrieve all available airlines")
            .operationId("getAirlines")
            .responses(OASFactory.createObject(APIResponses.class)
                .addAPIResponse("404", OASFactory.createObject(APIResponse.class)
                    .description("No airlines found")
                    .content(OASFactory.createObject(Content.class)
                        .addMediaType("n/a", OASFactory.createObject(MediaType.class)))))))
    .addPathItem("/availabilityModel", OASFactory.createObject(PathItem.class)
        .GET(OASFactory.createObject(Operation.class)
            .tags(new ArrayList<String>())
                .addTag("Availability")
            .summary("TEST SUMMARY")
            .operationId("getTestFlights")
//...

I do not see the benefit of having a builder pattern for the Map. Even with the new builder method for Maps (java.util.Map.of(k1, v1, k2, v2) - Java 10), I think that the single add builder method is more readable.


My recommendation, add a simple setter like this:

void setPathItems(Map<String, PathItem> items);

If we use a setter method, then it is natural to have a void return value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extend table maps that are used as interfaces | Dynamics 365
This article describes how to extend table maps that are used as interfaces.
Read more >
Understanding and using interfaces in TypeScript
Indexable types are helpful when you have to define custom properties and functions that should operate on a range of values of the...
Read more >
Why does Map not extend Collection interface [duplicate]
Collection assume elements of one value. Map assumes entries of key/value pairs. They could have been engineered to re-use the same common ...
Read more >
The Map Interface (The Java™ Tutorials > Collections ...
A Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most...
Read more >
Collection Classes: List, Set, Map
The SortedSet interface extends Set with operations based on some ordering of the elements in a set; when constructing an object from a...
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