-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(type-safe-api): separate model projects per model language (#872)
Rather than sharing a single `TypeSafeApiModelProject` for both Smithy and OpenAPI, we separate them into their own projects. This improves the ability to add future additional model languages since they can inherit from other projen project types (not just `Project`). This also makes instantiating standalone Smithy libraries more intuitive as they are created with `SmithyModelProject`, rather than `TypeSafeApiModelProject` and modelLanguage set to SMITHY, therefore no `!` needs to be used to access the possibly undefined `smithy` property. BREAKING CHANGE: Removed `TypeSafeApiModelProject`. Please instantiate Smithy shape libraries with `SmithyModelProject`. re #825
- Loading branch information
Showing
29 changed files
with
882 additions
and
587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/type-safe-api/src/project/codegen/components/generate-task.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 */ | ||
import { ProjectUtils } from "@aws/monorepo"; | ||
import { Component, Project, Task } from "projen"; | ||
|
||
/** | ||
* Component which manages a "generate" task for a project | ||
*/ | ||
export class GenerateTask extends Component { | ||
/** | ||
* Retrieves an instance of GenerateTask if one is associated to the given project. | ||
* | ||
* @param project project instance. | ||
*/ | ||
static of(project: Project): Task | undefined { | ||
return ( | ||
project.components.find((c) => | ||
ProjectUtils.isNamedInstanceOf(c, GenerateTask) | ||
) as GenerateTask | undefined | ||
)?.task; | ||
} | ||
|
||
/** | ||
* Retrieves an instance of GenerateTask if one is associated to the given project, | ||
* otherwise creates a GenerateTask instance for the project. | ||
* | ||
* @param project project instance. | ||
*/ | ||
static ensure(project: Project): Task { | ||
return GenerateTask.of(project) || new GenerateTask(project).task; | ||
} | ||
|
||
public readonly task: Task; | ||
|
||
constructor(project: Project) { | ||
super(project); | ||
|
||
this.task = | ||
project.tasks.tryFind("generate") ?? project.addTask("generate"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 */ | ||
import * as path from "path"; | ||
import { Project, SampleFile } from "projen"; | ||
import { ModelLanguage } from "../types"; | ||
|
||
/** | ||
* Options for the model readme | ||
*/ | ||
export interface ModelReadmeOptions { | ||
/** | ||
* Language for the model | ||
*/ | ||
readonly modelLanguage: ModelLanguage; | ||
/** | ||
* Type of API | ||
*/ | ||
readonly apiType: "rest" | "async"; | ||
} | ||
|
||
/** | ||
* README.md file for a model project | ||
*/ | ||
export class ModelReadme extends SampleFile { | ||
constructor(project: Project, options: ModelReadmeOptions) { | ||
super(project, "README.md", { | ||
sourcePath: path.resolve( | ||
__dirname, | ||
"..", | ||
"..", | ||
"..", | ||
"samples", | ||
"type-safe-api", | ||
"readme", | ||
`model-${options.apiType}`, | ||
`${options.modelLanguage}.md` | ||
), | ||
}); | ||
} | ||
} |
Oops, something went wrong.