aws-apigateway: JsonSchema expects type as enum type
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When hand-writing a schema or importing a schema from somewhere else to use in multiple places, including apigateway, TypeScript rejects the schema:
```
const analyticsEventInputSchema = {
type: 'object',
properties: {
name: { type: 'string' }
}
}
const analyticsEventModel = api.addModel("AnalyticsEvent", {
modelName: "AnalyticsEvent",
contentType: "application/json",
schema: analyticsEventInputSchema,
});
```
### Expected Behavior
This should just work
### Current Behavior
> Types of property 'type' are incompatible.
> Type '"object"' is not assignable to type 'JsonSchemaType | JsonSchemaType[] | undefined'.
### Reproduction Steps
If the example above is not enough to show the issue, I can create a reproducing repo.
### Possible Solution
Introduce a string union type for `JsonSchemaTypeString` and use it here:
https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-apigateway/lib/json-schema.ts#L34
Keep the exported `JsonSchemaType` enum to avoid a breaking change and deprecate it.
### Additional Information/Context
_No response_
### CDK CLI Version
2.20.0
### Framework Version
_No response_
### Node.js Version
16.13.1
### OS
Windows 11
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start in packages/@aws-cdk/aws-apigateway/lib/json-schema.ts at the JsonSchemaType definition and reproduce the TypeScript example from the issue. Confirm that string-literal schema types are accepted while the exported enum remains available and is deprecated; add or update the relevant tests if the surrounding package identifies them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100