repo_name stringlengths 1 62 | dataset stringclasses 1
value | lang stringclasses 11
values | pr_id int64 1 20.1k | owner stringlengths 2 34 | reviewer stringlengths 2 39 | diff_hunk stringlengths 15 262k | code_review_comment stringlengths 1 99.6k |
|---|---|---|---|---|---|---|---|
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,160 @@
+# SOAR-0013: Optimistic naming strategy
+
+Introduce an alternative naming strategy for more idiomatic Swift identifiers, including a way to provide custom name overrides.
+
+## Overview
+
+- Proposal: SOAR-0013
+- Author(s): [Honza Dvorsky](https://github.com/czechboy0), [Si Beaumont](https://github... | Suggestion: move this up to the constraints we found (the sentence that begins with "The root cause...") |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,160 @@
+# SOAR-0013: Optimistic naming strategy
+
+Introduce an alternative naming strategy for more idiomatic Swift identifiers, including a way to provide custom name overrides.
+
+## Overview
+
+- Proposal: SOAR-0013
+- Author(s): [Honza Dvorsky](https://github.com/czechboy0), [Si Beaumont](https://github... | Suggest we can remove this. It's already called out in alternatives section. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,160 @@
+# SOAR-0013: Optimistic naming strategy
+
+Introduce an alternative naming strategy for more idiomatic Swift identifiers, including a way to provide custom name overrides.
+
+## Overview
+
+- Proposal: SOAR-0013
+- Author(s): [Honza Dvorsky](https://github.com/czechboy0), [Si Beaumont](https://github... | Naming bikeshed: I don't mind the terms `defensive` and `optimistic`, but should we make these terms symmetric?
E.g. `pessimistic` and `optimistic`? (Clearly `offensive` as a converse of `defensive` is bad).
Another idea: `defensive` and `idiomatic`. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,160 @@
+# SOAR-0013: Optimistic naming strategy
+
+Introduce an alternative naming strategy for more idiomatic Swift identifiers, including a way to provide custom name overrides.
+
+## Overview
+
+- Proposal: SOAR-0013
+- Author(s): [Honza Dvorsky](https://github.com/czechboy0), [Si Beaumont](https://github... | If we move this down below the paragraph that introduces the naming overrides it allows us to provide more guidance. If you want to use it and it doesn't produce compiling code for a given OpenAPI document then you have two choices: (1) if the number of offending identifiers is small, you can use the naming overrides; ... |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,160 @@
+# SOAR-0013: Optimistic naming strategy
+
+Introduce an alternative naming strategy for more idiomatic Swift identifiers, including a way to provide custom name overrides.
+
+## Overview
+
+- Proposal: SOAR-0013
+- Author(s): [Honza Dvorsky](https://github.com/czechboy0), [Si Beaumont](https://github... | Aside: do we think this ever should become the default, e.g. if we were to cut a new major? IMO, no, but I'm curious what you think? |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,160 @@
+# SOAR-0013: Optimistic naming strategy
+
+Introduce an alternative naming strategy for more idiomatic Swift identifiers, including a way to provide custom name overrides.
+
+## Overview
+
+- Proposal: SOAR-0013
+- Author(s): [Honza Dvorsky](https://github.com/czechboy0), [Si Beaumont](https://github... | Suggest we just state the facts here. E.g. let's say that this resolved all the compilation issues with our corpus of NNN OpenAPI documents, but we don't need to make a statement about whether we believe or not it was the right call. I believe it was; others might not and we don't want distract from the proposal itself... |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,160 @@
+# SOAR-0013: Optimistic naming strategy
+
+Introduce an alternative naming strategy for more idiomatic Swift identifiers, including a way to provide custom name overrides.
+
+## Overview
+
+- Proposal: SOAR-0013
+- Author(s): [Honza Dvorsky](https://github.com/czechboy0), [Si Beaumont](https://github... | Suggest we move this down to after explaining what it does and we can talk about the outcome there (see the other comment too below about how we position the outcome). |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -12,6 +12,24 @@
//
//===----------------------------------------------------------------------===//
+/// A strategy for turning OpenAPI identifiers into Swift identifiers.
+public enum NamingStrategy: String, Sendable, Codable, Equatable {
+
+ /// A defensive strategy that can handle any OpenAPI identifier an... | ```suggestion
```
I don't think this is the right place to document this. We have it in the correct place already, which is the docs on the `Config` object. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -12,6 +12,24 @@
//
//===----------------------------------------------------------------------===//
+/// A strategy for turning OpenAPI identifiers into Swift identifiers.
+public enum NamingStrategy: String, Sendable, Codable, Equatable {
+
+ /// A defensive strategy that can handle any OpenAPI identifier an... | ```suggestion
``` |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -35,6 +53,14 @@ public struct Config: Sendable {
/// Filter to apply to the OpenAPI document before generation.
public var filter: DocumentFilter?
+ /// The naming strategy to use for deriving Swift identifiers from OpenAPI identifiers.
+ ///
+ /// Defaults to `defensive`.
+ public var naming... | This layer should have a non-optional value, with a default. The optionality will be in `GenerateOptions`, used in the CLI. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -13,6 +13,32 @@
//===----------------------------------------------------------------------===//
import Foundation
+/// Extra context for the `safeForSwiftCode_` family of functions to produce more appropriate Swift identifiers.
+struct SwiftNameOptions {
+
+ /// An option for controlling capitalization.
+ ... | An enum with a "this" and "not this" case sounds like it should be replaced with boolean. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -67,6 +93,178 @@ extension String {
return "_\(validString)"
}
+ /// Returns a string sanitized to be usable as a Swift identifier, and tries to produce UpperCamelCase
+ /// or lowerCamelCase string, the casing is controlled using the provided options.
+ ///
+ /// If the string contains a... | Note to self, check tests for this.
We're three conditionals (four including the switch), wondering if we can flatten this out with a more expressive switch statement with multiple terms or some `case ... where` statements. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -67,6 +93,178 @@ extension String {
return "_\(validString)"
}
+ /// Returns a string sanitized to be usable as a Swift identifier, and tries to produce UpperCamelCase
+ /// or lowerCamelCase string, the casing is controlled using the provided options.
+ ///
+ /// If the string contains a... | Note to self: any uses of `.` in this position that would be a problem? |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -67,6 +93,178 @@ extension String {
return "_\(validString)"
}
+ /// Returns a string sanitized to be usable as a Swift identifier, and tries to produce UpperCamelCase
+ /// or lowerCamelCase string, the casing is controlled using the provided options.
+ ///
+ /// If the string contains a... | I thought we said we'd always flush the result of the idiomatic strategy through the defensive strategy too. That way it's a two phase process: try to make it pretty, then make it safe. If the first phase made it pretty in a way that was safe, then the second results in the same, but we have a lot of confidence in the ... |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -35,6 +53,14 @@ public struct Config: Sendable {
/// Filter to apply to the OpenAPI document before generation.
public var filter: DocumentFilter?
+ /// The naming strategy to use for deriving Swift identifiers from OpenAPI identifiers.
+ ///
+ /// Defaults to `defensive`.
+ public var naming... | I think we should have resolved this to an actual, possibly empty, dictionary by this point, which will mean we're not doing so for every call to `asSwiftSafeName`. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -47,7 +47,18 @@ protocol FileTranslator {
extension FileTranslator {
/// A new context from the file translator.
- var context: TranslatorContext { TranslatorContext(asSwiftSafeName: { $0.safeForSwiftCode }) }
+ var context: TranslatorContext {
+ let asSwiftSafeName: (String, SwiftNameOptions) -... | If this were resolved in the config (see comment in Config.swift), then we won't have to do this on every call. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -495,7 +495,8 @@ struct TypeAssigner {
{
typeNameForComponents()
.appending(
- swiftComponent: context.asSwiftSafeName(componentType.openAPIComponentsKey).uppercasingFirstLetter,
+ swiftComponent: context.asSwiftSafeName(componentType.openAPIComponentsKey, .ca... | Why do we need `.uppercasingFirstLetter` still? Is this for when we're still using `defensive`?
And, is this what's returning `Components`? If so, should it be simplified to just do that? |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -528,14 +529,15 @@ struct TypeAssigner {
case "application/pdf": return "pdf"
case "image/jpeg": return "jpeg"
default:
- let safedType = context.asSwiftSafeName(contentType.originallyCasedType)
- let safedSubtype = context.asSwiftSafeName(contentType.originallyCasedS... | This looks like it's still returning `type_subtype`. Should it be `typeSubtype`? |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -35,11 +35,15 @@ The configuration file has the following keys:
- `package`: Generated API is accessible from other modules within the same package or project.
- `internal` (default): Generated API is accessible from the containing module only.
- `additionalImports` (optional): array of strings. Each stri... | ```suggestion
- `namingStrategy` (optional): a string. The strategy of converting OpenAPI identifiers into Swift identifiers.
```
The "customization" happens with `nameOverrides`. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -35,11 +35,15 @@ The configuration file has the following keys:
- `package`: Generated API is accessible from other modules within the same package or project.
- `internal` (default): Generated API is accessible from the containing module only.
- `additionalImports` (optional): array of strings. Each stri... | ```suggestion
- `idiomatic`: Produces more idiomatic Swift identifiers for OpenAPI identifiers. Might produce name conflicts (in that case, switch back to `defensive`). Check out [SOAR-0013](https://swiftpackageindex.com/apple/swift-openapi-generator/documentation/swift-openapi-generator/soar-0013) for details.
`... |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -1,4 +1,4 @@
-// swift-tools-version: 5.9
+// swift-tools-version: 6.0 | Is this deliberate? It means that only folks on the latest Swift compiler can walk through the tutorial. Seems an unrelated, additional restriction. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -1,3 +1,4 @@
generate:
- types
- client
+namingStrategy: idiomatic | While I'm open to us having a specific example showing the idiomatic naming, I'm a little wary of us having non-defaults in our main tutorial. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -81,13 +81,15 @@ private func timing<Output>(_ title: String, _ operation: @autoclosure () throws
}
private let sampleConfig = _UserConfig(
- generate: [],
+ generate: [.types, .client],
filter: DocumentFilter(
operations: ["getGreeting"],
tags: ["greetings"],
paths: ["/gree... | Why is this in the example config for the `filter` command? |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -83,6 +75,8 @@ extension _GenerateOptions {
return []
}
+ func resolvedNamingStrategy(_ config: _UserConfig?) -> NamingStrategy { config?.namingStrategy ?? .defensive }
+ func resolvedNameOverrides(_ config: _UserConfig?) -> [String: String] { config?.nameOverrides ?? [:] } | This is great. I think these should be passed in where we turn the config into a proper `Config`. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,148 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache License v2.0
+//
+// See LIC... | Please add a case for all uppercase, without any word separator. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -0,0 +1,148 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache License v2.0
+//
+// See LIC... | To show it's preserving _only_ leading underscores, this test should have both leading and non-leading underscores. |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -531,19 +531,33 @@ struct TypeAssigner {
default:
let safedType = context.asSwiftSafeName(contentType.originallyCasedType, .noncapitalized)
let safedSubtype = context.asSwiftSafeName(contentType.originallyCasedSubtype, .noncapitalized)
- let prefix = "\(safedType)_\(safe... | Seeing this here is giving me pause for concern. We're having one object, the `TypeAssigner` that holds a context containing a _strategy_ (essentially a config option), and then it's either branching in the function (like this one) or it's calling a closure with different arguments (in others).
The `TypeAssigner` se... |
swift-openapi-generator | github_2023 | others | 679 | apple | simonjbeaumont | @@ -44,35 +44,50 @@ protocol FileTranslator {
func translateFile(parsedOpenAPI: ParsedOpenAPIRepresentation) throws -> StructuredSwiftRepresentation
}
+/// A generator that allows overriding the documented name.
+struct OverridableSafeNameGenerator: SafeNameGenerator { | This is a really nice win. I hadn't yet thought of layering it this way but it composes nicely :) |
swift-openapi-generator | github_2023 | others | 697 | apple | czechboy0 | @@ -37,7 +37,7 @@ enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
let targetNames = targetNames.joined(separator: ", ", lastSeparator: " and ")
return "Found no targets with names \(targetNames)."
case .fileErrors(let fileErrors):
- return "Issues w... | ```suggestion
return "Issues with required files:\n\(fileErrors.map { "- " + $0.description }.joined(separator: "\n"))."
``` |
swift-openapi-generator | github_2023 | others | 697 | apple | czechboy0 | @@ -37,7 +37,7 @@ enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
let targetNames = targetNames.joined(separator: ", ", lastSeparator: " and ")
return "Found no targets with names \(targetNames)."
case .fileErrors(let fileErrors):
- return "Issues w... | ```suggestion
return "Issues with required files:\n\(fileErrors.map { "- " + $0.description }.joined(separator: "\n"))."
```
Nit: extra space after `$0` |
swift-openapi-generator | github_2023 | others | 642 | apple | czechboy0 | @@ -107,6 +107,9 @@ The generated code, runtime library, and transports are supported on more platfo
| Generator plugin and CLI | ✅ 10.15+ | ✅ | ✖️ | ✖️ | ✖️ | ✖️ |
| Generated code and runtime library | ✅ 10.15+ | ✅ | ✅ 13+ | ✅ 13+ | ✅ 6+ | ✅ 1+ |
+> [!NOTE]
+> When us... | The syntax in docc for notes is `> Note: ...` |
swift-openapi-generator | github_2023 | others | 626 | apple | czechboy0 | @@ -0,0 +1,151 @@
+# SOAR-0011: Improved Error Handling
+
+Improve error handling by adding the ability for mapping application errors to HTTP responses.
+
+## Overview
+
+- Proposal: SOAR-0011
+- Author(s): [Gayathri Sairamkrishnan](https://github.com/gayathrisairam)
+- Status: **Awaiting Review**
+- Issue: [apple/swi... | ```suggestion
When implementing a server with Swift OpenAPI Generator, users implement a type that conforms to a generated protocol, providing one method for each API operation defined in the OpenAPI document. At runtime, if this function throws, it's up to the server transport to transform it into an HTTP response s... |
swift-openapi-generator | github_2023 | others | 626 | apple | czechboy0 | @@ -0,0 +1,151 @@
+# SOAR-0011: Improved Error Handling
+
+Improve error handling by adding the ability for mapping application errors to HTTP responses.
+
+## Overview
+
+- Proposal: SOAR-0011
+- Author(s): [Gayathri Sairamkrishnan](https://github.com/gayathrisairam)
+- Status: **Awaiting Review**
+- Issue: [apple/swi... | This needs to be a case from the `Operations.getGreeting.Output`, so e.g. `.notFound(.init())` here? Or since this is `GreetingError.authorizationError`, maybe using `.unauthorized(.init())` is more illustrative? |
swift-openapi-generator | github_2023 | others | 626 | apple | czechboy0 | @@ -0,0 +1,151 @@
+# SOAR-0011: Improved Error Handling
+
+Improve error handling by adding the ability for mapping application errors to HTTP responses.
+
+## Overview
+
+- Proposal: SOAR-0011
+- Author(s): [Gayathri Sairamkrishnan](https://github.com/gayathrisairam)
+- Status: **Awaiting Review**
+- Issue: [apple/swi... | ```suggestion
Hummingbird also has an [error handling mechanism](https://docs.hummingbird.codes/2.0/documentation/hummingbird/errorhandling/)
``` |
swift-openapi-generator | github_2023 | others | 626 | apple | czechboy0 | @@ -0,0 +1,151 @@
+# SOAR-0011: Improved Error Handling
+
+Improve error handling by adding the ability for mapping application errors to HTTP responses.
+
+## Overview
+
+- Proposal: SOAR-0011
+- Author(s): [Gayathri Sairamkrishnan](https://github.com/gayathrisairam)
+- Status: **Awaiting Review**
+- Issue: [apple/swi... | Nit: for clarity, we can shorten this
```suggestion
.badRequest
case .authorizationError:
.forbidden
``` |
swift-openapi-generator | github_2023 | others | 626 | apple | czechboy0 | @@ -0,0 +1,151 @@
+# SOAR-0011: Improved Error Handling
+
+Improve error handling by adding the ability for mapping application errors to HTTP responses.
+
+## Overview
+
+- Proposal: SOAR-0011
+- Author(s): [Gayathri Sairamkrishnan](https://github.com/gayathrisairam)
+- Status: **Awaiting Review**
+- Issue: [apple/swi... | Nit: you're using the name `ErrorMiddleware` earlier, and `ErrorHandlingMiddleware` here. While the name itself will be discussed as part of the review, it might make sense to make them consistent to avoid confusion of whether the names will or will not be the same. |
swift-openapi-generator | github_2023 | others | 626 | apple | czechboy0 | @@ -0,0 +1,151 @@
+# SOAR-0011: Improved Error Handling
+
+Improve error handling by adding the ability for mapping application errors to HTTP responses.
+
+## Overview
+
+- Proposal: SOAR-0011
+- Author(s): [Gayathri Sairamkrishnan](https://github.com/gayathrisairam)
+- Status: **Awaiting Review** | ```suggestion
- Status: **In Review**
``` |
swift-openapi-generator | github_2023 | others | 626 | apple | czechboy0 | @@ -0,0 +1,159 @@
+# SOAR-0011: Improved Error Handling
+
+Improve error handling by adding the ability for mapping application errors to HTTP responses.
+
+## Overview
+
+- Proposal: SOAR-0011
+- Author(s): [Gayathri Sairamkrishnan](https://github.com/gayathrisairam)
+- Status: **In Review** | ```suggestion
- Status: **Ready for Implementation**
``` |
swift-openapi-generator | github_2023 | others | 626 | apple | czechboy0 | @@ -0,0 +1,159 @@
+# SOAR-0011: Improved Error Handling
+
+Improve error handling by adding the ability for mapping application errors to HTTP responses.
+
+## Overview
+
+- Proposal: SOAR-0011
+- Author(s): [Gayathri Sairamkrishnan](https://github.com/gayathrisairam)
+- Status: **Ready for Implementation** | ```suggestion
- Status: **Implemented**
``` |
swift-openapi-generator | github_2023 | others | 674 | apple | simonjbeaumont | @@ -42,32 +59,48 @@ extension FileTranslator {
isNullable: Bool,
allowedValues: [AnyCodable]
) throws -> Declaration {
- let cases: [(String, LiteralDescription)] = try allowedValues.map(\.value)
- .map { anyValue in
- switch backingType {
- case .s... | This maybe-add-to-dictionary flow, that maintains a set seems unnecessarily complex.
We already had an array of key-value pairs, which we can then just pass to `Dictionary.init(_:uniquingKeysWith:)`:
```swift
let dict = Dictionary(cases, uniquingKeysWith: { first, _ in
// emit diagnostic
... |
swift-openapi-generator | github_2023 | others | 674 | apple | simonjbeaumont | @@ -23,6 +23,23 @@ enum RawEnumBackingType {
case integer
}
+/// The extracted enum value.
+private enum EnumValue: Hashable, CustomStringConvertible {
+
+ /// A string value.
+ case string(String)
+
+ /// An integer value.
+ case integer(Int)
+
+ var description: String {
+ switch self {
... | Is `description` the right thing to use to generate the representation we need to be safe in generated code? Should we promote this to a more formally named computed property? |
swift-openapi-generator | github_2023 | others | 656 | apple | czechboy0 | @@ -55,14 +56,34 @@ extension TypesFileTranslator {
}
associatedValues.append(.init(type: .init(responseStructTypeName)))
- let enumCaseDesc = EnumCaseDescription(name: enumCaseName, kind: .nameWithAssociatedValues(associatedValues))
- let enumCaseDecl: Declaration = .commentable(
- ... | ```suggestion
let staticMemberDecl: Declaration?
let responseHasNoHeaders = typedResponse.response.headers?.isEmpty ?? true
let responseHasNoContent = typedResponse.response.content.isEmpty
if responseHasNoContent && responseHasNoHeaders && !responseKind.wantsStatusCode {
... |
swift-openapi-generator | github_2023 | others | 653 | apple | simonjbeaumont | @@ -74,13 +74,13 @@ For details, check out <doc:Configuring-the-generator>.
### How do I enable the build plugin in Xcode and Xcode Cloud?
-By default, build plugins must be explicitly enabled by the adopter.
+By default, you must explicitly enable build plugins before they are allowed to run.
-In Xcode, the fir... | ```suggestion
Before a plugin is enabled, you will encounter a build error with the message `"OpenAPIGenerator" is disabled`.
``` |
swift-openapi-generator | github_2023 | others | 652 | apple | czechboy0 | @@ -9,23 +9,16 @@ jobs:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
- api_breakage_check_enabled: false | I think we want to keep `api_breakage_check_enabled: false`? We recently disabled it, as we don't have any public API from this package, only plugins and executables, and the one library here is explicitly _not_ stable. |
swift-openapi-generator | github_2023 | others | 629 | apple | czechboy0 | @@ -0,0 +1,374 @@
+# SOAR-0012: Generate enums for server variables
+
+Introduce generator logic to generate Swift enums for server variables that define the 'enum' field.
+
+## Overview
+
+- Proposal: SOAR-NNNN | ```suggestion
- Proposal: SOAR-0012
``` |
swift-openapi-generator | github_2023 | others | 629 | apple | czechboy0 | @@ -0,0 +1,374 @@
+# SOAR-0012: Generate enums for server variables
+
+Introduce generator logic to generate Swift enums for server variables that define the 'enum' field.
+
+## Overview
+
+- Proposal: SOAR-NNNN
+- Author(s): [Joshua Asbury](https://github.com/theoriginalbit)
+- Status: **Awaiting Review**
+- Issue: [a... | ```suggestion
```
You mention the possibility to clean this up in the runtime library later in the proposal, but since we can't do this in v1 (it'd be a breaking change), I think we can just remove it from here. |
swift-openapi-generator | github_2023 | others | 629 | apple | czechboy0 | @@ -0,0 +1,374 @@
+# SOAR-0012: Generate enums for server variables
+
+Introduce generator logic to generate Swift enums for server variables that define the 'enum' field.
+
+## Overview
+
+- Proposal: SOAR-NNNN
+- Author(s): [Joshua Asbury](https://github.com/theoriginalbit)
+- Status: **Awaiting Review** | ```suggestion
- Status: **In Review**
``` |
swift-openapi-generator | github_2023 | others | 629 | apple | czechboy0 | @@ -0,0 +1,428 @@
+# SOAR-0012: Generate enums for server variables
+
+Introduce generator logic to generate Swift enums for server variables that define the 'enum' field.
+
+## Overview
+
+- Proposal: SOAR-0012
+- Author(s): [Joshua Asbury](https://github.com/theoriginalbit)
+- Status: **Ready for Implementation** | ```suggestion
- Status: **Implemented (1.4.0)**
```
This will go out with the next minor. |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -28,6 +28,10 @@
public enum FeatureFlag: String, Hashable, Codable, CaseIterable, Sendable {
// needs to be here for the enum to compile
case empty
+
+ /// When enabled any server URL templating variables that have a defined
+ /// enum field will be generated as an enum instead of raw Strings.
+ ... | ```suggestion
case serverVariablesAsEnums
```
In the past, we've just used the names directly, rather than capitalize them. |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -43,6 +43,11 @@ class FileBasedReferenceTests: XCTestCase {
}
func testPetstore() throws { try _test(referenceProject: .init(name: .petstore)) }
+
+ func testPetstoreWithServerVariablesEnumsFeatureFlag() throws { | I appreciate you trying to improve the test coverage here, but we generally avoid duplicating the file-based reference tests for testing relatively self-contained features - as file-based reference tests are _really_ expensive to maintain.
Please remove these, and instead lean on snippet-based reference tests, which... |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -5473,6 +5673,21 @@ extension SnippetBasedReferenceTests {
let (registerHandlersDecl, _) = try translator.translateRegisterHandlers(operations)
try XCTAssertSwiftEquivalent(registerHandlersDecl, expectedSwift, file: file, line: line)
}
+
+ func assertServerTranslation(
+ _ serverYAML... | ```suggestion
func assertServersTranslation(
_ serversYAML: String,
_ expectedSwift: String,
accessModifier: AccessModifier = .public,
featureFlags: FeatureFlags = [],
file: StaticString = #filePath,
line: UInt = #line
) throws {
continueAfterFail... |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -64,15 +36,70 @@ extension TypesFileTranslator {
.call([
.init(
label: "validatingOpenAPIServerURL",
- expression: .literal(.string(server.urlTemplate.absoluteString))... | Could we use the `renamed:` parameter of the deprecation, to allow people to migrate by accepting a Fix-It? |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -154,25 +154,87 @@ extension APIProtocol {
/// Server URLs defined in the OpenAPI document.
public enum Servers {
/// Example Petstore implementation service
+ public enum Server1 {
+ public static func url() throws -> Foundation.URL { | We should also generate a comment on the `url()` static function. Might make sense to simply duplicate the user-provided comment that we already put on the namespace (e.g. above `Server1` here) |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -154,25 +154,87 @@ extension APIProtocol {
/// Server URLs defined in the OpenAPI document.
public enum Servers {
/// Example Petstore implementation service
+ public enum Server1 {
+ public static func url() throws -> Foundation.URL {
+ try Foundation.URL(
+ validatingOpen... | ```suggestion
port: Port = ._443,
```
Can we omit repeating the type, to match what users would type manually? |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -14,47 +14,19 @@
import OpenAPIKit
extension TypesFileTranslator {
-
- /// Returns a declaration of a server URL static method defined in
- /// the OpenAPI document.
- /// - Parameters:
- /// - index: The index of the server in the list of servers defined
- /// in the OpenAPI document.
- //... | Please add a doc comment for this function. |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -0,0 +1,214 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache License v2.0
+//
+// See LIC... | ```suggestion
/// Returns the declaration (enum) that should be added to the `Variables.Server`
``` |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -0,0 +1,214 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache License v2.0
+//
+// See LIC... | Please add doc comments for the properties. |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -0,0 +1,214 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache License v2.0
+//
+// See LIC... | Please add a doc comment for the initializer |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -154,25 +154,89 @@ extension APIProtocol {
/// Server URLs defined in the OpenAPI document.
public enum Servers {
/// Example Petstore implementation service
+ public enum Server1 {
+ /// Example Petstore implementation service
+ public static func url() throws -> Foundation.URL {
+ ... | ```suggestion
@available(*, deprecated, renamed: "Servers.Server1.url()")
```
Should it also contain the `()` or not? Can you check that accepting the Fix-it does the right thing? |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -5181,6 +5181,297 @@ final class SnippetBasedReferenceTests: XCTestCase {
)
}
+ func testServerWithNoVariables() throws {
+ try self.assertServersTranslation(
+ """
+ - url: https://example.com/api
+ """,
+ """
+ public enum Servers {... | Can you also generate the enums as `Sendable`? |
swift-openapi-generator | github_2023 | others | 618 | apple | czechboy0 | @@ -222,14 +222,17 @@ final class Test_Types: XCTestCase {
verifyingJSON: #"{"name":"C","parent":{"nested":{"name":"B","parent":{"nested":{"name":"A"}}}}}"#
)
}
- func testServers_1() throws { XCTAssertEqual(try Servers.server1(), URL(string: "https://example.com/api")) }
- func testSer... | Please just remove the `XCTAssertThrowsError`, we don't want to have that warning in our tests as the goal is to be warning-free and run with warnings-as-errors in CI. The underlying validation is run as part of Swift OpenAPI Runtime tests, so I'm happy for us to drop it here. |
swift-openapi-generator | github_2023 | others | 640 | apple | simonjbeaumont | @@ -69,9 +68,9 @@ struct TypeMatcher {
try Self._tryMatchRecursive(
for: schema.value,
test: { (schema) -> TypeUsage? in
- if let builtinType = Self._tryMatchBuiltinNonRecursive(for: schema) { return builtinType }
+ if let builtinType = _tryMatchBuiltinNo... | Do we need to mint a new `TypeAssigner` on each of these calls? Is this the only place `context` is used? Maybe we're better having the assigner be a stored property instead? WDYT? |
swift-openapi-generator | github_2023 | others | 625 | apple | czechboy0 | @@ -113,6 +113,7 @@ The returned binary body contains the raw events, and the stream can be split up
- encode: `AsyncSequence<some Encodable>.asEncodedJSONSequence(encoder:)`
- Server-sent Events
- decode (if data is JSON): `AsyncSequence<ArraySlice<UInt8>>.asDecodedServerSentEventsWithJSONData(of:decoder:)`... | ```suggestion
- decode (if data is JSON with a non-JSON terminating byte sequence): `AsyncSequence<ArraySlice<UInt8>>.asDecodedServerSentEventsWithJSONData(of:decoder:while:)`
``` |
swift-openapi-generator | github_2023 | others | 625 | apple | czechboy0 | @@ -113,6 +113,7 @@ The returned binary body contains the raw events, and the stream can be split up
- encode: `AsyncSequence<some Encodable>.asEncodedJSONSequence(encoder:)`
- Server-sent Events
- decode (if data is JSON): `AsyncSequence<ArraySlice<UInt8>>.asDecodedServerSentEventsWithJSONData(of:decoder:)`... | ```suggestion
- decode (for other data): `AsyncSequence<ArraySlice<UInt8>>.asDecodedServerSentEvents(while:)`
``` |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,50 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | This wasn't something we had before. Do we want it in all projects? |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,50 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | Starting a thread here to discuss your comment you made at the PR level about the example tests.
The script already uses a shared directory for cache and scratch, which, to be fair, opens it up to not catching a missing dependency in an example that is run later than an earlier one that had it.
You'd be surprised... |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,50 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | We've made no effort to switch to Swift 6 language mode in this project _yet(!)_. Can we have this one be marked as skipped for now? |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,50 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | I think it's fair to leave the `unacceptable_language_check` pipeline disabled because we need to do a hot-swap with the other pipeline.
But for the shellcheck pipeline, what's the issue. I ask because this project already _has_ a shellcheck pipeline, which is passing. So why can't this one be passing? |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,68 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | @czechboy0 @FranzBusch do you think we need to do this for all the Swift versions? |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,71 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | Because it's more visible. The fact that some are default to true and some to false is confusing IMO. I like to be able to see what tests we're running in the YAML. |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,71 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | More than happy to. But that's over-and-above what we currently had in this project. We can track it separately. |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,71 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | Because it's materially slower and not blocking a PR. Note that this PR does use the nightly Swift versions in the scheduled workflow so we'll still be alerted. I'd really like to only have PR pipelines that are gating PR merges, especially when we have external contributors. |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -1,12 +1,71 @@
-name: Pull Request
+name: PR
on:
- pull_request:
- types: [opened, reopened, synchronize, ready_for_review]
-
+ pull_request:
+ types: [opened, reopened, synchronize]
+
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusab... | Answered above. |
swift-openapi-generator | github_2023 | others | 604 | apple | simonjbeaumont | @@ -26,25 +26,25 @@ services:
| I hadn't actually considered removing them altogether but I guess the only downside to doing so is that the existing CI will immediately fail because it can't find them. Maybe that's fine since we want it turned off anyway.
@czechboy0 any objections to me just deleting all the docker-based CI files? |
swift-openapi-generator | github_2023 | others | 607 | apple | czechboy0 | @@ -83,7 +83,7 @@ extension _GenerateOptions {
try finalizeDiagnostics()
} catch let error as Diagnostic {
// Emit our nice Diagnostics message instead of relying on ArgumentParser output.
- diagnostics.emit(error)
+ try ErrorThrowingDiagnosticCollector(upstream:... | We should only create `ErrorThrowingDiagnosticCollector` in one place, not in the translate methods (those will already get a `DiagnosticCollector` value, which will already have this collector).
Just update the block around line 45 to something like:
```swift
let innerDiagnostics: any DiagnosticCollector & Send... |
swift-openapi-generator | github_2023 | others | 607 | apple | czechboy0 | @@ -110,7 +110,9 @@ func makeGeneratorPipeline(
}
let validateDoc = { (doc: OpenAPI.Document) -> OpenAPI.Document in
let validationDiagnostics = try validator(doc, config)
- for diagnostic in validationDiagnostics { diagnostics.emit(diagnostic) }
+ for diagnostic in validationDiagnostic... | The `diagnostics: any DiagnosticCollector` (line 104) should already be a `ErrorThrowingDiagnosticCollector`, so this shouldn't be necessary (see my other comment at the bottom). |
swift-openapi-generator | github_2023 | others | 607 | apple | czechboy0 | @@ -165,7 +165,33 @@ public protocol DiagnosticCollector {
/// Submits a diagnostic to the collector.
/// - Parameter diagnostic: The diagnostic to submit. | Yup these changes look great 🙏 |
swift-openapi-generator | github_2023 | others | 607 | apple | czechboy0 | @@ -42,17 +42,21 @@ extension _GenerateOptions {
featureFlags: resolvedFeatureFlags
)
}
- let diagnostics: any DiagnosticCollector & Sendable
+ let innerDiagnostics: any DiagnosticCollector & Sendable
let finalizeDiagnostics: () throws -> Void
if le... | I was thinking you could move all this logic into the prepare... function, so that it can be called from tests and also from here.
The method would take an optional URL, depending on whether the user provided a diagnostic URL or not. But the whole diagnostics collector construction would happen in that method. |
swift-openapi-generator | github_2023 | others | 607 | apple | czechboy0 | @@ -114,6 +114,14 @@ let package = Package(
swiftSettings: swiftSettings
),
+ // Test Target for swift-openapi-generator
+ .testTarget(
+ name: "OpenAPIGeneratorTests",
+ dependencies: ["swift-openapi-generator"], | You also need to add an explicit dependency on ArgumentParser, the 5.9.0 CI pipeline is failing with:
```
/code/Tests/OpenAPIGeneratorTests/Test_GenerateOptions.swift:39: error: undefined reference to '$s14ArgumentParser17ParsableArgumentsPAAE5parseyxSaySSGSgKFZ'
``` |
swift-openapi-generator | github_2023 | others | 603 | apple | FranzBusch | @@ -5,8 +5,6 @@ on:
types: [opened, reopened, synchronize, ready_for_review]
jobs:
- call-reusable-pull-request-workflow:
- name: Checks
- uses: apple/swift-nio/.github/workflows/reusable_pull_request.yml@main
- with:
- benchmarks_linux_enabled: false
\ No newline at end of file
+ call-pull-req... | ```suggestion
soundness:
``` |
swift-openapi-generator | github_2023 | others | 591 | apple | simonjbeaumont | @@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/bash | This is a script that devs or CI run. For devs, they want their environment to be taken into account. For CI we control the environment.
This can be useful for images that may have a Bash 3 and Bash 4, for example. |
swift-openapi-generator | github_2023 | others | 591 | apple | simonjbeaumont | @@ -9,4 +9,6 @@ jobs:
name: Checks
uses: apple/swift-nio/.github/workflows/reusable_pull_request.yml@main
with:
- benchmarks_linux_enabled: false
\ No newline at end of file
+ benchmarks_linux_enabled: false
+ unacceptable_language_check_enabled: false | Are we doing opt-out? Seems like it might be pretty bad to do that since we'll introduce CI breakages for adopters of the reusable workflow when we add new things that they don't want and/or can't use for some reason. |
swift-openapi-generator | github_2023 | others | 595 | apple | czechboy0 | @@ -645,7 +645,12 @@ struct TextBasedRenderer: RendererProtocol {
/// Renders the specified enum declaration.
func renderEnum(_ enumDesc: EnumDescription) {
- if enumDesc.isFrozen {
+ func shouldAnnotateAsFrozen(_ enumDesc: EnumDescription) -> Bool { | Could you break this method out and add unit tests for it, and update the reference tests as well please? |
swift-openapi-generator | github_2023 | others | 592 | apple | czechboy0 | @@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2024 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache License v2.0
+//
+// See LICE... | 👏 |
swift-openapi-generator | github_2023 | others | 583 | apple | czechboy0 | @@ -0,0 +1,35 @@
+// swift-tools-version:5.9
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2024 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache L... | The package name needs updating. |
swift-openapi-generator | github_2023 | others | 583 | apple | czechboy0 | @@ -0,0 +1,38 @@
+// swift-tools-version:5.9
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2024 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache L... | ```suggestion
``` |
swift-openapi-generator | github_2023 | others | 583 | apple | czechboy0 | @@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the SwiftOpenAPIGenerator open source project
+//
+// Copyright (c) 2024 Apple Inc. and the SwiftOpenAPIGenerator project authors
+// Licensed under Apache License v2.0
+//
+// See LICE... | ```suggestion
``` |
swift-openapi-generator | github_2023 | others | 468 | apple | PeterAdams-A | @@ -1,62 +1,69 @@
# Examples of using Swift OpenAPI Generator
-This directory contains examples of how to use Swift OpenAPI Generator and
-integrate with other packages in the ecosystem.
+This directory contains examples of how to use and
+integrate Swift OpenAPI Generator with other packages in the ecosystem.
-> ... | Feels like it's begging for an "as below" other wise it almost reads as, to run this locally, clone and run it which doesn't sound hugely helpful :-) |
swift-openapi-generator | github_2023 | others | 458 | apple | czechboy0 | @@ -1,4 +1,4 @@
-# Curated Library Client
+# Curated library client module | Have we used the word "module" in any other example? |
swift-openapi-generator | github_2023 | others | 458 | apple | czechboy0 | @@ -1,4 +1,4 @@
-# A command plugin invocation Client
+# Manual code generation using the Swift package plugin | ```suggestion
# Manual code generation using the Swift package command plugin
```
|
swift-openapi-generator | github_2023 | others | 458 | apple | czechboy0 | @@ -1,4 +1,4 @@
-# Swagger UI Endpoints Server
+# Server with Swagger UI Endpoint | ```suggestion
# Server with Swagger UI Endpoints
```
There are 3 endpoints, right? The raw file and the HTML page, plus the redirect. |
swift-openapi-generator | github_2023 | others | 524 | apple | simonjbeaumont | @@ -14,7 +14,7 @@
// Emit a compiler error if this library is linked with a target in an adopter
// project.
-#if !(os(macOS) || os(Linux))
+#if !(os(macOS) || targetEnvironment(macCatalyst) || os(Linux)) | ```suggestion
// When compiling for Mac Catalyst, the plugin is (erroneously?) compiled with os(iOS).
#if !(os(macOS) || os(Linux) || (os(iOS) && targetEnvironment(macCatalyst)))
``` |
swift-openapi-generator | github_2023 | others | 242 | apple | glbrntt | @@ -13,39 +13,66 @@
//===----------------------------------------------------------------------===//
import OpenAPIKit
+/// The backing type of a raw enum.
+enum RawEnumBackingType {
+
+ /// Backed by a `String`.
+ case string
+
+ /// Backed by an `Int`.
+ case integer
+}
+
extension FileTranslator {
... | It feels slightly wrong prefixing the case with an underscore as we typically reserve that for not-actually-public but I don't have a better alternative to suggest. |
swift-openapi-generator | github_2023 | others | 509 | apple | simonjbeaumont | @@ -38,9 +38,7 @@ Another example is the generation of empty structs within the input or output ty
Some generators offer lots of options that affect the code generation process. In order to keep the project streamlined and maintainable, Swift OpenAPI Generator offers very few options.
-One concrete example of this... | Although we _do_ now allow configuration of the access modifier, one salient point above, that has been deleted in this patch, is still very relevant: we do not make any provision for namespace collisions in the target into which the code is generated. The advise of using a dedicated Swift module still applies, no? |
swift-openapi-generator | github_2023 | others | 500 | apple | simonjbeaumont | @@ -115,6 +272,9 @@ func validateDoc(_ doc: ParsedOpenAPIRepresentation, config: Config) throws -> [
(try? _OpenAPIGeneratorCore.ContentType(string: contentType)) != nil
}
+ let filteredDoc = try FilteredDocumentBuilder(document: doc).filter() | This filter hasn't been constructed from the user config so isn't quite what we're looking for.
However, it isn't necessary to do it here anyway because this function, `validateDoc(_:config:)`, is called as a post-transition hook after parsing the OpenAPI document _after_ the existing post-transition hook for filter... |
swift-openapi-generator | github_2023 | others | 471 | apple | czechboy0 | @@ -13,6 +13,58 @@
//===----------------------------------------------------------------------===//
import OpenAPIKit
+import Foundation
+
+/// Extracts content types from a ParsedOpenAPIRepresentation.
+///
+/// - Parameter doc: The OpenAPI document representation.
+/// - Returns: An array of strings representing ... | To avoid duplicating similar logic, you can validate whether the content type is valid by trying to create a `_OpenAPIGeneratorCore.ContentType` value from the string, and if it fails, it's an invalid content type. This regex doesn't fully represent the requirements, and we don't want to have to keep multiple pieces of... |
swift-openapi-generator | github_2023 | others | 471 | apple | czechboy0 | @@ -13,6 +13,58 @@
//===----------------------------------------------------------------------===//
import OpenAPIKit
+import Foundation
+
+/// Extracts content types from a ParsedOpenAPIRepresentation.
+///
+/// - Parameter doc: The OpenAPI document representation.
+/// - Returns: An array of strings representing ... | You could change this to a visitor pattern, where you provide a closure with the signature `(String) -> Bool`, that returns `true` if the content type is valid. And this method would be responsible for walking all the places that have content types.
That way, you can then emit a good diagnostic about _which_ content... |
swift-openapi-generator | github_2023 | others | 471 | apple | czechboy0 | @@ -13,6 +13,58 @@
//===----------------------------------------------------------------------===//
import OpenAPIKit
+import Foundation
+
+/// Extracts content types from a ParsedOpenAPIRepresentation.
+///
+/// - Parameter doc: The OpenAPI document representation.
+/// - Returns: An array of strings representing ... | We should also validate the content types in `#/components/requestBodies` and `#/components/responses` here. |
swift-openapi-generator | github_2023 | others | 471 | apple | czechboy0 | @@ -14,6 +14,71 @@
import OpenAPIKit
+/// Validates all content types from an OpenAPI document represented by a ParsedOpenAPIRepresentation.
+///
+/// This function iterates through the paths, endpoints, and components of the OpenAPI document,
+/// checking and reporting any invalid content types using the provide... | ```suggestion
"Invalid content type string: '\(contentType.rawValue)' found in requestBody at path '\(path.rawValue), method: \(endpoint.method.rawValue)'. Must have 2 components separated by a slash '<type>/<subtype>'.\n"
``` |
swift-openapi-generator | github_2023 | others | 471 | apple | czechboy0 | @@ -14,6 +14,71 @@
import OpenAPIKit
+/// Validates all content types from an OpenAPI document represented by a ParsedOpenAPIRepresentation.
+///
+/// This function iterates through the paths, endpoints, and components of the OpenAPI document,
+/// checking and reporting any invalid content types using the provide... | ```suggestion
"Invalid content type string: '\(contentType.rawValue)' found in responses at path '\(path.rawValue), method: \(endpoint.method.rawValue)'. Must have 2 components separated by a slash '<type>/<subtype>'.\n"
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.