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 | 196 | apple | czechboy0 | @@ -20,6 +20,7 @@ extension TypesFileTranslator {
/// - typedResponse: The typed response to declare.
/// - Returns: A structure declaration.
func translateResponseInTypes(
+ responseKind: String = "", | ```suggestion
responseKind: ResponseKind,
```
As below, let's pass in the typesafe variant and not provide a default. |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -22,10 +22,18 @@ extension TypesFileTranslator {
/// - header: A response parameter.
/// - Returns: A property blueprint.
func parseResponseHeaderAsProperty(
+ responseKind: String = "",
+ typeName: TypeName,
for header: TypedResponseHeader
) throws -> PropertyBlueprint {... | ```suggestion
: "responses/\(responseKind)/headers/\(header.name)"
``` |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -42,6 +42,7 @@ extension TypesFileTranslator {
let responseStructDecl: Declaration?
if typedResponse.isInlined {
responseStructDecl = try translateResponseInTypes(
+ responseKind: responseKind.jsonPathComponent, | ```suggestion
responseKind: responseKind,
``` |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -126,6 +126,10 @@ struct TypeName: Equatable {
precondition(components.count >= 1, "Cannot get the parent of a root type")
return .init(components: components.dropLast())
}
+
+ var isComponent: Bool {
+ description.contains("#/components") | I think you could instead check if the first two JSON components are `#` and `components`, that'd at least use the internal `components` storage and be a little more reliable. |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -54,8 +54,18 @@ extension TypesFileTranslator {
}
let identifier = contentSwiftName(content.content.contentType) | ```suggestion
let contentType = content.content.contentType
let identifier = contentSwiftName(contentType)
``` |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -54,8 +54,18 @@ extension TypesFileTranslator {
}
let identifier = contentSwiftName(content.content.contentType)
let associatedType = content.resolvedTypeUsage
- let contentCase: Declaration = .enumCase(
- .init(
+
+ let subPath: String = {
... | ```suggestion
let typeName = requestBody.typeUsage.typeName
let subPath: String = {
let contentPath = (typeName.isComponent ? "" : "requestBody/") + "content"
return "\(contentPath)/\(contentType.lowercasedTypeAndSubtypeWithEscape)"
}()
... |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -20,6 +20,7 @@ extension TypesFileTranslator {
/// - typedResponse: The typed response to declare.
/// - Returns: A structure declaration.
func translateResponseInTypes(
+ responseKind: ResponseKind?, | Actually, I wonder - don't we already have this information in `typeName`'s JSON components? Why do we need to pass `responseKind`, especially since it's optional so won't always be there? |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -76,22 +88,45 @@ extension TypesFileTranslator {
)
bodyCases.append(contentsOf: inlineTypeDecls)
}
- let bodyCase: Declaration = .enumCase(
- name: identifier,
- kind: .nameWithAssociatedValues([
- .init(type: ... | There's quite a lot of duplication of prefixes of the comments, could we make it a bit more readable by building it up gradually using some local variables, and concatenating more components as needed? Otherwise it's difficult to read how the different branches of the if/else are different. |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -136,6 +171,7 @@ extension TypesFileTranslator {
of: OpenAPI.Response.self
)
return try translateResponseInTypes(
+ responseKind: nil, | Well, this is unfortunate. Now I wonder if we don't already have this info in `typeName`? |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -22,10 +22,22 @@ extension TypesFileTranslator {
/// - header: A response parameter.
/// - Returns: A property blueprint.
func parseResponseHeaderAsProperty(
+ responseKind: ResponseKind?,
+ typeName: TypeName,
for header: TypedResponseHeader
) throws -> PropertyBlueprint... | If the comment is the only reason we have to start passing these other two params, let's move the creation of the comment to the caller of this method, this muddies up the purpose of the method. |
swift-openapi-generator | github_2023 | others | 196 | apple | czechboy0 | @@ -126,6 +126,14 @@ struct TypeName: Equatable {
precondition(components.count >= 1, "Cannot get the parent of a root type")
return .init(components: components.dropLast())
}
+
+ /// Returns a bool value indicating whether the list of JSON path components contains "#" first and "components" s... | ```suggestion
var isInComponents: Bool {
``` |
swift-openapi-generator | github_2023 | others | 200 | apple | FranzBusch | @@ -27,7 +27,7 @@ Below is a table of example changes you might make to an OpenAPI document, and w
| Remove a required property | ❌ | ❌ | ❌ |
| Rename a schema | ✅ | ❌ | ❌ |
-> †: Safe change to make as long as no adopter captured the Swift function signature of the initializer of the generated struct, which gains ... | > function signature of generated structs
Do you mean the function signature of generated initialisers? |
swift-openapi-generator | github_2023 | others | 183 | apple | czechboy0 | @@ -144,10 +144,29 @@ extension OperationDescription {
)
}
- /// Returns parameters from both the path item level
- /// and the operation level.
+ /// Merged parameters from both the path item level and the operation level.
+ /// If duplicate parameters exist, only the parameters from the op... | ```suggestion
var mergedParameters: [UnresolvedParameter] = []
var uniqueIdentifiers: Set<String> = []
```
Style nit: prefer a literal. |
swift-openapi-generator | github_2023 | others | 183 | apple | czechboy0 | @@ -144,10 +144,29 @@ extension OperationDescription {
)
}
- /// Returns parameters from both the path item level
- /// and the operation level.
+ /// Merged parameters from both the path item level and the operation level.
+ /// If duplicate parameters exist, only the parameters from the op... | ```suggestion
let identifier = resolvedParameter.location.rawValue + ":" + resolvedParameter.name
```
Nit: it reads better if the larger scope (location) goes first, then the name that only needs to be unique within the location, and let's separate it with a character for easier readability when de... |
swift-openapi-generator | github_2023 | others | 183 | apple | czechboy0 | @@ -144,10 +144,29 @@ extension OperationDescription {
)
}
- /// Returns parameters from both the path item level
- /// and the operation level.
+ /// Merged parameters from both the path item level and the operation level.
+ /// If duplicate parameters exist, only the parameters from the op... | ```suggestion
guard !uniqueIdentifiers.contains(identifier) else {
continue
}
```
Style nit. |
swift-openapi-generator | github_2023 | others | 183 | apple | czechboy0 | @@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// 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... | I think constructing `OpenAPI.PathItem` is better than creating a document from YAML. See if you can get that to work to initialize an `OperationDescription`. |
swift-openapi-generator | github_2023 | others | 183 | apple | czechboy0 | @@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LICE... | ```suggestion
path: .init(["/test"]),
``` |
swift-openapi-generator | github_2023 | others | 183 | apple | czechboy0 | @@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LICE... | Can you please add one more test that verifies the correct ordering?
Could be:
- path item level: A, B
- operation level: B, C
- expected result: A, B, C |
swift-openapi-generator | github_2023 | others | 179 | apple | glbrntt | @@ -60,28 +60,42 @@ class Test_isSchemaSupported: XCTestCase {
)
),
- // allOf with two schemas
+ // allOf with many schemas
.all(of: [
.object(properties: [
"Foo": .string
]),
.reference(.component(named: "MyObj")),
... | The following code doesn't have a discriminator... is it meant to or is the comment wrong? |
swift-openapi-generator | github_2023 | others | 179 | apple | simonjbeaumont | @@ -1223,6 +1251,13 @@ extension SnippetBasedReferenceTests {
line: UInt = #line
) throws {
let translator = try makeTypesTranslator(componentsYAML: componentsYAML)
+ let schemas = translator.components.schemas
+ for (key, schema) in schemas {
+ XCTAssertTrue(
+ ... | Is this a preflight check of the test, rather than the test itself? What would be the behaviour if we removed this; wouldn't it just throw in `translator.translateSchemas`? IMO, that would be fine, because we can keep the logic simpler here and have tests that `XCTAssertThrowsError` for things we don't support today, i... |
swift-openapi-generator | github_2023 | others | 179 | apple | simonjbeaumont | @@ -142,12 +142,12 @@ Supported features are always provided on _both_ client and server.
- [x] enum
- [x] type
- [x] allOf
- - a wrapper struct is generated and children must be object schemas
+ - a wrapper struct is generated, children can be any schema
- [x] oneOf
- - if a discriminator is specified (re... | > When using the discriminator, inline schemas will not be considered.
Just want to check that we're not being over-strict here. We shouldn't consider inline schemas, sure; but hopefully we're not failing if we find any? |
swift-openapi-generator | github_2023 | others | 179 | apple | simonjbeaumont | @@ -256,8 +242,9 @@ extension FileTranslator {
/// - Parameter schema: A schema to check.
func isRefToObjectishSchemaAndSupported(_ schema: JSONSchema) throws -> IsSchemaSupportedResult {
switch schema.value {
- case .reference:
- return try isObjectishSchemaAndSupported(schema)
+ ... | This lookup isn't required IIUC, as AFAICT `isObjectishSchemaAndSupported` calls `isSchemaSupported` which also does the lookup, in the case of a `.reference`. |
swift-openapi-generator | github_2023 | others | 178 | apple | simonjbeaumont | @@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LICE... | Maybe we can provide an even more consistent experience by catching the errors from this call and emitting fatal `.error` diagnostics? |
swift-openapi-generator | github_2023 | others | 176 | apple | simonjbeaumont | @@ -20,15 +20,23 @@ extension FileTranslator {
/// - typeName: The name of the type to give to the declared enum.
/// - openAPIDescription: A user-specified description from the OpenAPI
/// document.
+ /// - isNullable: Whether the enum schema is nullable.
/// - allowedValues: The enume... | Do we even need the `isNullable` parameter? i.e. would it be safe to just test if `anyValue is Void` unilaterally? |
swift-openapi-generator | github_2023 | others | 171 | apple | glbrntt | @@ -189,6 +192,14 @@ extension FileTranslator {
.content
.contentType
.codingStrategy
+ switch parameter.location {
+ case .query, .cookie:
+ style = .form
+ explode = true
+ case .path, .header:
+ ... | These are just the defaults from https://swagger.io/specification/#parameter-object, right?
Where we implement specs in our other projects we tend to drop in references to them so that if we return to the code later we can see why a decision was made (i.e. we are following the spec vs. just doing what we think is ri... |
swift-openapi-generator | github_2023 | others | 173 | apple | glbrntt | @@ -17,103 +17,106 @@ import OpenAPIKit30
///
/// Represents the serialization method of the payload and affects
/// the generated serialization code.
-enum ContentType: Hashable {
+struct ContentType: Hashable {
+
+ /// The category of a content type.
+ enum Category: Hashable {
+
+ /// A content type ... | Is this ever modified? Wondering if it can be `private let` so that the `category` can be `internal let`? |
swift-openapi-generator | github_2023 | others | 173 | apple | glbrntt | @@ -17,103 +17,106 @@ import OpenAPIKit30
///
/// Represents the serialization method of the payload and affects
/// the generated serialization code.
-enum ContentType: Hashable {
+struct ContentType: Hashable {
+
+ /// The category of a content type.
+ enum Category: Hashable {
+
+ /// A content type ... | Why can we bucket everything else as `binary`? I don't think e.g. `xml` falls in to any of these categories. |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -664,6 +664,38 @@ struct SwitchDescription: Equatable, Codable {
var cases: [SwitchCaseDescription]
}
+/// A description of an if condition and the corresponding code block.
+///
+/// For example: in `if foo { bar }`, the condition pair represents
+/// `foo` + `bar`.
+struct IfConditionPair: Equatable, Codab... | Does seem a bit of a strange one. Could it be folded _into_ the `IfStatementDescription`—e.g. could `IfStatementDescription.IfConditionPair` just be replaced with a tuple of `(Expression, [CodeBlock])`.
If you do keep it here, it seems the term "branch" might be good—which you used as the property name in the below ... |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -256,7 +256,7 @@ public struct Client: APIProtocol {
try converter.setHeaderFieldAsText(
in: &request.headerFields,
name: "accept",
- value: "application/json"
+ value: "application/json, text/plain, application/octet-st... | I realise this might change later, but, to confirm, the plan here is to send _all_ content types the client _knows_ about—that is, all those in the OpenAPI doc—in the accept header?
Looking at the OAS, it appears there's some specified precedence when there's overlap:
> REQUIRED. The content of the request body. ... |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -113,6 +113,31 @@ paths:
$ref: '#/components/schemas/Pet'
'400':
$ref: '#/components/responses/ErrorBadRequest'
+ /pets/stats:
+ get:
+ operationId: getStats
+ responses:
+ '200':
+ description: A successful response.
+ content:
+ ... | Is the handling of content types with wildcards out of scope at this time? |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -1202,6 +1248,23 @@ extension Expression {
)
}
+ /// Returns an if statement, with optional else if's and an else
+ /// statement attached.
+ /// - Parameters:
+ /// - branches: The conditional branches.
+ /// - elseBody: The body of an else block.
+ static func ifStatement(
+ ... | Could the shape of this API be improved to encourage correctness? I.e. it's not possible to have just an `else` branch.
> `/// Returns an if statement, with optional else if's and an else statement attached.`
These docs make complete sense, which implies to me three parameters are needed:
- The first if branc... |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -61,6 +61,78 @@ extension FileTranslator {
return .init(content: content, typeUsage: associatedType)
}
+ /// Extract the supported content types.
+ /// - Parameters:
+ /// - map: The content map from the OpenAPI document.
+ /// - excludeBinary: A Boolean value controlling whether bina... | IIUC there are two dimensions by which a value in a content map might be skipped:
1. The content map key isn't something we support.
2. The schema isn't supported.
Are we emitting clear diagnostics for each? Specifically, I can see we do (1) in the functions below, but does `validateSchemaIsSupported` emit a diagn... |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -72,6 +144,7 @@ extension FileTranslator {
/// - map: The content map from the OpenAPI document.
/// - excludeBinary: A Boolean value controlling whether binary content
/// type should be skipped, for example used when encoding headers.
+ /// - foundIn: The location where this content is pa... | Just popping this here, while I found it, on the OAS spec, but we can break this out into a separate discussion.
The encoding can be specified by a user using an `encoding` field in their document[^1]. I don't think we support that today (correct me if I'm wrong)—are we tracking it?
The reason I drop it here is b... |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -123,4 +196,62 @@ extension FileTranslator {
return nil
}
}
+
+ /// Returns a wrapped version of the provided content if supported, returns
+ /// nil otherwise.
+ ///
+ /// Priority of checking for known MIME types:
+ /// 1. JSON
+ /// 2. text
+ /// 3. binary
+ ///
... | The `encoding` property in the `content` map should only be used in more specific cases[^1]. Should we be more precise about when we consider it?
> The encoding object SHALL only apply to requestBody objects when the media type is multipart or application/x-www-form-urlencoded.
[^1]: https://spec.openapis.org/oas... |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -95,12 +95,11 @@ extension FileTranslator {
isInlined = true
}
- guard
- let content = try bestSingleTypedContent(
- request.content,
- inParent: typeName
- )
- else {
+ let contents = try supportedTypedContents(
+ ... | Took me a while to grok this, because I was expecting the feature flag switch to be here, but then realised that you fallback to the old behaviour in the _new_ function, based on the feature flag.
What was the reasoning behind this? Could we move it here, which would also allow the new function, that does multiple c... |
swift-openapi-generator | github_2023 | others | 146 | apple | simonjbeaumont | @@ -616,7 +616,79 @@ final class SnippetBasedReferenceTests: XCTestCase {
)
}
- func testComponentsResponsesResponseWithOptionalHeader() throws {
+ func testComponentsResponsesResponseMultipleContentTypes() throws { | Thanks for adding these tests! |
swift-openapi-generator | github_2023 | others | 146 | apple | gjcairo | @@ -342,6 +342,120 @@ final class Test_Client: XCTestCase {
}
}
+ func testGetStats_200_json() async throws {
+ transport = .init { request, baseURL, operationID in
+ XCTAssertEqual(operationID, "getStats")
+ XCTAssertEqual(request.path, "/pets/stats")
+ XCTAss... | Do we want to assert anything about the error being thrown? |
swift-openapi-generator | github_2023 | others | 146 | apple | gjcairo | @@ -16,23 +16,18 @@ import OpenAPIKit30
extension TypesFileTranslator {
/// Returns a list of declarations that define a Swift type for
- /// the request body content and type name.
+ /// the request body content.
/// - Parameters:
- /// - typeName: The type name to declare the request body type... | What's the context behind removing this override? |
swift-openapi-generator | github_2023 | others | 169 | apple | simonjbeaumont | @@ -54,12 +54,15 @@ struct TextBasedRenderer: RendererProtocol {
prefix = "// MARK:"
commentString = string
}
- return commentString.transformingLines { line in
- if line.isEmpty {
- return prefix
+ return
+ commentString
+ ... | In the presence of `\r\n` this produces two newlines but I think it should just be one.
Presumably the goal of this patch is to handle both newline conventions: `LF` or `CR+LF`. IIUC, the `\r` is a carriage return.
Does `String` have any utilities for splitting on "newlines" which might just handle this for us in... |
swift-openapi-generator | github_2023 | others | 169 | apple | simonjbeaumont | @@ -721,7 +723,7 @@ fileprivate extension String {
/// Returns an array of strings, where each string represents one line
/// in the current string.
func asLines() -> [String] {
- split(separator: "\n", omittingEmptySubsequences: false)
+ split(omittingEmptySubsequences: false, whereSeparat... | Should we be omitting empty sequences?
Realise this is scope creep because this was probably the behaviour before but I think that we should be preserving the number of newlines in comments. If you consider that a comment may be interpreted as markdown, you need two newlines to start a new block. |
swift-openapi-generator | github_2023 | others | 164 | apple | simonjbeaumont | @@ -13,6 +13,46 @@
//===----------------------------------------------------------------------===//
import OpenAPIKit30
+/// A result of checking whether a schema is supported.
+enum IsSchemaSupportedResult: Equatable {
+
+ /// The schema is supported and can be generated.
+ case supported
+
+ /// The reas... | But this is a valid schema that isn't "object-ish", right?
```yaml
schema:
type: string
```
Is this for when it's supposed to be "object-ish" but isn't? |
swift-openapi-generator | github_2023 | others | 161 | apple | denil-ct | @@ -29,6 +29,7 @@ If you have any questions, tag [Honza Dvorsky](https://github.com/czechboy0) or
- Awaiting Review
- In Review
- Ready for Implementation
+- Merged behind a Feature Flag | Mentioning the flag name in the state, would also be a good addition. |
swift-openapi-generator | github_2023 | others | 162 | apple | simonjbeaumont | @@ -125,31 +125,33 @@ func makeGeneratorPipeline(
postTransitionHooks: [
{ doc in
- // Run OpenAPIKit's built-in validation.
- try doc.validate()
-
- // Validate that the document is dereferenceable, which
- // c... | Do we need to be more selective here about what's gated and what isn't?
Didn't we add these originally to reject documents with reference cycles and/or external references that we cannot support, and would otherwise fail to generate anyway?
If that's the case then shouldn't we keep the `locallyDereferened()` and ... |
swift-openapi-generator | github_2023 | others | 95 | apple | michalsrutek | @@ -0,0 +1,50 @@
+# SOAR-0001
+
+Encoding for Property Names
+
+## Overview
+
+- Proposal: SOAR-0001
+- Author(s): [Denil](https://github.com/denil-ct)
+- Status: **Awaiting Review**
+- Issue: https://github.com/apple/swift-openapi-generator/issues/21
+- Implementation:
+ - https://github.com/apple/swift-openapi-gen... | Looking at the example mapping
yaml | swift
-- | --
a b | a_space_b
ab_ | ab_
it follows that there would be a collision for
yaml | swift
-- | --
a b | a_space_b
a_space_b | a_space_b
which needs to be addressed somehow. |
swift-openapi-generator | github_2023 | others | 147 | apple | czechboy0 | @@ -55,10 +55,10 @@ extension FileTranslator {
switch type {
case .allOf:
// AllOf uses all required properties.
- propertyType = rawPropertyType
+ propertyType = rawPropertyType.withOptional(false)
case .anyOf... | I like it, it feels right - `allOf` is all subschemas being required, `anyOf` is all subschemas being optional. |
swift-openapi-generator | github_2023 | others | 150 | apple | czechboy0 | @@ -107,6 +107,13 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/CodeError'
+ X-Extra-Arguments2:
+ required: true
+ description: "A description here."
+ content:
+ application/json... | I don't think we need this change to the integration test project, `listPets/My-Response-UUID` already is an example of a required response header. |
swift-openapi-generator | github_2023 | others | 150 | apple | czechboy0 | @@ -519,7 +519,7 @@ final class SnippetBasedReferenceTests: XCTestCase {
)
}
- func testComponentsResponsesResponseWithHeader() throws {
+ func testComponentsResponsesResponseWithOptionalHeader() throws { | These changes are great, covering both in snippet tests gives us the confidence it works correctly without having to expand the file-based reference test. |
swift-openapi-generator | github_2023 | others | 150 | apple | czechboy0 | @@ -192,6 +193,7 @@ final class Test_Client: XCTestCase {
return
}
XCTAssertEqual(value.headers.X_Extra_Arguments, .init(code: 1))
+ XCTAssertEqual(value.headers.X_Extra_Arguments2, .init(code: 9999)) | Let's undo these changes, as per the comment in `petstore.yaml`. |
swift-openapi-generator | github_2023 | others | 150 | apple | czechboy0 | @@ -166,7 +166,7 @@ final class Test_Server: XCTestCase {
XCTAssertEqual(
response.headerFields,
[
- .init(name: "X-Extra-Arguments", value: #"{"code":1}"#),
+ .init(name: "X-Extra-Arguments2", value: #"{"code":1}"#), | Let's undo these changes, as per the comment in `petstore.yaml`. |
swift-openapi-generator | github_2023 | others | 150 | apple | czechboy0 | @@ -985,12 +985,18 @@ public enum Operations {
public struct Created: Sendable, Equatable, Hashable {
public struct Headers: Sendable, Equatable, Hashable {
public var X_Extra_Arguments: Components.Schemas.CodeError?
+ public var X_Extra_Arguments2: ... | Let's undo these changes, as per the comment in `petstore.yaml`. |
swift-openapi-generator | github_2023 | others | 150 | apple | czechboy0 | @@ -220,6 +220,11 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
name: "X-Extra-Arguments",
value: value.headers.X_Extra_Arguments
)
+ try converter.setHeaderFieldAsJSON(
+ in: &res... | Let's undo these changes, as per the comment in `petstore.yaml`. |
swift-openapi-generator | github_2023 | others | 150 | apple | czechboy0 | @@ -174,6 +174,11 @@ public struct Client: APIProtocol {
in: response.headerFields,
name: "X-Extra-Arguments",
as: Components.Schemas.CodeError.self
+ ),
+ X_Extra_Arguments2: try convert... | Let's undo these changes, as per the comment in `petstore.yaml`. |
swift-openapi-generator | github_2023 | others | 150 | apple | simonjbeaumont | @@ -80,6 +80,21 @@ struct StructBlueprint {
var properties: [PropertyBlueprint]
}
+extension StructBlueprint {
+
+ /// A Boolean value indicating whether the struct can be initialized using
+ /// an empty initializer.
+ ///
+ /// For example, when all the properties of the struct have a default valu... | Nit: Thin it would read nicer to invert this check:
```suggestion
properties.allSatisfy { $0.defaultValue != nil }
``` |
swift-openapi-generator | github_2023 | others | 150 | apple | simonjbeaumont | @@ -36,20 +36,21 @@ extension TypesFileTranslator {
let headerProperties: [PropertyBlueprint] = try headers.map { header in
try parseResponseHeaderAsProperty(for: header)
}
+ let headersStructBlueprint: StructBlueprint = .init( | Nit: This syntax makes the reader ask "is there some kind of upcasting going on here?", could we replace with:
```suggestion
let headersStructBlueprint = StructBlueprint(
``` |
swift-openapi-generator | github_2023 | others | 157 | apple | gjcairo | @@ -11,127 +11,10 @@
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
-import OpenAPIRuntime
-import Foundation
-
-enum TestError: Swift.Error, LocalizedError, CustomStringConvertible {
- case noHandlerFound(method: HTTPMethod, path: [Route... | Potentially naive question but why wouldn't this belong in the common target too? |
swift-openapi-generator | github_2023 | others | 98 | apple | Kyle-Ye | @@ -0,0 +1,161 @@
+//===----------------------------------------------------------------------===//
+//
+// 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... | This logic is duplicated. Maybe we could move such code to a single file. And make soft link to it so that both plugins can depend on it. |
swift-openapi-generator | github_2023 | others | 98 | apple | denil-ct | @@ -0,0 +1,45 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case badArguments(arguments: [String])
+ // The description is only suitable for Xcode, as it's only thrown in Xcode plugins.
+ ... | ```suggestion
case multipleConfigsFound(targetName: String, files: [Path])
case multipleDocumentsFound(targetName: String, files: [Path])
```
A bit clearer on the meaning. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -27,6 +27,7 @@ let package = Package(
products: [
.executable(name: "swift-openapi-generator", targets: ["swift-openapi-generator"]),
.plugin(name: "OpenAPIGenerator", targets: ["OpenAPIGenerator"]),
+ .plugin(name: "OpenAPIGeneratorCommandPlugin", targets: ["OpenAPIGeneratorCommandPlug... | ```suggestion
.plugin(name: "OpenAPIGeneratorCommand", targets: ["OpenAPIGeneratorCommand"]),
```
I think `OpenAPIGeneratorCommand` is a good name. `Plugin` is redundant, as the build system ensures that this product type is used in the correct context. It also reads better when it shows up in Xcode, as yo... |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -134,5 +135,19 @@ let package = Package(
"swift-openapi-generator",
]
),
+
+ .plugin(
+ name: "OpenAPIGeneratorCommandPlugin",
+ capability: Target.PluginCapability.command(
+ intent: .custom(
+ verb: "generate-open... | ```suggestion
description: "Generates Swift code from an OpenAPI document."
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -134,5 +135,19 @@ let package = Package(
"swift-openapi-generator",
]
),
+
+ .plugin(
+ name: "OpenAPIGeneratorCommandPlugin",
+ capability: Target.PluginCapability.command(
+ intent: .custom(
+ verb: "generate-open... | ```suggestion
permissions: [.writeToPackageDirectory(reason: "To write the generated Swift files back into the source directory of the package.")]
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,137 @@
+//===----------------------------------------------------------------------===//
+//
+// 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... | Can you also clean the environment, to ensure that nothing leaks through. If that breaks the plugin, only add the exact env vars required.
```suggestion
process.arguments = inputs.arguments
process.environment = [:]
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,137 @@
+//===----------------------------------------------------------------------===//
+//
+// 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... | Should we have a `process.waitUntilExit()` here? Otherwise the command plugin might exit before the spawned process does. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,137 @@
+//===----------------------------------------------------------------------===//
+//
+// 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... | I think we can simplify the whole plugin by _always_ requiring exactly one target name. That way, we don't have to search for dependencies or worry about which targets are included in a scheme.
It also means we can emit good errors in all scenarios, instead of guessing which target the adopter meant to generate code... |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,82 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetsFoundForCommandPlugin
+ case fileErrors([FileError], targetName: String)
+
+ var description: String {
+ ... | ```suggestion
return "Incompatible target called '\(targetName)'. Only Swift source targets can be used with the Swift OpenAPI Generator plugin."
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,82 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetsFoundForCommandPlugin
+ case fileErrors([FileError], targetName: String)
+
+ var description: String {
+ ... | I guess this case will go away if we simplify to always require the specific target to be passed in. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,82 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetsFoundForCommandPlugin
+ case fileErrors([FileError], targetName: String)
+
+ var description: String {
+ ... | ```suggestion
case multipleFilesFound(files: [Path])
```
While we're changing this, we can make it clearer. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -42,16 +42,19 @@ struct _GenerateCommand: AsyncParsableCommand {
)
var outputDirectory: URL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
- @Flag(
+ @Option(
help:
"Whether this invocation is from the SwiftPM plugin. We always need to produce all files when ... | Allow me to bikeshed for a moment here: I think the name `pluginInvocationSource` would work well, as an option (so `PluginInvocationSource?`).
Then, the `PluginInvocationSource` would only have the cases `.command` and `.build`.
That way, by default, and when invoked manually, this option is nil. Otherwise, each... |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,6 @@
+/// The source of the generator invocation.
+enum InvocationSource: String, Codable { | ```suggestion
enum PluginInvocationSource: String, Codable {
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,6 @@
+/// The source of the generator invocation.
+enum InvocationSource: String, Codable {
+ case BuildToolPlugin
+ case CommandPlugin
+ case CLI | ```suggestion
case build
case command
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,118 @@
+import PackagePlugin
+
+enum PluginUtils {
+ private static var supportedConfigFiles: Set<String> { Set(["yaml", "yml"].map { "openapi-generator-config." + $0 }) }
+ private static var supportedDocFiles: Set<String> { Set(["yaml", "yml", "json"].map { "openapi." + $0 }) }
+
+ /// Validated v... | I'd keep the name to the original name, that way when folks upgrade to the newer generator, they won't immediately get a build error as we'd generate duplicate files to the new directory name, and not clean up the old one. `GeneratedSources` is explicit enough, IMO. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -151,5 +152,20 @@ let package = Package(
"swift-openapi-generator"
]
),
+
+ // Command Plugin
+ .plugin(
+ name: "OpenAPIGeneratorCommand",
+ capability: Target.PluginCapability.command( | ```suggestion
capability: .command(
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -151,5 +152,20 @@ let package = Package(
"swift-openapi-generator"
]
),
+
+ // Command Plugin
+ .plugin(
+ name: "OpenAPIGeneratorCommand",
+ capability: Target.PluginCapability.command(
+ intent: .custom(
+ ... | ```suggestion
verb: "generate-code-from-openapi",
```
Maybe a slightly better name, I prefer if the input is on the left of the output when reading left-to-right, so "generate code from openapi". |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -151,5 +152,20 @@ let package = Package(
"swift-openapi-generator"
]
),
+
+ // Command Plugin
+ .plugin(
+ name: "OpenAPIGeneratorCommand",
+ capability: Target.PluginCapability.command(
+ intent: .custom(
+ ... | ```suggestion
description: "Generate Swift code from an OpenAPI document."
```
Unsure, but maybe this should be an imperative? |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
let introduction = dependencyNames.isEmpty ? "Target called '\(targetName)' doesn't contain" : "Target called '\(targetName)' or its local dependencies \(dependencyNames.joined(separator: ", ") don't contain"
```
Should we format the names somehow? |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String) | ```suggestion
case incompatibleTarget(name: String)
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
case noTargetsMatchingTargetName(String)
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
return "\(introduction) any config or OpenAPI document files with expected names. See documentation for details."
```
Let's add "OpenAPI" to the sentence and drop the summary of the docs, we don't want to have to keep it in sync here with the other places. Sending people to docs is good e... |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | Adopters might be using this from other IDEs, so I'd drop the reference to Xcode specifically.
```suggestion
return "Unexpected arguments: '\(arguments.joined(separator: " "))', expected: '--target MyTarget'."
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
return "Found no targets with the name '\(targetName)'."
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
return "Found too many targets with the name '\(targetName)': \(matchingTargetNames.joined(separator: ", ")). Select a target name with a unique name."
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
return "Issues with required files: \(errors.map(\.localizedDescription).joined(separator: ", and"))."
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | Nit: You could put these first 5 on the same line, to more clearly communicate that they are handled the same way. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
var isMisconfigurationError: Bool {
```
You can drop the "Definite", as `isMisconfigurationError` already communicates what you need. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
var isMisconfigurationError: Bool {
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | Let's reshuffle this a bit to get rid of the force unwrap.
1. Move the contents of `helpAnchor` to be the implementation of `description`.
2. Have `helpAnchor` call `description`.
3. Drop the `FileError { ... }` part completely, unless it's specifically parsed some other tool? |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | Is anything calling this helper function? |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
private extension Array where Element == FileError {
```
Nit: This is the spelling we use in this project. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,125 @@
+import PackagePlugin
+import Foundation
+
+enum PluginError: Swift.Error, CustomStringConvertible, LocalizedError {
+ case incompatibleTarget(targetName: String)
+ case noTargetOrDependenciesWithExpectedFiles(targetName: String, dependencyNames: [String])
+ case badArguments([String])
+ c... | ```suggestion
var isMisconfigurationError: Bool {
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,5 @@
+/// The source of a plugin generator invocation.
+enum PluginSource: String, Codable {
+ case build
+ case command | Please add doc comments for the cases. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -94,18 +105,31 @@ extension _Tool {
/// - Throws: When writing to disk fails.
/// - Returns: `true` if the generated contents changed, otherwise `false`.
@discardableResult
- static func replaceFileContents(at path: URL, with contents: () throws -> Data) throws -> Bool {
+ static func replaceFil... | ```suggestion
let fileManager = FileManager()
```
Variable naming, and it's better to create a new FileManager, as otherwise someone might have set the delegate on the shared file manager, which can lead to unexpected results. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -42,16 +42,19 @@ struct _GenerateCommand: AsyncParsableCommand {
)
var outputDirectory: URL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
- @Flag(
+ @Option(
help:
- "Whether this invocation is from the SwiftPM plugin. We always need to produce all files when ... | Just bumping the first half of this comment: https://github.com/apple/swift-openapi-generator/pull/98#discussion_r1265064137
Let's also rename the option (will require a change in the plugins as well, and in the docs) to `--plugin-source`, I'm not a fan of options ending with a preposition.
```suggestion
var... |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,118 @@
+import PackagePlugin
+
+enum PluginUtils {
+ private static var supportedConfigFiles: Set<String> { Set(["yaml", "yml"].map { "openapi-generator-config." + $0 }) }
+ private static var supportedDocFiles: Set<String> { Set(["yaml", "yml", "json"].map { "openapi." + $0 }) }
+
+ /// Validated v... | ```suggestion
"--plugin-source", "\(pluginSource.rawValue)",
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// 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... | Also, we should inspect the `process.terminationStatus` and throw an error if it's not 0. |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// 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... | Idea: also accept a single argument name, and treat it as the name of the target? So the `--target` part would be somewhat optional.
That way, folks can invoke it from CLI as
```
swift package generate-code-from-openapi MyTarget
``` |
swift-openapi-generator | github_2023 | others | 98 | apple | czechboy0 | @@ -0,0 +1,103 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 simple `print(...)` describing which target is being inspected, and whether we tried to run the command on it, and if it succeeded or not. Just for easier debugging. |
swift-openapi-generator | github_2023 | others | 148 | apple | simonjbeaumont | @@ -61,7 +32,7 @@ fileprivate extension String {
///
/// In addition to replacing illegal characters with an underscores, also
/// ensures that the identifier starts with a letter and not a number.
- var sanitizedForSwiftCode: String {
+ var safeForSwiftCode: String { | If we're going to dependency inject in the function for doing this, can we remove these functions from being extensions on `String` which seems a bit too easy to accidentally reach for. |
swift-openapi-generator | github_2023 | others | 148 | apple | simonjbeaumont | @@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LICE... | Why do we have this wrapper function at this level. Shouldn't we be injecting this in at the top and have `swiftSafeName` be a property on `FileTranslator` too? |
swift-openapi-generator | github_2023 | others | 148 | apple | simonjbeaumont | @@ -30,6 +30,10 @@ struct OperationDescription {
/// The OpenAPI components, used to resolve JSON references.
var components: OpenAPI.Components
+ /// A converted function from user-provided strings to strings
+ /// safe to be used as a Swift identifier.
+ var asSwiftSafeName: (String) -> String | Having these as properties in the various description objects feels wrong to me.
Having the various types that do generations holding onto one of these functions feels right, but these description objects are supposed to be just a datatype.
I take it this was added because you didn't want to change the computed p... |
swift-openapi-generator | github_2023 | others | 141 | apple | simonjbeaumont | @@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 LICE... | I'm not sure I understand why this has been moved here. Couple of reasons:
- This PR is in aid of the _multiple_ content types but it is operating on a single `ContentType` as it was when it was a computed property on `ContentType`.
- This flow is no longer colocated with all the other logic, e.g. `headerValueForSt... |
swift-openapi-generator | github_2023 | others | 140 | apple | czechboy0 | @@ -231,6 +231,46 @@ final class Test_Server: XCTestCase {
)
}
+
+ func testCreatePet_withIncorrectContentType() async throws {
+ client = .init(
+ createPetBlock: { input in
+ return .created(
+ .init(
+ headers: .init(
+... | ```suggestion
} catch {}
```
You can remove the non-nil check, as the `error` variable in the `catch` block is of type `Error`, not `Error?`. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.