holyturt / SwiftOverpassWrapper

A wrapper of the Overpass API for Swift.
MIT License
16 stars 2 forks source link

Possibility of making invalid relationships #9

Closed holyturt closed 6 years ago

holyturt commented 6 years ago

When user makes relation between queries, it may be like:

let nodeQuery = SwiftOverpass.query(type: .node)
let wayQuery = nodeQuery.related(.way)

It will work correctly, but the method related(_:) may cause an error inside the API server if user codes like:

let nodeQuery = SwiftOverpass.query(type: .node)
let backwardsQuery = nodeQuery.related(.backwards) // invalid relationship(node-backwords)

As above, user can make wrong relationships(e.g. node-backwards, node-node etc.) easily. First, I made it can throw an error when it's going wrong way. But it seems better to be restructured.

I think the cause is sharing related(_:) in the all query classes which implement OverpassQuery. Therefore, I split up the method into dedicated methods(e.g. node(:_), way(:_), backwards(:_) etc.) and set them into proper classes. The details are in the PR #8.

This will be breaking changes for making query instances.

// before
let node = SwiftOverpass.query(type: .node)
let way = node.related(.way)

// after
let node = NodeQuery()
let way = node.way()

Therefore, I'd like to have opinions/thoughts.

wtimme commented 6 years ago

Thanks for the suggestion! This was implemented with #8.