From c4b4e7df526483a6cfaf03ed29e4bb17807f9376 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 9 Sep 2023 19:51:42 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20Films=20and=20Starships?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds `Film` and `Starship` models and their operations. --- CONTRIBUTING.md | 5 +++ src/films.tsp | 57 ++++++++++++++++++++++++++++++++++ src/main.tsp | 2 ++ src/starships.tsp | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 src/films.tsp create mode 100644 src/starships.tsp diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fba78a0..bbf044b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,3 +18,8 @@ Use `npm run` to list all available scripts. The `release` script executes a - Using `@resource` adds _all_ REST operations. Thus, the spec files explicitly configure `list` and `read` operations because SWAPI only supports those. + +- Use backticks to escape properties that are TypeSpec keywords. For example, + ```typespec + `model`: string; // Used in starships.tsp + ``` diff --git a/src/films.tsp b/src/films.tsp new file mode 100644 index 0000000..6cd6c65 --- /dev/null +++ b/src/films.tsp @@ -0,0 +1,57 @@ +import "@typespec/http"; +import "@typespec/rest"; + +using TypeSpec.Http; +using TypeSpec.Rest; + +namespace SWAPI; + +@route("/films") +namespace films { + /** + * Get all the film resources. + * + * @param search Case-insensitive partial match on the `title` field. + */ + op list(search: string): Film[]; + + @route("/{filmId}") + namespace film { + /** + * Get a specific film resource. + * + * @param filmId Numeric ID of the film to get. + */ + op read(@path filmId: int32): Film; + } +} + +/** A Film resource is a single film. */ +model Film { + /** The title of this film */ + title: string; + + /** The episode number of this film. */ + episode_id: integer; + + /** The opening paragraphs at the beginning of this film. */ + opening_crawl: string; + + /** The name of the director of this film. */ + director: string; + + /** The name(s) of the producer(s) of this film. Comma separated. */ + producer: string; + + /** The ISO 8601 date format of film release at original creator country. */ + release_date: plainDate; + + /** The hypermedia URL of this resource. */ + url: string; + + /** The ISO 8601 date format of the time that this resource was created. */ + created: string; + + /** The ISO 8601 date format of the time that this resource was edited. */ + edited: string; +} diff --git a/src/main.tsp b/src/main.tsp index 4b65363..b10d5b8 100644 --- a/src/main.tsp +++ b/src/main.tsp @@ -1,2 +1,4 @@ import "./root.tsp"; import "./people.tsp"; +import "./films.tsp"; +import "./starships.tsp"; diff --git a/src/starships.tsp b/src/starships.tsp new file mode 100644 index 0000000..d51df27 --- /dev/null +++ b/src/starships.tsp @@ -0,0 +1,78 @@ +import "@typespec/http"; +import "@typespec/rest"; + +using TypeSpec.Http; +using TypeSpec.Rest; + +namespace SWAPI; + +@route("/starships") +namespace starships { + /** + * Get all the starship resources. + * + * @param search Case-insensitive partial match on the `title` field. + */ + op list(search: string): Starship[]; + + @route("/{starshipId}") + namespace starship { + /** + * Get a specific starship resource. + * + * @param starshipId Numeric ID of the starship to get. + */ + op read(@path starshipId: int32): Starship; + } +} + +/** A Starship resource is a single transport craft that has hyperdrive capability. */ +model Starship { + /** The name of this starship. The common name, such as "Death Star". */ + name: string; + + /** The model or official name of this starship. Such as "T-65 X-wing" or "DS-1 Orbital Battle Station". */ + `model`: string; + + /** The class of this starship, such as "Starfighter" or "Deep Space Mobile Battlestation" */ + starship_class: string; + + /** The manufacturer of this starship. Comma separated if more than one. */ + manufacturer: string; + + /** The cost of this starship new, in galactic credits. */ + cost_in_credits: string; + + /** The length of this starship in meters. */ + length: string; + + /** The number of personnel needed to run or pilot this starship. */ + crew: string; + + /** The number of non-essential people this starship can transport. */ + passengers: string; + + /** The maximum speed of this starship in the atmosphere. "N/A" if this starship is incapable of atmospheric flight. */ + max_atmosphering_speed: string; + + /** The class of this starships hyperdrive. */ + hyperdrive_rating: string; + + /** The Maximum number of Megalights this starship can travel in a standard hour. A "Megalight" is a standard unit of distance and has never been defined before within the Star Wars universe. This figure is only really useful for measuring the difference in speed of starships. We can assume it is similar to AU, the distance between our Sun (Sol) and Earth. */ + MGLT: string; + + /** The maximum number of kilograms that this starship can transport. */ + cargo_capacity: string; + + /** The maximum length of time that this starship can provide consumables for its entire crew without having to resupply. */ + consumables: string; + + /** The hypermedia URL of this resource. */ + url: string; + + /** The ISO 8601 date format of the time that this resource was created. */ + created: string; + + /** The ISO 8601 date format of the time that this resource was edited. */ + edited: string; +}