-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make minimal additions to start adding an API gateway Model type, wit…
…h a single test. Add a test for adding a model with valid JSON schema. Document some test cases. Add support for optional model name/description properties. Add test for consumption of a model in a MethodResponse. Add test case for importing an existing model, and using it. Clean up testing todo list. Add test case for exporting a model. Update formatting from 4 to 2 spaces. Create IModelConstruct to expose IConstruct properties on concrete implementations of IModel. Fix tests from rebase to updated master. Add method to RestApi to direclty add a model. Tweak some documentation and add an integration test for an API with defined models. Expose property on model that can be used to generate a canonical reference for another external model to consume. Correct typo in README, and add some comments into code sample. Update comments and make minor syntactic changes. Split ModelProps into two interfaces to handle the constructor vs addModel method cases. Clean up IModel awslint exclusions. Rename IModel -> IModelRef, and IModelConstruct -> IModel. Add JSON schema type safety to the schema property of Model. Fix test errors after merge with 'master'
- Loading branch information
1 parent
fb9fef2
commit b1bdb3d
Showing
12 changed files
with
84,425 additions
and
30 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
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,72 @@ | ||
/** | ||
* Represents a JSON schema definition of the structure of a | ||
* REST API model. Copied from npm module jsonschema. | ||
* | ||
* @see http://json-schema.org/ | ||
* @see https://github.com/tdegrunt/jsonschema | ||
*/ | ||
export interface JsonSchema { | ||
readonly id?: string; | ||
// Exported as $schema - JSII linting does not like the $ | ||
readonly schema?: string; | ||
// Exported as $ref - JSII linting does not like the $ | ||
readonly ref?: string; | ||
readonly title?: string; | ||
readonly description?: string; | ||
readonly multipleOf?: number; | ||
readonly maximum?: number; | ||
readonly exclusiveMaximum?: boolean; | ||
readonly minimum?: number; | ||
readonly exclusiveMinimum?: boolean; | ||
readonly maxLength?: number; | ||
readonly minLength?: number; | ||
readonly pattern?: string; | ||
readonly additionalItems?: boolean | JsonSchema; | ||
readonly items?: JsonSchema | JsonSchema[]; | ||
readonly maxItems?: number; | ||
readonly minItems?: number; | ||
readonly uniqueItems?: boolean; | ||
readonly maxProperties?: number; | ||
readonly minProperties?: number; | ||
readonly required?: string[]; | ||
readonly additionalProperties?: boolean | JsonSchema; | ||
readonly definitions?: { | ||
[name: string]: JsonSchema; | ||
}; | ||
readonly properties?: { | ||
[name: string]: JsonSchema; | ||
}; | ||
readonly patternProperties?: { | ||
[name: string]: JsonSchema; | ||
}; | ||
readonly dependencies?: { | ||
[name: string]: JsonSchema | string[]; | ||
}; | ||
readonly 'enum'?: any[]; | ||
readonly type?: string | string[]; | ||
readonly format?: string; | ||
readonly allOf?: JsonSchema[]; | ||
readonly anyOf?: JsonSchema[]; | ||
readonly oneOf?: JsonSchema[]; | ||
readonly not?: JsonSchema; | ||
} | ||
|
||
export class JsonSchemaMapper { | ||
/** | ||
* Transforms naming of some properties to prefix with a $, where needed | ||
* according to the JSON schema spec | ||
* @param jsonSchema The JsonSchema object to transform for CloudFormation output | ||
*/ | ||
public static toCfnJsonSchema(jsonSchema: JsonSchema): any { | ||
let cfnJsonSchema: string = JSON.stringify(jsonSchema); | ||
JsonSchemaMapper.PropsWithPrefix.forEach(prop => { | ||
const propKey = `"${prop}":`; | ||
const propReplace = `"$${prop}":`; | ||
cfnJsonSchema = cfnJsonSchema.replace(propKey, propReplace); | ||
}); | ||
|
||
return JSON.parse(cfnJsonSchema); | ||
} | ||
|
||
private static readonly PropsWithPrefix = ['schema', 'ref']; | ||
} |
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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import { IModel } from './model'; | ||
import { IModelRef } from './model'; | ||
|
||
export interface MethodResponse { | ||
|
||
/** | ||
* The method response's status code, which you map to an IntegrationResponse. | ||
* Required. | ||
*/ | ||
readonly statusCode: string; | ||
/** | ||
* The method response's status code, which you map to an IntegrationResponse. | ||
* Required. | ||
*/ | ||
readonly statusCode: string; | ||
|
||
/** | ||
* Response parameters that API Gateway sends to the client that called a method. | ||
* Specify response parameters as key-value pairs (string-to-Boolean maps), with | ||
* a destination as the key and a Boolean as the value. Specify the destination | ||
* using the following pattern: method.response.header.name, where the name is a | ||
* valid, unique header name. The Boolean specifies whether a parameter is required. | ||
* @default None | ||
*/ | ||
readonly responseParameters?: { [destination: string]: boolean }; | ||
/** | ||
* Response parameters that API Gateway sends to the client that called a method. | ||
* Specify response parameters as key-value pairs (string-to-Boolean maps), with | ||
* a destination as the key and a Boolean as the value. Specify the destination | ||
* using the following pattern: method.response.header.name, where the name is a | ||
* valid, unique header name. The Boolean specifies whether a parameter is required. | ||
* @default None | ||
*/ | ||
readonly responseParameters?: { [destination: string]: boolean }; | ||
|
||
/** | ||
* The resources used for the response's content type. Specify response models as | ||
* key-value pairs (string-to-string maps), with a content type as the key and a Model | ||
* resource name as the value. | ||
* @default None | ||
*/ | ||
readonly responseModels?: { [contentType: string]: IModel }; | ||
/** | ||
* The resources used for the response's content type. Specify response models as | ||
* key-value pairs (string-to-string maps), with a content type as the key and a Model | ||
* resource name as the value. | ||
* @default None | ||
*/ | ||
readonly responseModels?: { [contentType: string]: IModelRef }; | ||
} |
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
Oops, something went wrong.