Skip to content

Commit

Permalink
feat: register all components/schemas from openapi spec
Browse files Browse the repository at this point in the history
  • Loading branch information
spirius committed Nov 24, 2023
1 parent 8290a9d commit 3ed3296
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/http-api/HttpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class HttpApi<OperationType extends object = object> extends Construct {
}
}

private registerSchema(operation: ParsedOperation<OperationType>): string {
private registerOperationSchema(operation: ParsedOperation<OperationType>): string {
const {
operationId,
request: {
Expand Down Expand Up @@ -361,7 +361,7 @@ export class HttpApi<OperationType extends object = object> extends Construct {
>): Promise<BundlerTypeScriptHandler> {
// get dereferenced version of the operation
const operation = await this.operationParser.parseOperation(pathPattern, method)
const operationTitle = this.registerSchema(operation)
const operationTitle = this.registerOperationSchema(operation)

// render lambda function entry point, handler and validator
const entryPointPath = await this.renderLambdaFiles(operation, operationTitle)
Expand Down Expand Up @@ -471,6 +471,12 @@ export class HttpApi<OperationType extends object = object> extends Construct {
public async _preSynth() {
// write the OpenAPI document
await writeFile(this.documentOutputPath, JSON.stringify(this.config.document, null, 2))

const doc = await this.operationParser.document

if (doc.components?.schemas) {
Object.values(doc.components.schemas).forEach(schema => this.bundler.registerSchema(schema))
}
}

public async _synth() {
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/openapi/OperationParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class OperationParser<OperationType extends object = object> {
}
}

private get document(): PromiseLike<DereferencedDocument<OperationType>> {
public get document(): PromiseLike<DereferencedDocument<OperationType>> {
if (!this.dereferencedDocument) {
this.dereferencedDocument = new Promise<DereferencedDocument<OperationType>>(resolve => {
SwaggerParser.dereference(JSON.parse(JSON.stringify(this.rawDocument))).then(doc =>
Expand Down

0 comments on commit 3ed3296

Please sign in to comment.