From bad61276a63fbc9a884ff707f52302a2b6271f99 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Fri, 25 Aug 2023 21:27:04 +0200 Subject: [PATCH 1/3] Support OpenAPI 3.1 in addition to 3.0 --- Package.swift | 2 + .../_OpenAPIGeneratorCore/Diagnostics.swift | 2 +- .../Extensions/OpenAPIKit.swift | 8 +++- .../GeneratorPipeline.swift | 2 +- .../Layers/ParsedOpenAPIRepresentation.swift | 2 +- .../Parser/YamsParser.swift | 40 +++++++++++-------- .../ClientTranslator/ClientTranslator.swift | 2 +- .../translateClientMethod.swift | 2 +- .../translateAllAnyOneOf.swift | 2 +- .../CommonTranslations/translateArray.swift | 2 +- .../CommonTranslations/translateCodable.swift | 2 +- .../translateObjectStruct.swift | 2 +- .../translateRawRepresentableEnum.swift | 2 +- .../CommonTranslations/translateSchema.swift | 4 +- .../translateStringEnum.swift | 2 +- .../translateStructBlueprint.swift | 2 +- .../translateTypealias.swift | 2 +- .../CommonTypes/CommentExtensions.swift | 2 +- .../Translator/CommonTypes/Constants.swift | 2 +- .../CommonTypes/DiscriminatorExtensions.swift | 2 +- .../CommonTypes/SchemaOverrides.swift | 2 +- .../CommonTypes/StructBlueprint.swift | 2 +- .../Translator/Content/ContentInspector.swift | 2 +- .../Translator/Content/ContentSwiftName.swift | 2 +- .../Translator/Content/ContentType.swift | 2 +- .../Translator/Content/SchemaContent.swift | 4 +- .../FileTranslator+FeatureFlags.swift | 2 +- .../Translator/FileTranslator.swift | 2 +- .../Translator/MultiplexTranslator.swift | 2 +- .../Operations/OperationDescription.swift | 2 +- .../Parameters/TypedParameter.swift | 4 +- .../Parameters/translateParameter.swift | 2 +- .../RequestBody/TypedRequestBody.swift | 4 +- .../RequestBody/translateRequestBody.swift | 2 +- .../Translator/Responses/ResponseKind.swift | 2 +- .../Translator/Responses/TypedResponse.swift | 4 +- .../Responses/TypedResponseHeader.swift | 4 +- .../Responses/acceptHeaderContentTypes.swift | 2 +- .../Responses/translateResponse.swift | 2 +- .../Responses/translateResponseHeader.swift | 2 +- .../Responses/translateResponseOutcome.swift | 2 +- .../ServerTranslator/ServerTranslator.swift | 2 +- .../translateServerMethod.swift | 2 +- .../Translator/TranslatorProtocol.swift | 2 +- .../TypeAssignment/TypeAssigner.swift | 21 +++++++++- .../TypeAssignment/TypeLocation.swift | 2 +- .../TypeAssignment/TypeMatcher.swift | 6 +-- .../TypeAssignment/isSchemaSupported.swift | 4 +- .../TypesTranslator/TypesFileTranslator.swift | 2 +- .../translateAPIProtocol.swift | 2 +- .../translateComponentHeaders.swift | 2 +- .../translateComponentParameters.swift | 2 +- .../translateComponentRequestBodies.swift | 2 +- .../translateComponentResponses.swift | 2 +- .../TypesTranslator/translateComponents.swift | 2 +- .../TypesTranslator/translateOperations.swift | 2 +- .../TypesTranslator/translateSchemas.swift | 2 +- .../TypesTranslator/translateServers.swift | 2 +- .../GenerateOptions.swift | 2 +- .../Parser/Test_YamsParser.swift | 9 +++-- .../Parser/Test_validateDoc.swift | 2 +- .../TestUtilities.swift | 2 +- .../Test_translateCodable.swift | 2 +- .../Test_translateStringEnum.swift | 2 +- .../Test_translateStructBlueprint.swift | 2 +- .../Test_DiscriminatorExtensions.swift | 2 +- .../Content/Test_ContentSwiftName.swift | 2 +- .../Translator/Content/Test_ContentType.swift | 2 +- .../Test_OperationDescription.swift | 2 +- .../TypeAssignment/Test_TypeAssigner.swift | 12 +++--- .../TypeAssignment/Test_TypeMatcher.swift | 2 +- .../Test_isSchemaSupported.swift | 2 +- .../Test_translateSchemas.swift | 2 +- .../FileBasedReferenceTests.swift | 2 +- .../Resources/Docs/petstore.yaml | 2 +- .../SnippetBasedReferenceTests.swift | 4 +- 76 files changed, 143 insertions(+), 109 deletions(-) diff --git a/Package.swift b/Package.swift index 368e45a1..91c9a046 100644 --- a/Package.swift +++ b/Package.swift @@ -91,7 +91,9 @@ let package = Package( .target( name: "_OpenAPIGeneratorCore", dependencies: [ + .product(name: "OpenAPIKit", package: "OpenAPIKit"), .product(name: "OpenAPIKit30", package: "OpenAPIKit"), + .product(name: "OpenAPIKitCompat", package: "OpenAPIKit"), .product(name: "Algorithms", package: "swift-algorithms"), .product(name: "Yams", package: "Yams"), .product(name: "SwiftSyntax", package: "swift-syntax"), diff --git a/Sources/_OpenAPIGeneratorCore/Diagnostics.swift b/Sources/_OpenAPIGeneratorCore/Diagnostics.swift index f990eff7..0628cd26 100644 --- a/Sources/_OpenAPIGeneratorCore/Diagnostics.swift +++ b/Sources/_OpenAPIGeneratorCore/Diagnostics.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import Foundation -import OpenAPIKit30 +import OpenAPIKit /// A message emitted by the generator. public struct Diagnostic: Error, Codable { diff --git a/Sources/_OpenAPIGeneratorCore/Extensions/OpenAPIKit.swift b/Sources/_OpenAPIGeneratorCore/Extensions/OpenAPIKit.swift index 0316eac0..98e0a8e3 100644 --- a/Sources/_OpenAPIGeneratorCore/Extensions/OpenAPIKit.swift +++ b/Sources/_OpenAPIGeneratorCore/Extensions/OpenAPIKit.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension Either { @@ -20,7 +20,7 @@ extension Either { /// - Parameter components: The Components section of the OpenAPI document. func resolve( in components: OpenAPI.Components - ) throws -> B where A == JSONReference { + ) throws -> B where A == OpenAPI.Reference { switch self { case let .a(a): return try components.lookup(a) @@ -59,6 +59,8 @@ extension JSONSchema.Schema { return "reference" case .fragment: return "fragment" + case .null: + return "null" } } @@ -89,6 +91,8 @@ extension JSONSchema.Schema { return nil case .fragment(let coreContext): return coreContext.formatString + case .null: + return nil } } diff --git a/Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift b/Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift index dbe0e045..1b508b70 100644 --- a/Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift +++ b/Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit import Foundation import Yams diff --git a/Sources/_OpenAPIGeneratorCore/Layers/ParsedOpenAPIRepresentation.swift b/Sources/_OpenAPIGeneratorCore/Layers/ParsedOpenAPIRepresentation.swift index 5cbba9d8..f322580e 100644 --- a/Sources/_OpenAPIGeneratorCore/Layers/ParsedOpenAPIRepresentation.swift +++ b/Sources/_OpenAPIGeneratorCore/Layers/ParsedOpenAPIRepresentation.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// An OpenAPIKit document that contains the operations and types for which the generator emits Swift types. typealias ParsedOpenAPIRepresentation = OpenAPI.Document diff --git a/Sources/_OpenAPIGeneratorCore/Parser/YamsParser.swift b/Sources/_OpenAPIGeneratorCore/Parser/YamsParser.swift index 6398d500..948d7a9b 100644 --- a/Sources/_OpenAPIGeneratorCore/Parser/YamsParser.swift +++ b/Sources/_OpenAPIGeneratorCore/Parser/YamsParser.swift @@ -12,7 +12,9 @@ // //===----------------------------------------------------------------------===// import Foundation +import OpenAPIKit import OpenAPIKit30 +import OpenAPIKitCompat import Yams /// A parser that uses the Yams library to parse the provided @@ -44,21 +46,27 @@ struct YamsParser: ParserProtocol { guard let openAPIVersion = versionedDocument.openapi else { throw Diagnostic.openAPIMissingVersionError(location: .init(filePath: input.absolutePath.path)) } - switch openAPIVersion { - case "3.0.0", "3.0.1", "3.0.2", "3.0.3": - break - default: - throw Diagnostic.openAPIVersionError( - versionString: "openapi: \(openAPIVersion)", - location: .init(filePath: input.absolutePath.path) - ) - } - do { - return try decoder.decode( - OpenAPI.Document.self, - from: input.contents - ) + let document: OpenAPIKit.OpenAPI.Document + switch openAPIVersion { + case "3.0.0", "3.0.1", "3.0.2", "3.0.3": + let openAPI30Document = try decoder.decode( + OpenAPIKit30.OpenAPI.Document.self, + from: input.contents + ) + document = openAPI30Document.convert(to: .v3_1_0) + case "3.1.0": + document = try decoder.decode( + OpenAPIKit.OpenAPI.Document.self, + from: input.contents + ) + default: + throw Diagnostic.openAPIVersionError( + versionString: "openapi: \(openAPIVersion)", + location: .init(filePath: input.absolutePath.path) + ) + } + return document } catch DecodingError.dataCorrupted(let errorContext) { try checkParsingError(context: errorContext, input: input) throw DecodingError.dataCorrupted(errorContext) @@ -104,7 +112,7 @@ extension Diagnostic { static func openAPIVersionError(versionString: String, location: Location) -> Diagnostic { return error( message: - "Unsupported document version: \(versionString). Please provide a document with OpenAPI versions in the 3.0.x set.", + "Unsupported document version: \(versionString). Please provide a document with OpenAPI versions in the 3.0.x or 3.1.x sets.", location: location ) } @@ -115,7 +123,7 @@ extension Diagnostic { static func openAPIMissingVersionError(location: Location) -> Diagnostic { return error( message: - "No openapi key found, please provide a valid OpenAPI document with OpenAPI versions in the 3.0.x set.", + "No openapi key found, please provide a valid OpenAPI document with OpenAPI versions in the 3.0.x or 3.1.x sets.", location: location ) } diff --git a/Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/ClientTranslator.swift b/Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/ClientTranslator.swift index 0a194854..393b0875 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/ClientTranslator.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/ClientTranslator.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A translator for the generated client. /// diff --git a/Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/translateClientMethod.swift b/Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/translateClientMethod.swift index 108e3088..0d3fcf5d 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/translateClientMethod.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/translateClientMethod.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension ClientFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateAllAnyOneOf.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateAllAnyOneOf.swift index a567862f..08469b7c 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateAllAnyOneOf.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateAllAnyOneOf.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// Describes one of the two options: allOf or anyOf. enum AllOrAnyOf { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateArray.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateArray.swift index f7a41621..f4c14203 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateArray.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateArray.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateCodable.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateCodable.swift index 0f187a82..baae4679 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateCodable.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateCodable.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateObjectStruct.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateObjectStruct.swift index d5369c79..71c7c1cf 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateObjectStruct.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateObjectStruct.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateRawRepresentableEnum.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateRawRepresentableEnum.swift index a1c18014..e1b963ca 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateRawRepresentableEnum.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateRawRepresentableEnum.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateSchema.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateSchema.swift index 58b6b049..77cdce6c 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateSchema.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateSchema.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { @@ -38,7 +38,7 @@ extension FileTranslator { switch schema { case let .a(ref): // reference, wrap that into JSONSchema - unwrappedSchema = .reference(ref) + unwrappedSchema = .reference(ref.jsonReference) case let .b(schema): unwrappedSchema = schema } diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStringEnum.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStringEnum.swift index f663fe94..13a4f286 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStringEnum.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStringEnum.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStructBlueprint.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStructBlueprint.swift index 7cc0e758..d011d8ca 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStructBlueprint.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStructBlueprint.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateTypealias.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateTypealias.swift index 00304c16..ab734ca0 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateTypealias.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateTypealias.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/CommentExtensions.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/CommentExtensions.swift index 9ba10355..069309a3 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/CommentExtensions.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/CommentExtensions.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension Comment { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/Constants.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/Constants.swift index 9956ff3d..695d9af1 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/Constants.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/Constants.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// Constant values used in generated code, some of which refer to type names /// in the Runtime library, so they need to be kept in sync. diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/DiscriminatorExtensions.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/DiscriminatorExtensions.swift index 130f3d11..3872e1c2 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/DiscriminatorExtensions.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/DiscriminatorExtensions.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit import Foundation /// A child schema of a oneOf with a discriminator. diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/SchemaOverrides.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/SchemaOverrides.swift index 4b6f20c0..0e380bf5 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/SchemaOverrides.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/SchemaOverrides.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A container of properties that can be defined at multiple levels in /// the OpenAPI document. If a property is filled in, the value is used instead diff --git a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/StructBlueprint.swift b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/StructBlueprint.swift index d38c9f75..1a15ffc9 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/StructBlueprint.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/StructBlueprint.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A structure that contains the information about an OpenAPI object that is /// required to generate a matching Swift structure. diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentInspector.swift b/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentInspector.swift index 0fac1f13..8ed19037 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentInspector.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentInspector.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// Utilities for asking questions about OpenAPI.Content extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentSwiftName.swift b/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentSwiftName.swift index fc7b710d..637946b1 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentSwiftName.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentSwiftName.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentType.swift b/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentType.swift index 5b29ce76..991f9135 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentType.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Content/ContentType.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A content type of a request, response, and other types. /// diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Content/SchemaContent.swift b/Sources/_OpenAPIGeneratorCore/Translator/Content/SchemaContent.swift index a3e1fa6e..5665488d 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Content/SchemaContent.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Content/SchemaContent.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A type representing OpenAPI content that contains both a content type /// and the optional JSON schema. @@ -48,4 +48,4 @@ struct TypedSchemaContent { /// An unresolved OpenAPI schema. /// /// Can be either a reference or an inline schema. -typealias UnresolvedSchema = Either, JSONSchema> +typealias UnresolvedSchema = Either, JSONSchema> diff --git a/Sources/_OpenAPIGeneratorCore/Translator/FileTranslator+FeatureFlags.swift b/Sources/_OpenAPIGeneratorCore/Translator/FileTranslator+FeatureFlags.swift index 66ea70e5..7b2a587c 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/FileTranslator+FeatureFlags.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/FileTranslator+FeatureFlags.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/FileTranslator.swift b/Sources/_OpenAPIGeneratorCore/Translator/FileTranslator.swift index c81a71a9..90122176 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/FileTranslator.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/FileTranslator.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// An object that generates a Swift file for a provided OpenAPI document. /// diff --git a/Sources/_OpenAPIGeneratorCore/Translator/MultiplexTranslator.swift b/Sources/_OpenAPIGeneratorCore/Translator/MultiplexTranslator.swift index a617e2c4..298a8545 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/MultiplexTranslator.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/MultiplexTranslator.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A translator that inspects the generator configuration and delegates /// the code generation logic to the appropriate translator. diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift b/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift index a6f5b98f..d2951aa0 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Operations/OperationDescription.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A wrapper of an OpenAPI operation that includes the information /// about the parent containers of the operation, such as its path diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Parameters/TypedParameter.swift b/Sources/_OpenAPIGeneratorCore/Translator/Parameters/TypedParameter.swift index 356af5ad..46e63d5a 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Parameters/TypedParameter.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Parameters/TypedParameter.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A container for an OpenAPI parameter and its computed Swift type usage. struct TypedParameter { @@ -258,7 +258,7 @@ extension FileTranslator { /// An unresolved OpenAPI parameter. /// /// Can be either a reference or an inline parameter. -typealias UnresolvedParameter = Either, OpenAPI.Parameter> +typealias UnresolvedParameter = Either, OpenAPI.Parameter> extension OpenAPI.Parameter.Context.Location { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Parameters/translateParameter.swift b/Sources/_OpenAPIGeneratorCore/Translator/Parameters/translateParameter.swift index 571e9936..fe880797 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Parameters/translateParameter.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Parameters/translateParameter.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/RequestBody/TypedRequestBody.swift b/Sources/_OpenAPIGeneratorCore/Translator/RequestBody/TypedRequestBody.swift index 3a2a3266..2f311765 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/RequestBody/TypedRequestBody.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/RequestBody/TypedRequestBody.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A container for an OpenAPI request body and its computed Swift type usage. struct TypedRequestBody { @@ -117,4 +117,4 @@ extension FileTranslator { /// An unresolved OpenAPI request. /// /// Can be either a reference or an inline request. -typealias UnresolvedRequest = Either, OpenAPI.Request> +typealias UnresolvedRequest = Either, OpenAPI.Request> diff --git a/Sources/_OpenAPIGeneratorCore/Translator/RequestBody/translateRequestBody.swift b/Sources/_OpenAPIGeneratorCore/Translator/RequestBody/translateRequestBody.swift index 54df348e..b578dbaf 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/RequestBody/translateRequestBody.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/RequestBody/translateRequestBody.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Responses/ResponseKind.swift b/Sources/_OpenAPIGeneratorCore/Translator/Responses/ResponseKind.swift index a87f516f..2bab6065 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Responses/ResponseKind.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Responses/ResponseKind.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A type of an OpenAPI operation response: a specific HTTP status code, /// a range of HTTP status codes, or default. diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Responses/TypedResponse.swift b/Sources/_OpenAPIGeneratorCore/Translator/Responses/TypedResponse.swift index c749cd3b..79a9e548 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Responses/TypedResponse.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Responses/TypedResponse.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A container for an OpenAPI response and its computed Swift type usage. struct TypedResponse { @@ -63,4 +63,4 @@ extension FileTranslator { /// An unresolved OpenAPI response. /// /// Can be either a reference or an inline response. -typealias UnresolvedResponse = Either, OpenAPI.Response> +typealias UnresolvedResponse = Either, OpenAPI.Response> diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Responses/TypedResponseHeader.swift b/Sources/_OpenAPIGeneratorCore/Translator/Responses/TypedResponseHeader.swift index 5026070f..663ff0c6 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Responses/TypedResponseHeader.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Responses/TypedResponseHeader.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A container for an OpenAPI response header and its computed /// Swift type usage. @@ -173,4 +173,4 @@ extension FileTranslator { /// An unresolved OpenAPI response header. /// /// Can be either a reference or an inline response header. -typealias UnresolvedHeader = Either, OpenAPI.Header> +typealias UnresolvedHeader = Either, OpenAPI.Header> diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Responses/acceptHeaderContentTypes.swift b/Sources/_OpenAPIGeneratorCore/Translator/Responses/acceptHeaderContentTypes.swift index 6e838166..0afac8a6 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Responses/acceptHeaderContentTypes.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Responses/acceptHeaderContentTypes.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit import Algorithms extension FileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponse.swift b/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponse.swift index 0003ea46..3dbb0e6a 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponse.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponse.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseHeader.swift b/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseHeader.swift index 867b9885..eb83cb26 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseHeader.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseHeader.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseOutcome.swift b/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseOutcome.swift index 4c89c276..4741b251 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseOutcome.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/Responses/translateResponseOutcome.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift b/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift index 8438309f..b183cffb 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A translator for the generated server. /// diff --git a/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/translateServerMethod.swift b/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/translateServerMethod.swift index b53f6ee6..8cf2cf9f 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/translateServerMethod.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/translateServerMethod.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension ServerFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TranslatorProtocol.swift b/Sources/_OpenAPIGeneratorCore/Translator/TranslatorProtocol.swift index d5b8ad17..09377c8b 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TranslatorProtocol.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TranslatorProtocol.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// An object that turns an OpenAPI document into the structured Swift /// representation of the request generated file: types, client, or server. diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeAssigner.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeAssigner.swift index b641b45c..1743885e 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeAssigner.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeAssigner.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit import Foundation /// A set of functions that compute the deterministic, unique, and global @@ -368,6 +368,25 @@ struct TypeAssigner { return try typeName(for: internalReference, in: componentType) } + /// Returns a type name for an OpenAPI reference. + /// + /// Behaves similarly to JSONReference. + /// + /// - NOTE: Only internal references are currently supported; throws an error for external references. + /// - Parameters: + /// - reference: The reference to compute a type name for. + /// - componentType: The type of the component to which the reference + /// points. + func typeName( + for reference: OpenAPI.Reference, + in componentType: Component.Type = Component.self + ) throws -> TypeName { + try typeName( + for: reference.jsonReference, + in: componentType + ) + } + /// Returns a type name for an internal reference to a component. /// /// - NOTE: Only component references are supported; throws an error for paths outside of the Components object. diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeLocation.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeLocation.swift index 5d01f70d..7f64228c 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeLocation.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeLocation.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// Describes the location of a name type in the OpenAPI document. enum TypeLocation { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeMatcher.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeMatcher.swift index 1b9ffef6..174da412 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeMatcher.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeMatcher.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A set of functions that match Swift types onto OpenAPI types. struct TypeMatcher { @@ -71,7 +71,7 @@ struct TypeMatcher { ) throws -> TypeUsage? { try Self._tryMatchRecursive( for: schema.value, - test: { schema in + test: { (schema) -> TypeUsage? in if let builtinType = Self._tryMatchBuiltinNonRecursive(for: schema) { return builtinType } @@ -238,7 +238,7 @@ struct TypeMatcher { // arrays are already recursed-into by _tryMatchTypeRecursive // so just return nil here return nil - case .reference, .not, .all, .any, .one: + case .reference, .not, .all, .any, .one, .null: // never built-in return nil } diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/isSchemaSupported.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/isSchemaSupported.swift index a868f40a..5c964a49 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/isSchemaSupported.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/isSchemaSupported.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A result of checking whether a schema is supported. enum IsSchemaSupportedResult: Equatable { @@ -163,7 +163,7 @@ extension FileTranslator { // > When using the discriminator, inline schemas will not be considered. // > — https://spec.openapis.org/oas/v3.0.3#discriminator-object return try areRefsToObjectishSchemaAndSupported(schemas.filter(\.isReference)) - case .not: + case .not, .null: return .unsupported( reason: .schemaType, schema: schema diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/TypesFileTranslator.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/TypesFileTranslator.swift index 23e3432f..485e1acc 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/TypesFileTranslator.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/TypesFileTranslator.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit /// A translator for the generated common types. /// diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateAPIProtocol.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateAPIProtocol.swift index 422320ee..9cbb4198 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateAPIProtocol.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateAPIProtocol.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentHeaders.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentHeaders.swift index fdeb9c3f..9f50c91f 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentHeaders.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentHeaders.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentParameters.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentParameters.swift index a839223c..d8845a4f 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentParameters.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentParameters.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentRequestBodies.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentRequestBodies.swift index 54de2b1e..ac581608 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentRequestBodies.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentRequestBodies.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentResponses.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentResponses.swift index f9c64082..c3d8e8b8 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentResponses.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponentResponses.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponents.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponents.swift index b5347c16..ed5dc1e9 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponents.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateComponents.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateOperations.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateOperations.swift index 648db594..46e12f47 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateOperations.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateOperations.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateSchemas.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateSchemas.swift index 0d4cd276..24dec36b 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateSchemas.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateSchemas.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateServers.swift b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateServers.swift index 5a0597da..8fb073d2 100644 --- a/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateServers.swift +++ b/Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateServers.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit extension TypesFileTranslator { diff --git a/Sources/swift-openapi-generator/GenerateOptions.swift b/Sources/swift-openapi-generator/GenerateOptions.swift index ef2e7de9..73460805 100644 --- a/Sources/swift-openapi-generator/GenerateOptions.swift +++ b/Sources/swift-openapi-generator/GenerateOptions.swift @@ -14,7 +14,7 @@ import ArgumentParser import Foundation import Yams -import OpenAPIKit30 +import OpenAPIKit import _OpenAPIGeneratorCore struct _GenerateOptions: ParsableArguments { diff --git a/Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift b/Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift index 9cbed193..121f2f16 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift @@ -21,13 +21,14 @@ final class Test_YamsParser: Test_Core { XCTAssertNoThrow(try _test(openAPIVersionString: "3.0.1")) XCTAssertNoThrow(try _test(openAPIVersionString: "3.0.2")) XCTAssertNoThrow(try _test(openAPIVersionString: "3.0.3")) + XCTAssertNoThrow(try _test(openAPIVersionString: "3.1.0")) let expected1 = - "/foo.yaml: error: Unsupported document version: openapi: 3.1.0. Please provide a document with OpenAPI versions in the 3.0.x set." - assertThrownError(try _test(openAPIVersionString: "3.1.0"), expectedDiagnostic: expected1) + "/foo.yaml: error: Unsupported document version: openapi: 3.2.0. Please provide a document with OpenAPI versions in the 3.0.x or 3.1.x sets." + assertThrownError(try _test(openAPIVersionString: "3.2.0"), expectedDiagnostic: expected1) let expected2 = - "/foo.yaml: error: Unsupported document version: openapi: 2.0. Please provide a document with OpenAPI versions in the 3.0.x set." + "/foo.yaml: error: Unsupported document version: openapi: 2.0. Please provide a document with OpenAPI versions in the 3.0.x or 3.1.x sets." assertThrownError(try _test(openAPIVersionString: "2.0"), expectedDiagnostic: expected2) } @@ -53,7 +54,7 @@ final class Test_YamsParser: Test_Core { """ let expected = - "/foo.yaml: error: No openapi key found, please provide a valid OpenAPI document with OpenAPI versions in the 3.0.x set." + "/foo.yaml: error: No openapi key found, please provide a valid OpenAPI document with OpenAPI versions in the 3.0.x or 3.1.x sets." assertThrownError(try _test(yaml), expectedDiagnostic: expected) } diff --git a/Tests/OpenAPIGeneratorCoreTests/Parser/Test_validateDoc.swift b/Tests/OpenAPIGeneratorCoreTests/Parser/Test_validateDoc.swift index f41ece07..adefedae 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Parser/Test_validateDoc.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Parser/Test_validateDoc.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_validateDoc: Test_Core { diff --git a/Tests/OpenAPIGeneratorCoreTests/TestUtilities.swift b/Tests/OpenAPIGeneratorCoreTests/TestUtilities.swift index a33365a5..e27d7aee 100644 --- a/Tests/OpenAPIGeneratorCoreTests/TestUtilities.swift +++ b/Tests/OpenAPIGeneratorCoreTests/TestUtilities.swift @@ -14,7 +14,7 @@ import XCTest import Foundation import Yams -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore class Test_Core: XCTestCase { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateCodable.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateCodable.swift index d515be6f..23f0be57 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateCodable.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateCodable.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_translateCodable: Test_Core { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateStringEnum.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateStringEnum.swift index 59a41509..abc7040f 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateStringEnum.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateStringEnum.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_translateStringEnum: Test_Core { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateStructBlueprint.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateStructBlueprint.swift index 5ab177d6..d471eb5b 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateStructBlueprint.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTranslations/Test_translateStructBlueprint.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_translateStructBlueprint: Test_Core { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTypes/Test_DiscriminatorExtensions.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTypes/Test_DiscriminatorExtensions.swift index 1eb90ce8..452b25d3 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTypes/Test_DiscriminatorExtensions.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/CommonTypes/Test_DiscriminatorExtensions.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_DiscriminatorExtensions: Test_Core { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/Content/Test_ContentSwiftName.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/Content/Test_ContentSwiftName.swift index c6a39ac1..b2a0e32f 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/Content/Test_ContentSwiftName.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/Content/Test_ContentSwiftName.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_ContentSwiftName: Test_Core { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/Content/Test_ContentType.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/Content/Test_ContentType.swift index 24348f43..629c10df 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/Content/Test_ContentType.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/Content/Test_ContentType.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_ContentType: Test_Core { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift index 8f6824af..2a767758 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit import XCTest @testable import _OpenAPIGeneratorCore diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeAssigner.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeAssigner.swift index 3fdf69a1..a9a8092b 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeAssigner.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeAssigner.swift @@ -12,28 +12,28 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore class Test_TypeAssigner: Test_Core { func testTypeNameForReferences() throws { try XCTAssertEqual( - typeAssigner.typeName(for: JSONReference.component(named: "mumble")), + typeAssigner.typeName(for: OpenAPI.Reference.component(named: "mumble")), newTypeName( swiftFQName: "Components.Schemas.mumble", jsonFQName: "#/components/schemas/mumble" ) ) try XCTAssertEqual( - typeAssigner.typeName(for: JSONReference.component(named: "mumble")), + typeAssigner.typeName(for: OpenAPI.Reference.component(named: "mumble")), newTypeName( swiftFQName: "Components.Parameters.mumble", jsonFQName: "#/components/parameters/mumble" ) ) try XCTAssertEqual( - typeAssigner.typeName(for: JSONReference.component(named: "mumble")), + typeAssigner.typeName(for: OpenAPI.Reference.component(named: "mumble")), newTypeName( swiftFQName: "Components.Headers.mumble", jsonFQName: "#/components/headers/mumble" @@ -41,7 +41,7 @@ class Test_TypeAssigner: Test_Core { ) try XCTAssertEqual( - typeAssigner.typeName(for: JSONReference.component(named: "mumble")), + typeAssigner.typeName(for: OpenAPI.Reference.component(named: "mumble")), newTypeName( swiftFQName: "Components.RequestBodies.mumble", jsonFQName: "#/components/requestBodies/mumble" @@ -49,7 +49,7 @@ class Test_TypeAssigner: Test_Core { ) try XCTAssertEqual( - typeAssigner.typeName(for: JSONReference.component(named: "mumble")), + typeAssigner.typeName(for: OpenAPI.Reference.component(named: "mumble")), newTypeName( swiftFQName: "Components.Responses.mumble", jsonFQName: "#/components/responses/mumble" diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeMatcher.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeMatcher.swift index ac4008e0..9791b8c9 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeMatcher.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeMatcher.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore final class Test_TypeMatcher: Test_Core { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_isSchemaSupported.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_isSchemaSupported.swift index b567aceb..15e9450f 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_isSchemaSupported.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_isSchemaSupported.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit @testable import _OpenAPIGeneratorCore class Test_isSchemaSupported: XCTestCase { diff --git a/Tests/OpenAPIGeneratorCoreTests/Translator/TypesTranslator/Test_translateSchemas.swift b/Tests/OpenAPIGeneratorCoreTests/Translator/TypesTranslator/Test_translateSchemas.swift index c39329f2..a1808b61 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Translator/TypesTranslator/Test_translateSchemas.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Translator/TypesTranslator/Test_translateSchemas.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit import Yams @testable import _OpenAPIGeneratorCore diff --git a/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift b/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift index 40e7ebb2..15041edf 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// import XCTest -import OpenAPIKit30 +import OpenAPIKit import Yams @testable import _OpenAPIGeneratorCore diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml b/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml index b1bd44d1..7086533f 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml @@ -1,4 +1,4 @@ -openapi: "3.0.3" +openapi: "3.1.0" info: version: 1.0.0 title: Petstore diff --git a/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift b/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift index 9c08530b..9edf08e2 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift @@ -11,7 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -import OpenAPIKit30 +import OpenAPIKit import XCTest import Yams @testable import _OpenAPIGeneratorCore @@ -1561,7 +1561,7 @@ extension SnippetBasedReferenceTests { } ?? OpenAPI.Components.noComponents let paths = try YAMLDecoder().decode(OpenAPI.PathItem.Map.self, from: pathsYAML) let document = OpenAPI.Document( - openAPIVersion: .v3_0_3, + openAPIVersion: .v3_1_0, info: .init(title: "Test", version: "1.0.0"), servers: [], paths: paths, From c7229971528f38dbc78cf63fc2e81d53907bf9b4 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Sat, 26 Aug 2023 10:34:30 +0200 Subject: [PATCH 2/3] Update docs --- IntegrationTest/Sources/openapi.yaml | 2 +- README.md | 6 ++++-- .../Articles/Supported-OpenAPI-features.md | 6 +++--- .../Documentation.docc/Swift-OpenAPI-Generator.md | 8 ++++++-- .../Documentation.docc/Tutorials/ExploreOpenAPI.tutorial | 2 +- .../Tutorials/_Resources/client.openapi.2.yaml | 2 +- .../Tutorials/_Resources/client.openapi.yaml | 2 +- .../Tutorials/_Resources/exploring-openapi.openapi.0.yaml | 2 +- .../Tutorials/_Resources/exploring-openapi.openapi.1.yaml | 2 +- .../Tutorials/_Resources/exploring-openapi.openapi.2.yaml | 2 +- .../Tutorials/_Resources/exploring-openapi.openapi.3.yaml | 2 +- .../Tutorials/_Resources/exploring-openapi.openapi.4.yaml | 2 +- .../Tutorials/_Resources/exploring-openapi.openapi.5.yaml | 2 +- .../Tutorials/_Resources/exploring-openapi.openapi.6.yaml | 2 +- .../Tutorials/_Resources/exploring-openapi.openapi.7.yaml | 2 +- .../Tutorials/_Resources/server.openapi.0.yaml | 2 +- .../Tutorials/_Resources/server.openapi.1.yaml | 2 +- .../Parser/Test_YamsParser.swift | 8 ++++---- 18 files changed, 31 insertions(+), 25 deletions(-) diff --git a/IntegrationTest/Sources/openapi.yaml b/IntegrationTest/Sources/openapi.yaml index 3f84c176..b42b0335 100644 --- a/IntegrationTest/Sources/openapi.yaml +++ b/IntegrationTest/Sources/openapi.yaml @@ -1,4 +1,4 @@ -openapi: "3.0.3" +openapi: "3.1.0" info: title: "GreetingService" version: "1.0.0" diff --git a/README.md b/README.md index 294ea29c..ecb897b6 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,10 @@ Choose one of the transports listed below, or create your own by adopting the `C ## Requirements and supported features -- Swift 5.8 -- OpenAPI 3.0.x +| Generator versions | Supported OpenAPI versions | Minimum Swift version | +| -------- | ------- | ----- | +| `0.1.0` ... `0.1.11` | 3.0 | 5.8 | +| `0.1.12` ... `main` | 3.0, 3.1 | 5.8 | ### Supported platforms and minimum versions diff --git a/Sources/swift-openapi-generator/Documentation.docc/Articles/Supported-OpenAPI-features.md b/Sources/swift-openapi-generator/Documentation.docc/Articles/Supported-OpenAPI-features.md index dd36cd19..b96caa26 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Articles/Supported-OpenAPI-features.md +++ b/Sources/swift-openapi-generator/Documentation.docc/Articles/Supported-OpenAPI-features.md @@ -4,9 +4,9 @@ Learn which OpenAPI features are supported by Swift OpenAPI Generator. ## Overview -Swift OpenAPI Generator is currently focused on supporting [OpenAPI 3.0.3][0]. +Swift OpenAPI Generator is currently focused on supporting [OpenAPI 3.0.3][0] and [OpenAPI 3.1.0][1]. -As the project evolves, support may be added [OpenAPI 3.1.0][1]. +> Note: Internally, documents are converted from 3.0.3 to 3.1.0 to allow the generator to only work with a single set of parsed OpenAPI types. Supported features are always provided on _both_ client and server. @@ -155,7 +155,7 @@ Supported features are always provided on _both_ client and server. - [x] description - [x] format - [ ] default -- [ ] nullable +- [ ] nullable (only in 3.0, removed in 3.1) - [x] discriminator - [ ] readOnly - [ ] writeOnly diff --git a/Sources/swift-openapi-generator/Documentation.docc/Swift-OpenAPI-Generator.md b/Sources/swift-openapi-generator/Documentation.docc/Swift-OpenAPI-Generator.md index b30a00e1..bfa9d757 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Swift-OpenAPI-Generator.md +++ b/Sources/swift-openapi-generator/Documentation.docc/Swift-OpenAPI-Generator.md @@ -41,8 +41,12 @@ Choose one of the transports listed below, or create your own by adopting the `C ### Requirements and supported features -- Swift 5.8 -- OpenAPI 3.0.x (for details, see ) +| Generator versions | Supported OpenAPI versions | Minimum Swift version | +| -------- | ------- | ----- | +| `0.1.0` ... `0.1.11` | 3.0 | 5.8 | +| `0.1.12` ... `main` | 3.0, 3.1 | 5.8 | + +See also . ### Supported platforms and minimum versions diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ExploreOpenAPI.tutorial b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ExploreOpenAPI.tutorial index 27a41e8a..ac2727de 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ExploreOpenAPI.tutorial +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/ExploreOpenAPI.tutorial @@ -16,7 +16,7 @@ @Steps { @Step { - Every OpenAPI document needs to declare its format version using the `openapi` key. Use the version `3.0.3` for this document. + Every OpenAPI document needs to declare its format version using the `openapi` key. Use the version `3.1.0` for this document. @Code(name: "openapi.yaml", file: exploring-openapi.openapi.0.yaml, reset: true) } @Step { diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.2.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.2.yaml index 90faf151..4408f4b1 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.2.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.2.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.yaml index fd9c7b48..c1e493c0 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/client.openapi.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.0.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.0.yaml index 457e12a1..57ada4ae 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.0.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.0.yaml @@ -1 +1 @@ -openapi: '3.0.3' +openapi: '3.1.0' diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.1.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.1.yaml index 9b858484..7993c1ac 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.1.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.1.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.2.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.2.yaml index 371ac107..052ca016 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.2.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.2.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.3.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.3.yaml index 1c422add..c0a17681 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.3.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.3.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.4.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.4.yaml index e4ac5393..e25c80f2 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.4.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.4.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.5.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.5.yaml index 8053dca9..d830252c 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.5.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.5.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.6.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.6.yaml index fd9c7b48..c1e493c0 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.6.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.6.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.7.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.7.yaml index fd9c7b48..c1e493c0 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.7.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/exploring-openapi.openapi.7.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.0.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.0.yaml index fd9c7b48..c1e493c0 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.0.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.0.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.1.yaml b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.1.yaml index a4ddcab0..6490845b 100644 --- a/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.1.yaml +++ b/Sources/swift-openapi-generator/Documentation.docc/Tutorials/_Resources/server.openapi.1.yaml @@ -1,4 +1,4 @@ -openapi: '3.0.3' +openapi: '3.1.0' info: title: GreetingService version: 1.0.0 diff --git a/Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift b/Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift index 121f2f16..9b7d5901 100644 --- a/Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift +++ b/Tests/OpenAPIGeneratorCoreTests/Parser/Test_YamsParser.swift @@ -61,7 +61,7 @@ final class Test_YamsParser: Test_Core { func testEmitsYamsParsingError() throws { // The `title: "Test"` line is indented the wrong amount to make the YAML invalid for the parser let yaml = """ - openapi: "3.0.0" + openapi: "3.1.0" info: title: "Test" version: 1.0.0 @@ -76,7 +76,7 @@ final class Test_YamsParser: Test_Core { func testEmitsYamsScanningError() throws { // The `version:"1.0.0"` line is missing a space after the colon to make it invalid YAML for the scanner let yaml = """ - openapi: "3.0.0" + openapi: "3.1.0" info: title: "Test" version:"1.0.0" @@ -91,7 +91,7 @@ final class Test_YamsParser: Test_Core { func testEmitsMissingInfoKeyOpenAPIParsingError() throws { // The `smurf` line should be `info` in a real OpenAPI document. let yaml = """ - openapi: "3.0.0" + openapi: "3.1.0" smurf: title: "Test" version: "1.0.0" @@ -106,7 +106,7 @@ final class Test_YamsParser: Test_Core { func testEmitsComplexOpenAPIParsingError() throws { // The `resonance` line should be `response` in a real OpenAPI document. let yaml = """ - openapi: "3.0.0" + openapi: "3.1.0" info: title: "Test" version: "1.0.0" From e669276c2ca1db217da24de38b2f0f098459cb1b Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Sun, 27 Aug 2023 09:19:26 +0200 Subject: [PATCH 3/3] Also verify that the allOf workaround isn't necessary in 3.1 anymore, and properties can now be documented --- Package.swift | 2 +- .../Resources/Docs/petstore.yaml | 3 +-- .../ReferenceSources/Petstore/Types.swift | 20 ++----------------- .../Types.swift | 20 ++----------------- 4 files changed, 6 insertions(+), 39 deletions(-) diff --git a/Package.swift b/Package.swift index 91c9a046..ca35c463 100644 --- a/Package.swift +++ b/Package.swift @@ -64,7 +64,7 @@ let package = Package( // Read OpenAPI documents .package( url: "https://github.com/mattpolzin/OpenAPIKit.git", - exact: "3.0.0-beta.1" + exact: "3.0.0-beta.2" ), .package( url: "https://github.com/jpsim/Yams.git", diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml b/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml index 7086533f..1dcdcbc6 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml @@ -297,9 +297,8 @@ components: me$sage: type: string extraInfo: + $ref: '#/components/schemas/ExtraInfo' description: Extra information about the error. - allOf: - - $ref: '#/components/schemas/ExtraInfo' userData: description: Custom user-provided key-value pairs. type: object diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift index a977e24b..a4a2d4b3 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift @@ -176,23 +176,7 @@ public enum Components { /// Extra information about the error. /// /// - Remark: Generated from `#/components/schemas/Error/extraInfo`. - public struct extraInfoPayload: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/Error/extraInfo/value1`. - public var value1: Components.Schemas.ExtraInfo - /// Creates a new `extraInfoPayload`. - /// - /// - Parameters: - /// - value1: - public init(value1: Components.Schemas.ExtraInfo) { self.value1 = value1 } - public init(from decoder: any Decoder) throws { value1 = try .init(from: decoder) } - public func encode(to encoder: any Encoder) throws { - try value1.encode(to: encoder) - } - } - /// Extra information about the error. - /// - /// - Remark: Generated from `#/components/schemas/Error/extraInfo`. - public var extraInfo: Components.Schemas._Error.extraInfoPayload? + public var extraInfo: Components.Schemas.ExtraInfo? /// Custom user-provided key-value pairs. /// /// - Remark: Generated from `#/components/schemas/Error/userData`. @@ -207,7 +191,7 @@ public enum Components { public init( code: Swift.Int32, me_sage: Swift.String, - extraInfo: Components.Schemas._Error.extraInfoPayload? = nil, + extraInfo: Components.Schemas.ExtraInfo? = nil, userData: OpenAPIRuntime.OpenAPIObjectContainer? = nil ) { self.code = code diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore_FF_MultipleContentTypes/Types.swift b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore_FF_MultipleContentTypes/Types.swift index bcb17a21..60b6237f 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore_FF_MultipleContentTypes/Types.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore_FF_MultipleContentTypes/Types.swift @@ -149,23 +149,7 @@ public enum Components { /// Extra information about the error. /// /// - Remark: Generated from `#/components/schemas/Error/extraInfo`. - public struct extraInfoPayload: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/Error/extraInfo/value1`. - public var value1: Components.Schemas.ExtraInfo - /// Creates a new `extraInfoPayload`. - /// - /// - Parameters: - /// - value1: - public init(value1: Components.Schemas.ExtraInfo) { self.value1 = value1 } - public init(from decoder: any Decoder) throws { value1 = try .init(from: decoder) } - public func encode(to encoder: any Encoder) throws { - try value1.encode(to: encoder) - } - } - /// Extra information about the error. - /// - /// - Remark: Generated from `#/components/schemas/Error/extraInfo`. - public var extraInfo: Components.Schemas._Error.extraInfoPayload? + public var extraInfo: Components.Schemas.ExtraInfo? /// Custom user-provided key-value pairs. /// /// - Remark: Generated from `#/components/schemas/Error/userData`. @@ -180,7 +164,7 @@ public enum Components { public init( code: Swift.Int32, me_dollar_sage: Swift.String, - extraInfo: Components.Schemas._Error.extraInfoPayload? = nil, + extraInfo: Components.Schemas.ExtraInfo? = nil, userData: OpenAPIRuntime.OpenAPIObjectContainer? = nil ) { self.code = code