Skip to content

Commit fa1c41c

Browse files
committed
using none for ref strategry
1 parent 36027ac commit fa1c41c

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"ts-jest": "^29.1.1",
128128
"tslib": "^2.6.2",
129129
"typescript": "^5.7.2",
130-
"zod-to-json-schema": "^3.23.5"
130+
"zod-to-json-schema": "^3.24.6"
131131
},
132132
"dependencies": {
133133
"chalk": "^2.4.2",

src/open-api-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class OpenApiSpecificationBuilder<
5050
return this.addComponent('securitySchemes', () => ({ [key]: scheme })) as any;
5151
}
5252

53-
withAWSLambdaApiGatewayIntegration<K extends string>(key: K, functionUri: string, payloadFormatVersion: '1.0' | '2.0' = '1.0', passthroughBehavior: 'when_no_templates' | 'when_no_match' | 'never' = 'when_no_templates')
53+
withAWSLambdaApiGatewayIntegration<const K extends string>(key: K, functionUri: string, payloadFormatVersion: '1.0' | '2.0' = '1.0', passthroughBehavior: 'when_no_templates' | 'when_no_match' | 'never' = 'when_no_templates')
5454
: OpenApiSpecificationBuilder<S, { schemes: T['schemes'], apiIntegrations: [...T['apiIntegrations'], K], }> {
5555
const scheme = {
5656
type: "aws_proxy",

src/schema-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class ZodSchemaBuilder<R extends Record<string, JsonSchema7Type>> {
1010
}
1111

1212
add<S extends string, T extends z.ZodType>(name: S, type: T): ZodSchemaBuilder<R & {[name in S]: JsonSchema7Type}> {
13-
this.schemas[name] = (zodToJsonSchema(type, {name, basePath: ['#','components', 'schemas'] }).definitions as any)[name];
13+
this.schemas[name] = (zodToJsonSchema(type, {name, basePath: ['#','components', 'schemas'], '$refStrategy': 'none' }).definitions as any)[name];
1414
this.schemas[name].title = name;
1515
return this as any;
1616
}

test/model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ export const ChickenCreateRequest = z.object({
1616
});
1717

1818
export type ChickenCreateRequest = z.infer<typeof ChickenCreateRequest>
19+
20+
export const OtherRequest = z.object({
21+
item: z.union([Chicken, ChickenCollection])
22+
});
23+
24+
export type OtherRequest = z.infer<typeof OtherRequest>

test/schema-example.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const servers: OASServer[] = [
1717

1818
const schemas = ZodSchemaBuilder.create()
1919
.add("Chicken", model.Chicken)
20+
.add("OtherRequest", model.OtherRequest)
2021
.add("ChickenCollection", model.ChickenCollection)
2122
.add("ChickenCreateRequest", model.ChickenCreateRequest)
2223
.build()
@@ -25,6 +26,15 @@ export default OpenApiSpecificationBuilder.create(schemas, { title: 'Chicken Sto
2526
.add('servers', oas => servers)
2627
.withAWSCognitoSecurityScheme('Cognito', '${ENDPOINT}', '${CLIENT}')
2728
.withAWSLambdaApiGatewayIntegration('apiHandler', '${API_HANDLER}')
29+
.withPath('other', (path, oas) =>
30+
path.get('getOther', {
31+
'x-amazon-apigateway-integration': oas.awsLambdaApiGatewayIntegration.apiHandler,
32+
security: [oas.securitySchemes.Cognito()],
33+
responses: {
34+
200: oas.jsonResponse('OtherRequest')
35+
}
36+
}
37+
))
2838
.withPath('chicken', (path, oas) =>
2939
path.get('getChickens', {
3040
'x-amazon-apigateway-integration': oas.awsLambdaApiGatewayIntegration.apiHandler,

0 commit comments

Comments
 (0)