Skip to content

feat: add missing required state for query param with $ref #1308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-aliens-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"swagger-typescript-api": patch
---

add missing required state for query param with $ref
5 changes: 5 additions & 0 deletions src/schema-routes/schema-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class SchemaRoutes {
lodash.each(parameters, (parameter) => {
const refTypeInfo =
this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter);

let routeParam = null;

if (refTypeInfo?.rawTypeData.in && refTypeInfo.rawTypeData) {
Expand All @@ -217,6 +218,10 @@ export class SchemaRoutes {
...refTypeInfo.rawTypeData,
...(refTypeInfo.rawTypeData.schema || {}),
};

if (parameter?.required && !routeParam.required) {
routeParam.required = parameter.required;
}
} else {
if (!parameter.in) return;

Expand Down
6 changes: 6 additions & 0 deletions tests/spec/propertyNames/__snapshots__/basic.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ export type FooBarBazNoAdditionalPropertiesPrimitive = object;
export interface FooBarBazNested {
dataCount?: Record<KekEnum, number>;
}

export type ProductId = string;

export interface GetProductsParams {
productId: ProductId;
}
"
`;
4 changes: 3 additions & 1 deletion tests/spec/propertyNames/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ describe("basic", async () => {
output: tmpdir,
silent: true,
generateClient: false,
generateRouteTypes: true,
generateRouteTypes: false,
extractRequestBody: true,
extractRequestParams: true,
});

const content = await fs.readFile(path.join(tmpdir, "schema.ts"), {
Expand Down
43 changes: 43 additions & 0 deletions tests/spec/propertyNames/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ info:
security:
- registryCookieAuth: []
- cookieAuth: [ ]
paths:
/api/v1/products:
get:
operationId: getProducts
tags:
- Products
summary: ASDfdsafdsafdsaf
parameters:
- in: query
required: true
$ref: '#/components/parameters/ProductIdQueryParam'
responses:
'200':
description: KO
components:
schemas:
FooBarBazRoot:
Expand Down Expand Up @@ -53,3 +67,32 @@ components:
- dadd
- xzxzxz
- axzxe
ProductId:
type: string
parameters:
LimitQueryParam:
name: limit
in: query
schema:
type: integer
OffsetQueryParam:
name: offset
in: query
schema:
type: integer
ProductIdPathParam:
name: productId
in: path
required: true
schema:
$ref: '#/components/schemas/ProductId'
ProductIdQueryParam:
name: productId
in: query
schema:
$ref: '#/components/schemas/ProductId'
SearchQueryParam:
name: search
in: query
schema:
type: string