Skip to content

Commit

Permalink
✨ Operation IDs
Browse files Browse the repository at this point in the history
Adds `@typespec/openapi` and defines Operation IDs for all operations.
Example: `GetFilm` instead of the default `film_read`.
  • Loading branch information
connorjs committed Sep 10, 2023
1 parent b297e87 commit dfecd24
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"devDependencies": {
"@typespec/compiler": "~0.47.1",
"@typespec/http": "~0.47.0",
"@typespec/openapi": "^0.47.0",
"@typespec/openapi3": "~0.47.0",
"@typespec/prettier-plugin-typespec": "~0.47.0",
"husky": "^8.0.3",
Expand Down
2 changes: 2 additions & 0 deletions src/films.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace films {
*
* @param search Case-insensitive partial match on the `title` field.
*/
@OpenAPI.operationId("ListFilms")
op list(search: string): Film[];

@route("/{filmId}")
Expand All @@ -18,6 +19,7 @@ namespace films {
*
* @param filmId Numeric ID of the film to get.
*/
@OpenAPI.operationId("GetFilm")
op read(@path filmId: int32): Film;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@typespec/http";
import "@typespec/openapi";

import "./films.tsp";
import "./people.tsp";
Expand Down
2 changes: 2 additions & 0 deletions src/people.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace people {
*
* @param search Case-insensitive partial match on the `name` field.
*/
@OpenAPI.operationId("ListPerson")
op list(search: string): Person[];

@route("/{personId}")
Expand All @@ -18,6 +19,7 @@ namespace people {
*
* @param personId Numeric ID of the person to get.
*/
@OpenAPI.operationId("GetPerson")
op read(@path personId: int32): Person;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/planets.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace planets {
*
* @param search Case-insensitive partial match on the `name` field.
*/
@OpenAPI.operationId("ListPlanet")
op list(search: string): Planet[];

@route("/{planetId}")
Expand All @@ -18,6 +19,7 @@ namespace planets {
*
* @param planetId Numeric ID of the planet to get.
*/
@OpenAPI.operationId("GetPlanet")
op read(@path planetId: int32): Planet;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/root.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ namespace SWAPI;

/** Gets the `Root` resource. */
@route("/")
@get
op root(): Root;
namespace root {
@OpenAPI.operationId("GetRoot")
op read(): Root;
}

/**
* The Root resource provides information on all available resources within the
Expand Down
2 changes: 2 additions & 0 deletions src/species.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace species {
*
* @param search Case-insensitive partial match on the `name` field.
*/
@OpenAPI.operationId("ListSpecies")
op list(search: string): Species[];

@route("/{speciesId}")
Expand All @@ -18,6 +19,7 @@ namespace species {
*
* @param speciesId Numeric ID of the species to get.
*/
@OpenAPI.operationId("GetSpecies")
op read(@path speciesId: int32): Species;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/starships.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace starships {
*
* @param search Case-insensitive partial match on the `name` and `model` fields.
*/
@OpenAPI.operationId("ListStarships")
op list(search: string): Starship[];

@route("/{starshipId}")
Expand All @@ -18,6 +19,7 @@ namespace starships {
*
* @param starshipId Numeric ID of the starship to get.
*/
@OpenAPI.operationId("GetStarship")
op read(@path starshipId: int32): Starship;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/vehicles.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace vehicles {
*
* @param search Case-insensitive partial match on the `name` and `model` fields.
*/
@OpenAPI.operationId("ListVehicles")
op list(search: string): Vehicle[];

@route("/{vehicleId}")
Expand All @@ -18,6 +19,7 @@ namespace vehicles {
*
* @param vehicleId Numeric ID of the vehicle to get.
*/
@OpenAPI.operationId("GetVehicle")
op read(@path vehicleId: int32): Vehicle;
}
}
Expand Down

0 comments on commit dfecd24

Please sign in to comment.