Skip to content

Bug where route path component contains both parameter and constant #23

Description

@ehyche

I am implementing a Swift Package Registry Service using swift-openapi-vapor. This service contains (among others) these two endpoints:

The OpenAPI spec for this service can be found here.

The bug is: the VaporTransport cannot distinguish between these two routes. When I hit the my server with the following URL:

http://127.0.0.1:8080/pointfreeco/swift-clocks/1.0.6.zip

then this gets parsed as a fetchReleaseMetadata route rather than a downloadSourceArchive route.

I believe the bug is here in VaporTransport.swift:

extension [Vapor.PathComponent] {
    init(_ path: String) {
        self = path.split(
            separator: "/",
            omittingEmptySubsequences: true
        ).map { parameter in
            if parameter.first == "{", parameter.last == "}" {
                return .parameter(String(parameter.dropFirst().dropLast()))
            } else {
                return .constant(String(parameter))
            }
        }
    }
}

Currently the OpenAPI path /{scope}/{name}/{version}.zip is getting parsed as:

[
    .parameter("scope"),
    .parameter("name"),
    .constant("{version}.zip")
]

I would assume that the OpenAPI path /{scope}/{name}/{version}.zip should get parsed as:

    .parameter("scope"),
    .parameter("name"),
    .parameter("version"),
    .constant(".zip"),

Is this a correct assumption?

If so, then I will put up a PR which accomplishes this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions