From a1236f005cea3ac106383b0a77d9496cc47b3abc Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 9 Sep 2023 22:56:54 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20explicit=20read=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes the explicit `read` (get) route in favor of relying on the implicit `@path` parameter. This removes some boilerplate, moves the `read` operation “next to” the `list` operation, and looks similar to the templated approach (minus doc comments). --- src/people.tsp | 17 +++++------- src/planets.tsp | 17 +++++------- src/species.tsp | 67 +++++++++++++++++++++++------------------------ src/starships.tsp | 17 +++++------- src/vehicles.tsp | 17 +++++------- 5 files changed, 61 insertions(+), 74 deletions(-) diff --git a/src/people.tsp b/src/people.tsp index 6a9ef32..4a20981 100644 --- a/src/people.tsp +++ b/src/people.tsp @@ -12,16 +12,13 @@ namespace people { @OpenAPI.operationId("ListPerson") op list(@query search: string): Person[]; - @route("/{personId}") - namespace person { - /** - * Get a specific people resource. - * - * @param personId Numeric ID of the person to get. - */ - @OpenAPI.operationId("GetPerson") - op read(@path personId: int32): Person; - } + /** + * Get a specific people resource. + * + * @param personId Numeric ID of the person to get. + */ + @OpenAPI.operationId("GetPerson") + op read(@path personId: int32): Person; } /** A People resource is an individual person or character within the Star Wars universe. */ diff --git a/src/planets.tsp b/src/planets.tsp index 9a8d8e6..b5cacca 100644 --- a/src/planets.tsp +++ b/src/planets.tsp @@ -12,16 +12,13 @@ namespace planets { @OpenAPI.operationId("ListPlanet") op list(@query search: string): Planet[]; - @route("/{planetId}") - namespace planet { - /** - * Get a specific planet resource. - * - * @param planetId Numeric ID of the planet to get. - */ - @OpenAPI.operationId("GetPlanet") - op read(@path planetId: int32): Planet; - } + /** + * Get a specific planet resource. + * + * @param planetId Numeric ID of the planet to get. + */ + @OpenAPI.operationId("GetPlanet") + op read(@path planetId: int32): Planet; } /** A Planet resource is a large mass, planet or planetoid in the Star Wars Universe, at the time of 0 ABY. */ diff --git a/src/species.tsp b/src/species.tsp index 6870c44..02475d0 100644 --- a/src/species.tsp +++ b/src/species.tsp @@ -12,7 +12,6 @@ namespace species { @OpenAPI.operationId("ListSpecies") op list(@query search: string): Species[]; - @route("/{speciesId}") namespace species { /** * Get a specific species resource. @@ -22,52 +21,52 @@ namespace species { @OpenAPI.operationId("GetSpecies") op read(@path speciesId: int32): Species; } -} -/** A Species resource is a type of person or character within the Star Wars Universe. */ -model Species { - /** The name of this species. */ - name: string; + /** A Species resource is a type of person or character within the Star Wars Universe. */ + model Species { + /** The name of this species. */ + name: string; - /** The classification of this species, such as "mammal" or "reptile". */ - classification: string; + /** The classification of this species, such as "mammal" or "reptile". */ + classification: string; - /** The designation of this species, such as "sentient". */ - designation: string; + /** The designation of this species, such as "sentient". */ + designation: string; - /** The average height of this species in centimeters. */ - average_height: string; + /** The average height of this species in centimeters. */ + average_height: string; - /** The average lifespan of this species in years. */ - average_lifespan: string; + /** The average lifespan of this species in years. */ + average_lifespan: string; - /** A comma-separated string of common eye colors for this species, "none" if this species does not typically have eyes. */ - eye_colors: string; + /** A comma-separated string of common eye colors for this species, "none" if this species does not typically have eyes. */ + eye_colors: string; - /** A comma-separated string of common hair colors for this species, "none" if this species does not typically have hair. */ - hair_colors: string; + /** A comma-separated string of common hair colors for this species, "none" if this species does not typically have hair. */ + hair_colors: string; - /** A comma-separated string of common skin colors for this species, "none" if this species does not typically have skin. */ - skin_colors: string; + /** A comma-separated string of common skin colors for this species, "none" if this species does not typically have skin. */ + skin_colors: string; - /** The language commonly spoken by this species. */ - language: string; + /** The language commonly spoken by this species. */ + language: string; - /** The URL of a planet resource, a planet that this species originates from. */ - homeworld: url; + /** The URL of a planet resource, a planet that this species originates from. */ + homeworld: url; - /** An array of People URL Resources that are a part of this species. */ - people: url[]; + /** An array of People URL Resources that are a part of this species. */ + people: url[]; - /** An array of Film URL Resources that this species has appeared in. */ - films: url[]; + /** An array of Film URL Resources that this species has appeared in. */ + films: url[]; - /** The hypermedia URL of this resource. */ - url: url; + /** The hypermedia URL of this resource. */ + url: url; - /** The ISO 8601 date format of the time that this resource was created. */ - created: utcDateTime; + /** The ISO 8601 date format of the time that this resource was created. */ + created: utcDateTime; - /** The ISO 8601 date format of the time that this resource was edited. */ - edited: utcDateTime; + /** The ISO 8601 date format of the time that this resource was edited. */ + edited: utcDateTime; + } } diff --git a/src/starships.tsp b/src/starships.tsp index fe895be..37997c7 100644 --- a/src/starships.tsp +++ b/src/starships.tsp @@ -12,16 +12,13 @@ namespace starships { @OpenAPI.operationId("ListStarships") op list(@query search: string): Starship[]; - @route("/{starshipId}") - namespace starship { - /** - * Get a specific starship resource. - * - * @param starshipId Numeric ID of the starship to get. - */ - @OpenAPI.operationId("GetStarship") - op read(@path starshipId: int32): Starship; - } + /** + * Get a specific starship resource. + * + * @param starshipId Numeric ID of the starship to get. + */ + @OpenAPI.operationId("GetStarship") + op read(@path starshipId: int32): Starship; } /** A Starship resource is a single transport craft that has hyperdrive capability. */ diff --git a/src/vehicles.tsp b/src/vehicles.tsp index 3007d97..4c9b364 100644 --- a/src/vehicles.tsp +++ b/src/vehicles.tsp @@ -12,16 +12,13 @@ namespace vehicles { @OpenAPI.operationId("ListVehicles") op list(@query search: string): Vehicle[]; - @route("/{vehicleId}") - namespace vehicle { - /** - * Get a specific vehicle resource. - * - * @param vehicleId Numeric ID of the vehicle to get. - */ - @OpenAPI.operationId("GetVehicle") - op read(@path vehicleId: int32): Vehicle; - } + /** + * Get a specific vehicle resource. + * + * @param vehicleId Numeric ID of the vehicle to get. + */ + @OpenAPI.operationId("GetVehicle") + op read(@path vehicleId: int32): Vehicle; } /** A Vehicle resource is a single transport craft that **does not have** hyperdrive capability. */