Skip to content

Commit

Permalink
✨ Person/People resource
Browse files Browse the repository at this point in the history
Adds the `Person` model and people operations.

Note: Using `@resource` adds _all_ REST operations. Thus, this
explicitly configures list and read because SWAPI only supports those.
  • Loading branch information
connorjs committed Sep 9, 2023
1 parent f356a65 commit e2d5d0d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

[TypeSpec][typespec] representation of [SWAPI: The Star Wars API][swapi].

## Notes

- Using `@resource` adds _all_ REST operations. Thus, the spec files explicitly
configure `list` and `read` operations because SWAPI only supports those.

[swapi]: https://swapi.dev
[typespec]: https://microsoft.github.io/typespec/
1 change: 1 addition & 0 deletions src/main.tsp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import "./root.tsp";
import "./person.tsp";
57 changes: 57 additions & 0 deletions src/person.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("/people")
namespace people {
@doc("Get all the people resources")
op list(): Person[];

@route("/{personId}")
namespace person {
@doc("Get a specific people resource")
op read(@path personId: int32): Person;
}
}

model Person {
@doc("The name of this person.")
name: string;

@doc("The birth year of the person, using the in-universe standard of BBY or ABY - Before the Battle of Yavin or After the Battle of Yavin. The Battle of Yavin is a battle that occurs at the end of Star Wars episode IV: A New Hope.")
birth_year: string;

@doc("The eye color of this person. Will be \"unknown\" if not known or \"n/a\" if the person does not have an eye.")
eye_color: string;

@doc("The gender of this person. Either \"Male\", \"Female\" or \"unknown\", \"n/a\" if the person does not have a gender.")
gender: string;

@doc("The hair color of this person. Will be \"unknown\" if not known or \"n/a\" if the person does not have hair.")
hair_color: string;

@doc("The height of the person in centimeters.")
height: string;

@doc("The mass of the person in kilograms.")
mass: string;

@doc("The skin color of this person.")
skin_color: string;

@doc("The URL of a planet resource, a planet that this person was born on or inhabits.")
homeworld: string;

@doc("The hypermedia URL of this resource.")
url: string;

@doc("The ISO 8601 date format of the time that this resource was created.")
created: string;

@doc("The ISO 8601 date format of the time that this resource was edited.")
edited: string;
}

0 comments on commit e2d5d0d

Please sign in to comment.