Skip to content

Commit

Permalink
✨ Add Films and Starships
Browse files Browse the repository at this point in the history
Adds `Film` and `Starship` models and their operations.
  • Loading branch information
connorjs committed Sep 9, 2023
1 parent 207c66f commit c4b4e7d
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
57 changes: 57 additions & 0 deletions src/films.tsp
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions src/main.tsp
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import "./root.tsp";
import "./people.tsp";
import "./films.tsp";
import "./starships.tsp";
78 changes: 78 additions & 0 deletions src/starships.tsp
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit c4b4e7d

Please sign in to comment.