diff --git a/Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift b/Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift index a9caec5e..5bb79c56 100644 --- a/Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift +++ b/Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift @@ -122,7 +122,39 @@ func makeGeneratorPipeline( diagnostics: diagnostics ) }, - postTransitionHooks: [] + postTransitionHooks: [ + { doc in + + // Run OpenAPIKit's built-in validation. + try doc.validate() + + // Validate that the document is dereferenceable, which + // catches reference cycles, which we don't yet support. + _ = try doc.locallyDereferenced() + + // Also explicitly dereference the parts of components + // that the generator uses. `locallyDereferenced()` above + // only dereferences paths/operations, but not components. + let components = doc.components + try components.schemas.forEach { schema in + _ = try schema.value.dereferenced(in: components) + } + try components.parameters.forEach { schema in + _ = try schema.value.dereferenced(in: components) + } + try components.headers.forEach { schema in + _ = try schema.value.dereferenced(in: components) + } + try components.requestBodies.forEach { schema in + _ = try schema.value.dereferenced(in: components) + } + try components.responses.forEach { schema in + _ = try schema.value.dereferenced(in: components) + } + + return doc + } + ] ), translateOpenAPIToStructuredSwiftStage: .init( preTransitionHooks: [],