From 9be83f240079ee61e68b64d814ee7e81d954e0ae Mon Sep 17 00:00:00 2001 From: lprnmns Date: Sat, 29 Aug 2026 14:55:22 +0300 Subject: [PATCH 1/2] fix(openapi): support untyped oneOf query properties Signed-off-by: lprnmns --- lib/util/resolve-local-ref.js | 2 +- test/spec/openapi/refs.test.js | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/util/resolve-local-ref.js b/lib/util/resolve-local-ref.js index edf406db..eb38e275 100644 --- a/lib/util/resolve-local-ref.js +++ b/lib/util/resolve-local-ref.js @@ -4,7 +4,7 @@ const { rawRequired } = require('../symbols') const { xConsume } = require('../constants') function resolveLocalRef (jsonSchema, externalSchemas) { - if (jsonSchema.type !== undefined && jsonSchema.properties !== undefined) { + if (jsonSchema.properties !== undefined) { // for the shorthand querystring/params/headers declaration const propertiesMap = Object.keys(jsonSchema.properties).reduce((acc, headers) => { const rewriteProps = {} diff --git a/test/spec/openapi/refs.test.js b/test/spec/openapi/refs.test.js index 4e25c551..b21e8aef 100644 --- a/test/spec/openapi/refs.test.js +++ b/test/spec/openapi/refs.test.js @@ -264,8 +264,7 @@ test('support $ref schema in allOf in headers', async (t) => { t.assert.strictEqual(responseAfterSwagger.statusCode, 200) }) -test('uses examples if has property required in body', async (t) => { - t.plan(3) +test('supports properties in oneOf query schemas without explicit type', async (t) => { const fastify = Fastify() await fastify.register(fastifySwagger, openapiOption) @@ -301,11 +300,25 @@ test('uses examples if has property required in body', async (t) => { await fastify.ready() const openapiObject = fastify.swagger() - const schema = openapiObject.paths['/'].get + await Swagger.validate(openapiObject) + + t.assert.deepStrictEqual( + openapiObject.paths['/'].get.parameters.map(parameter => parameter.name), + ['bar', 'foo'] + ) +}) - t.assert.ok(schema) - t.assert.ok(schema.parameters) - t.assert.deepStrictEqual(schema.parameters[0].in, 'query') +test('supports empty query schemas', async (t) => { + const fastify = Fastify() + + await fastify.register(fastifySwagger, openapiOption) + fastify.get('/', { schema: { query: {} } }, () => {}) + + await fastify.ready() + + const openapiObject = fastify.swagger() + await Swagger.validate(openapiObject) + t.assert.strictEqual(openapiObject.paths['/'].get.parameters, undefined) }) test('renders required query parameter when property is a $ref', async (t) => { From 6a68a4792bd336c4ddb04d9fcfd0cc750c66455f Mon Sep 17 00:00:00 2001 From: Antonio Tripodi Date: Mon, 28 Sep 2026 14:36:23 +0200 Subject: [PATCH 2/2] chore: fix outdated comment in resolveLocalRef Signed-off-by: Antonio Tripodi --- lib/util/resolve-local-ref.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/resolve-local-ref.js b/lib/util/resolve-local-ref.js index eb38e275..ece9ea38 100644 --- a/lib/util/resolve-local-ref.js +++ b/lib/util/resolve-local-ref.js @@ -5,7 +5,7 @@ const { xConsume } = require('../constants') function resolveLocalRef (jsonSchema, externalSchemas) { if (jsonSchema.properties !== undefined) { - // for the shorthand querystring/params/headers declaration + // expand object properties into parameters (`type` may be omitted) const propertiesMap = Object.keys(jsonSchema.properties).reduce((acc, headers) => { const rewriteProps = {} rewriteProps.required = (Array.isArray(jsonSchema.required) && jsonSchema.required.indexOf(headers) >= 0) || false