Skip to content

Commit

Permalink
馃帹 Create CommonResourceMembers for code reuse
Browse files Browse the repository at this point in the history
Creates `common.tsp` with `CommonResourceMembers` that resources spread
for code reuse (model composition).
  • Loading branch information
connorjs committed Sep 11, 2023
1 parent 2723fc5 commit 17818d5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 48 deletions.
14 changes: 14 additions & 0 deletions src/common.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** Members common across all (most) resources. */
model CommonResourceMembers {
// Dev note: Use the spread syntax, not extends. This keeps the name internal.
// https://microsoft.github.io/typespec/language-basics/models#model-composition

/** 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 edited. */
edited: utcDateTime;
}
11 changes: 3 additions & 8 deletions src/films.tsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./common.tsp";

using TypeSpec.Http;

namespace SWAPI;
Expand Down Expand Up @@ -56,12 +58,5 @@ model Film {
/** An array of planet resource URLs that are in this film. */
planets: 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 edited. */
edited: utcDateTime;
...CommonResourceMembers;
}
11 changes: 3 additions & 8 deletions src/people.tsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./common.tsp";

using TypeSpec.Http;

namespace SWAPI;
Expand Down Expand Up @@ -62,12 +64,5 @@ model Person {
/** An array of vehicle resource URLs that this person has piloted. */
vehicles: 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 edited. */
edited: utcDateTime;
...CommonResourceMembers;
}
11 changes: 3 additions & 8 deletions src/planets.tsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./common.tsp";

using TypeSpec.Http;

namespace SWAPI;
Expand Down Expand Up @@ -56,12 +58,5 @@ model Planet {
/** An array of Film URL Resources that this planet has appeared in. */
films: 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 edited. */
edited: utcDateTime;
...CommonResourceMembers;
}
11 changes: 3 additions & 8 deletions src/species.tsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./common.tsp";

using TypeSpec.Http;

namespace SWAPI;
Expand Down Expand Up @@ -60,13 +62,6 @@ namespace species {
/** An array of Film URL Resources that this species has appeared in. */
films: 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 edited. */
edited: utcDateTime;
...CommonResourceMembers;
}
}
11 changes: 3 additions & 8 deletions src/starships.tsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./common.tsp";

using TypeSpec.Http;

namespace SWAPI;
Expand Down Expand Up @@ -68,12 +70,5 @@ model Starship {
/** An array of People URL Resources that this starship has been piloted by. */
pilots: 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 edited. */
edited: utcDateTime;
...CommonResourceMembers;
}
11 changes: 3 additions & 8 deletions src/vehicles.tsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./common.tsp";

using TypeSpec.Http;

namespace SWAPI;
Expand Down Expand Up @@ -62,12 +64,5 @@ model Vehicle {
/** An array of People URL Resources that this vehicle has been piloted by. */
pilots: 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 edited. */
edited: utcDateTime;
...CommonResourceMembers;
}

0 comments on commit 17818d5

Please sign in to comment.