Skip to content

Commit

Permalink
🔥 Remove explicit read route
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
connorjs committed Sep 10, 2023
1 parent f79d19c commit a1236f0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 74 deletions.
17 changes: 7 additions & 10 deletions src/people.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
17 changes: 7 additions & 10 deletions src/planets.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
67 changes: 33 additions & 34 deletions src/species.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace species {
@OpenAPI.operationId("ListSpecies")
op list(@query search: string): Species[];

@route("/{speciesId}")
namespace species {
/**
* Get a specific species resource.
Expand All @@ -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;
}
}
17 changes: 7 additions & 10 deletions src/starships.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
17 changes: 7 additions & 10 deletions src/vehicles.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit a1236f0

Please sign in to comment.