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

Optionally generate methods for obtaining map keys and list indexes #4

Open
andylowry opened this issue Mar 22, 2018 · 0 comments
Open

Comments

@andylowry
Copy link
Contributor

andylowry commented Mar 22, 2018

In the type configuration used by the generator, a 'map' type is implemented as a map of strings to values, and a collection type is implemented as a collection of values. The overlay adapter method getPathInParent can be used to obtain the map key or list position (though as a string, e.g. "10" not 10). But this is clumsy to code.

We should add a type configuration property like selectorName that, when present, will cause a convenience method to be defined for the object. For example, if we have selectorName: name on a map type, then the generated API for that type will include a method getName() that returns a string. Likewise, selectorName: position on a collection type will give rise to int getPosition().

These methods should return null if the instance does not happen to appear as a MapOverlay or ListOverlay child, and references to the instance, naturally, will reflect its non-reference occurrence (since there will only really be a single instance of the type, and its parent, if any, will be set according to where it was inlined). So e.g. in an OpenAPIv3 document, a Schema object may appear in the /components/schemas map but may also be referenced from various places in the overall model. Its name will be the name appearing in the /components/schemas map.

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

No branches or pull requests

1 participant