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
426
apple
czechboy0
@@ -0,0 +1,59 @@ +openapi: '3.1.0' +info: + title: GreetingService + version: 1.0.0 +servers: + - url: https://example.com/api + description: Example service deployment. +paths: + /greet: + get: + operationId: getGreeting + parameters: + - name: name + required: false + in: ...
Should be POST/PUT?
swift-openapi-generator
github_2023
others
426
apple
czechboy0
@@ -0,0 +1,59 @@ +openapi: '3.1.0' +info: + title: GreetingService + version: 1.0.0 +servers: + - url: https://example.com/api + description: Example service deployment. +paths: + /greet: + get: + operationId: getGreeting + parameters: + - name: name + required: false + in: ...
Can return 204 No Content instead.
swift-openapi-generator
github_2023
others
415
apple
simonjbeaumont
@@ -0,0 +1,45 @@ +// swift-tools-version:5.9 +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftOpenAPIGenerator open source project +// +// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors +// Licensed under Apache L...
I think this is overly restrictive these days and dates back to before we relaxed things, pre 0.1.
swift-openapi-generator
github_2023
others
415
apple
simonjbeaumont
@@ -0,0 +1,45 @@ +// swift-tools-version:5.9 +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftOpenAPIGenerator open source project +// +// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors +// Licensed under Apache L...
Weren't there some bug fixes related to streaming in Vapor? I realise we'd probably get them by resolution, but let's set this to something more recent, that we know has the fixes we need.
swift-openapi-generator
github_2023
others
415
apple
simonjbeaumont
@@ -0,0 +1,40 @@ +# Hello World Server + +An example project using [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator). + +## Overview + +A "hello world" server that uses generated server stubs to handle requests as the Greeting Service. + +The tool uses the [Vapor](https://github.com/vapor/vap...
Could we emphasise here that there's no transport involved in these tests so you preserve the ability to swap to another one at any time and no networking types or connectivity is required to run the tests.
swift-openapi-generator
github_2023
others
412
apple
simonjbeaumont
@@ -0,0 +1,51 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## 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 ...
```suggestion ```
swift-openapi-generator
github_2023
others
412
apple
simonjbeaumont
@@ -0,0 +1,51 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## 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 ...
```suggestion "${SWIFT_BIN}" package --package-path "${EXAMPLE_COPY_DIR}" \ ```
swift-openapi-generator
github_2023
others
412
apple
simonjbeaumont
@@ -0,0 +1,51 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## 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 ...
```suggestion "${SWIFT_BIN}" build --package-path "${EXAMPLE_COPY_DIR}" ```
swift-openapi-generator
github_2023
others
412
apple
simonjbeaumont
@@ -0,0 +1,51 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## 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 ...
```suggestion for EXAMPLE_PACKAGE_PATH in $(find "${EXAMPLES_PACKAGE_PATH}" -maxdepth 2 -name Package.swift -type f -print0 | xargs -0 dirname); do ``` (FYI, this kind of thing can be picked up by `shellcheck`).
swift-openapi-generator
github_2023
others
412
apple
simonjbeaumont
@@ -0,0 +1,51 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## 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 ...
```suggestion EXAMPLE_PACKAGE_NAME="$(basename "${EXAMPLE_PACKAGE_PATH}")" ```
swift-openapi-generator
github_2023
others
412
apple
simonjbeaumont
@@ -0,0 +1,51 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## 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 ...
Fun. In all these years I never knew `-R` is the same as `-r`.
swift-openapi-generator
github_2023
others
412
apple
simonjbeaumont
@@ -0,0 +1,51 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## 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 ...
```suggestion log "Running tests for example package: ${EXAMPLE_PACKAGE_NAME}" "${SWIFT_BIN}" test --package-path "${EXAMPLE_COPY_DIR}" ```
swift-openapi-generator
github_2023
others
398
apple
czechboy0
@@ -37,7 +37,7 @@ let package = Package( // The platforms below are not currently supported for running // the generator itself. We include them here to allow the generator // to emit a more descriptive compiler error. - .iOS(.v13), .tvOS(.v13), .watchOS(.v6), + .iOS(.v13), .tvO...
Technically, this isn't necessary, as any platform _not_ listed here is assumed to work using _all_ versions, which matches visionOS. But it's probably a good idea to have it here explicitly anyway, to signal that it's been considered.
swift-openapi-generator
github_2023
others
366
apple
simonjbeaumont
@@ -64,7 +64,7 @@ let package = Package( // Tests-only: Runtime library linked by generated code, and also // helps keep the runtime library new enough to work with the generated // code. - .package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.3.6")), ...
Would you prefer us to cut a 0.3.7 runtime and move to main separately?
swift-openapi-generator
github_2023
others
366
apple
simonjbeaumont
@@ -162,29 +168,40 @@ extension FileTranslator { /// - contentValue: The content value from the OpenAPI document. /// - excludeBinary: A Boolean value controlling whether binary content /// type should be skipped, for example used when encoding headers. + /// - isRequired: Whether the contents...
Can you elaborate on why this is here? Is this something that is convention in OpenAPI docs but compliant with OAS?
swift-openapi-generator
github_2023
others
366
apple
simonjbeaumont
@@ -45,12 +46,18 @@ extension TypesFileTranslator { let contentTypeName = typeName.appending(jsonComponent: "content") let contents = requestBody.contents for content in contents { - if TypeMatcher.isInlinable(content.content.schema) { + if TypeMatcher.isInlinable(conten...
Could this be chopped up a bit to make it easier to follow the conditions?
swift-openapi-generator
github_2023
others
366
apple
simonjbeaumont
@@ -149,6 +149,21 @@ struct TypeMatcher { /// - Returns: `true` if the schema is inlinable; `false` otherwise. static func isInlinable(_ schema: UnresolvedSchema?) -> Bool { !isReferenceable(schema) } + /// Return a reference to a multipart element type if the provided schema is referenceable. + /// -...
This one sounds like it should have some good test coverage; does it? I looked but didn't see it.
swift-openapi-generator
github_2023
others
369
apple
dnadoba
@@ -0,0 +1,933 @@ +# SOAR-0009: Type-safe streaming multipart support + +Provide a type-safe streaming API to produce and consume multipart bodies. + +## Overview + +- Proposal: SOAR-0009 +- Author(s): [Honza Dvorsky](https://github.com/czechboy0) +- Status: **In Review** +- Issue: [apple/swift-openapi-generator#36](ht...
I would suggest calling it RandomMultipartBoundaryGenerator Similar to the existing [`RandomNumberGenerator`](https://developer.apple.com/documentation/swift/randomnumbergenerator) protocol and [`SystemRandomNumberGenerator`](https://developer.apple.com/documentation/swift/systemrandomnumbergenerator) struct. ```su...
swift-openapi-generator
github_2023
others
346
apple
czechboy0
@@ -44,8 +43,7 @@ struct GreetingServiceClient { } // Use shorthand APIs to get an expected response or otherwise throw a runtime error. - print(try await client.getGreeting().ok.body.json.message) - // ^ ^ ^ + print(try await client.getGree...
Try to put an extra newline to see if then swift-format leaves the comment alone.
swift-openapi-generator
github_2023
others
345
apple
glbrntt
@@ -35,6 +41,13 @@ for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do fi done +log "Running swift-format..." +bash ${CURRENT_SCRIPT_DIR}/run-swift-format.sh $FIX_FORMAT > /dev/null
```suggestion bash "${CURRENT_SCRIPT_DIR}"/run-swift-format.sh $FIX_FORMAT > /dev/null ```
swift-openapi-generator
github_2023
others
343
apple
glbrntt
@@ -13,6 +13,86 @@ //===----------------------------------------------------------------------===// import Foundation +/// An object for building up a generated file line-by-line. +/// +/// After creation, make calls such as `writeLine` to build up the file, +/// and call `rendered` at the end to get the full file ...
Maybe it will become more obvious when I see call-sites, but why not have this as a parameter to `writeLine` which defaults to `false`?
swift-openapi-generator
github_2023
others
343
apple
glbrntt
@@ -13,6 +13,86 @@ //===----------------------------------------------------------------------===// import Foundation +/// An object for building up a generated file line-by-line. +/// +/// After creation, make calls such as `writeLine` to build up the file, +/// and call `rendered` at the end to get the full file ...
Makes basically no practical difference but feels odd to me to do this with an array vs `String(repeating: " ", count: level * 4)`
swift-openapi-generator
github_2023
others
343
apple
glbrntt
@@ -13,6 +13,86 @@ //===----------------------------------------------------------------------===// import Foundation +/// An object for building up a generated file line-by-line. +/// +/// After creation, make calls such as `writeLine` to build up the file, +/// and call `rendered` at the end to get the full file ...
We do this in grpc as well, makes the code-gen _so_ much easier to write and follow.
swift-openapi-generator
github_2023
others
343
apple
glbrntt
@@ -127,38 +227,65 @@ struct TextBasedRenderer: RendererProtocol { } /// Renders the specified member access expression. - func renderedMemberAccess(_ memberAccess: MemberAccessDescription) -> String { - let left = memberAccess.left.flatMap { renderedExpression($0) } ?? "" - return "\(left)...
One helper I've used before is a sequence which return the underlying element and whether it's the final value or not which would simplify this a tiny amount (and allows you to avoid conflating index and offset).
swift-openapi-generator
github_2023
others
343
apple
glbrntt
@@ -34,7 +34,7 @@ if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then To fix, run the following command: - % git ls-files -z '*.swift' | xargs -0 swift-format --in-place --parallel + % git ls-files -z '*.swift' | grep -z -v -e 'Tests/OpenAPIGeneratorReferenceTests/Resources' -e 'Sources/swift-openapi-generator/Documen...
It might be worth adding `// swift-format-ignore-file` (or whatever the directive is) to the generated code; makes life easier for adopters who check in the code (both grpc and protobuf do this).
swift-openapi-generator
github_2023
others
338
apple
czechboy0
@@ -17,7 +17,9 @@ struct GreetingServiceAPIImpl: APIProtocol { _ input: Operations.getEmoji.Input ) async throws -> Operations.getEmoji.Output { let emojis = "👋👍👏🙏🤙🤘" - return .ok(.init(body: .text(String(emojis.randomElement()!)))) + let emoji = String(emojis.randomElement()!...
You can provide the string directly to the HTTPBody initializer, no need to explicitly concert to data first.
swift-openapi-generator
github_2023
others
340
apple
dnadoba
@@ -17,6 +17,7 @@ import PetstoreConsumerTestCore final class Test_Types: XCTestCase { + /// Setup method called before the invocation of each test method in the class.
hm... we might want to have a different swift-format docs policy for test targets but this can be in a separate PR if we decided to do it
swift-openapi-generator
github_2023
others
337
apple
glbrntt
@@ -16,7 +16,7 @@ import XCTest import Yams @testable import _OpenAPIGeneratorCore -final class FilteredDocumentTests: XCTestCase { +final class Test_FilteredDocument: XCTestCase {
Is it possible to add a test that filters a document twice and validates the output is identical?
swift-openapi-generator
github_2023
others
335
apple
glbrntt
@@ -125,42 +122,38 @@ struct RecursionDetector { // We have seen this node. - // If the name is not in the stack, this is not a cycle. - if !stackSet.contains(name) { + // If the name is not in the stack twice, this is not a cycle. + if !previousStackSet.cont...
Is it worth checking if any of the boxable `cycleNodes` are already in `boxed`?
swift-openapi-generator
github_2023
others
330
apple
dnadoba
@@ -0,0 +1,130 @@ +# Supporting recursive types + +Learn how the generator supports recursive types. + +## Overview + +In some applications, the most expressive way to represent arbitrarily nested data is using a type that holds another value of itself, either directly, or through another type. We refer to such types a...
You will very likely need a `_modify` accessor here to not always trigger copy on write if mutated.
swift-openapi-generator
github_2023
others
330
apple
dnadoba
@@ -0,0 +1,204 @@ +//===----------------------------------------------------------------------===// +// +// 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...
FWIW this can now also be written as `extension Array<String> { ... }` or even `extension [String] { ... }` but that's just a matter of style.
swift-openapi-generator
github_2023
others
331
apple
czechboy0
@@ -44,9 +44,11 @@ class FileBasedReferenceTests: XCTestCase { #endif } - func testPetstore() throws { - try _test(referenceProject: .init(name: .petstore)) - } + #if canImport(SwiftSyntax509) + func testPetstore() throws { + try _test(referenceProject: .init(name: .pet...
One more thing - to avoid silently not running the test, can you put the #if into the function and in the #else just fail with a descriptive message? Once this lands, nobody should be running tests of this package with the 5.8 version of the dependencies.
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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...
Still relevant TODO?
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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...
Might be enough as `Decodable`?
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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...
Is there extra validation in the decoder of OpenAPI.Path we want to take advantage of? Or should we just make this a String?
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// 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...
Is there a distinction between an empty array and a nil array? Naively, I'd expect a nil array to mean "don't filter using this axis, aka keep everything", versus an empty array, which I'd understand as "filter out everything".
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,485 @@ +//===----------------------------------------------------------------------===// +// +// 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...
Super small nit, I find the word "include" a bit clearer than "require" here. Especially if we might add "exclude" down the line.
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,485 @@ +//===----------------------------------------------------------------------===// +// +// 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...
Very good call, will ensure adopters don't make a typo in their operation id and then spend time debugging why their operation isn't showing up. I wonder if we should somehow "consume" all the other filters as well, and throw an error if you're trying to include something that doesn't exist in the document? Not cruc...
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,485 @@ +//===----------------------------------------------------------------------===// +// +// 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 case .all(of: let schemas, _), .one(of: let schemas, _), .any(of: let schemas, _): ``` Does the same thing and avoids the scary fallthrough 🙂
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,485 @@ +//===----------------------------------------------------------------------===// +// +// 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 we throw an error if it fails to init? Looking at the impl, there might be situations where the user's document could cause this to crash, which becomes difficult to debug.
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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 will be useful for debugging. Could you also add a few words about it to the Configuring docc article, both about the new keys in the config file, and about using the new filter command?
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// 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...
`parseOpenAPIDocument` looks very similar to code we have in YamsParser, could you factor it out into a shared API on `_OpenAPIGeneratorCore`?
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,185 @@ +//===----------------------------------------------------------------------===// +// +// 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 move this to `TestUtilities.swift`? Could be useful elsewhere, and we already have some XCTAssert* utils there.
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -66,3 +72,40 @@ generate: additionalImports: - APITypes ``` + +### Document filtering + +The geneartor supports filtering the OpenAPI document prior to generation, which can be useful when
```suggestion The generator supports filtering the OpenAPI document prior to generation, which can be useful when ```
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -66,3 +72,40 @@ generate: additionalImports: - APITypes ``` + +### Document filtering + +The geneartor supports filtering the OpenAPI document prior to generation, which can be useful when +generating client code for a subset of a large API.
```suggestion generating client code for a subset of a large API, or splitting an implementation of a server across multiple modules. ```
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -66,3 +72,40 @@ generate: additionalImports: - APITypes ``` + +### Document filtering + +The geneartor supports filtering the OpenAPI document prior to generation, which can be useful when +generating client code for a subset of a large API. + +For example, to generate client code for only the operations with a...
```suggestion For example, to generate code for only the operations with a given tag, use the following config: ```
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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 think you actually want to use the function `validateDoc` from `validateDoc.swift`, which also takes the diagnostic collector and uses the same logic as the generation command. By default the `validate()` call contains a slightly different set of validations, and is overly strict about schema warnings.
swift-openapi-generator
github_2023
others
319
apple
czechboy0
@@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// 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...
Should we generate JSON if the user gave us JSON here?
swift-openapi-generator
github_2023
others
188
apple
czechboy0
@@ -16,7 +16,7 @@ "prioritizeKeepingFunctionOutputTogether" : false, "respectsExistingLineBreaks" : true, "rules" : { - "AllPublicDeclarationsHaveDocumentation" : false, + "AllPublicDeclarationsHaveDocumentation" :true,
```suggestion "AllPublicDeclarationsHaveDocumentation" : true, ``` Nit: whitespace.
swift-openapi-generator
github_2023
others
188
apple
czechboy0
@@ -23,16 +23,17 @@ REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" -git -C "${REPO_ROOT}" ls-files -z '*.swift' \ - | xargs -0 "${SWIFTFORMAT_BIN}" lint --parallel...
What was the issue with before? I think this would disable linting the Test and other directories, which I don't think we want. cc @simonjbeaumont
swift-openapi-generator
github_2023
others
188
apple
czechboy0
@@ -24,6 +24,7 @@ REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" git -C "${REPO_ROOT}" ls-files -z '*.swift' \ + | grep -z -v 'Tests/OpenAPIGeneratorReferenceTests/...
```suggestion | grep -z -v 'Tests/OpenAPIGeneratorReferenceTests/Resources' \ ``` And please also exclude and remove any changes to `Sources/swift-openapi-generator/Documentation.docc`, we don't want the tutorials to be affected. Otherwise will be ready to go.
swift-openapi-generator
github_2023
others
317
apple
czechboy0
@@ -5,7 +5,8 @@ services: image: &image swift-openapi-generator:22.04-5.9 build: args: - base_image: "swiftlang/swift:nightly-5.9-jammy" + ubuntu_version: "jammy"
Should we make this change in the 5.10 one as well?
swift-openapi-generator
github_2023
others
308
apple
czechboy0
@@ -103,6 +103,61 @@ extension TypesFileTranslator { ) ) bodyCases.append(bodyCase) + + var throwingGetterSwitchCases = [ + SwitchCaseDescription( + kind: .case(.identifier(".\(identifier)"), ["body"]), + ...
That's a good idea.
swift-openapi-generator
github_2023
others
308
apple
czechboy0
@@ -103,6 +103,61 @@ extension TypesFileTranslator { ) ) bodyCases.append(bodyCase) + + var throwingGetterSwitchCases = [ + SwitchCaseDescription( + kind: .case(.identifier(".\(identifier)"), ["body"]), + ...
```suggestion expression: .literal(.string(contentType.headerValueForValidation)) ``` While this is just for printing, `headerValueForValidation` is more appropriate as it doesn't include `charset`, which isn't used to match content types.
swift-openapi-generator
github_2023
others
308
apple
czechboy0
@@ -103,6 +103,61 @@ extension TypesFileTranslator { ) ) bodyCases.append(bodyCase) + + var throwingGetterSwitchCases = [ + SwitchCaseDescription( + kind: .case(.identifier(".\(identifier)"), ["body"]), + ...
```suggestion - Throws: An error if `self` is not `.\(identifier)`. ``` Since "runtime error" isn't a public type, I wouldn't mention it here.
swift-openapi-generator
github_2023
others
308
apple
czechboy0
@@ -73,7 +67,61 @@ extension TypesFileTranslator { ), .enumCase(enumCaseDesc) ) - return (responseStructDecl, enumCaseDecl) + + let throwingGetterDesc = VariableDescription( + accessModifier: config.access, + kind: .var, + left: enumCaseN...
I thought about this a bit, and I think you made the right choice. For ranges, the alternative choice would have been to return `(Int, BODY_TYPE)`, but I prefer just returning `BODY_TYPE`, and if the adopter wants the code, they need to switch manually.
swift-openapi-generator
github_2023
others
308
apple
czechboy0
@@ -73,7 +67,61 @@ extension TypesFileTranslator { ), .enumCase(enumCaseDesc) ) - return (responseStructDecl, enumCaseDecl) + + let throwingGetterDesc = VariableDescription( + accessModifier: config.access, + kind: .var, + left: enumCaseN...
```suggestion - Throws: An error if `self` is not `.\(enumCaseName)`. ``` Same as above.
swift-openapi-generator
github_2023
others
245
apple
simonjbeaumont
@@ -1087,9 +1087,9 @@ public enum Operations { /// - Remark: Generated from `#/paths/pets/stats/GET/responses/200/content/application\/json`. case json(Components.Schemas.PetStats) /// - Remark: Generated from `#/paths/pets/stats/GET/responses/200/content/t...
Just confirming, is `HTTPBody` the best we can do for `text/plain` in all cases?
swift-openapi-generator
github_2023
others
245
apple
simonjbeaumont
@@ -111,21 +103,8 @@ public extension Data { } } -public extension Request { - init( - path: String, - query: String? = nil, - method: HTTPMethod, - headerFields: [HeaderField] = [], - encodedBody: String - ) throws { - let body = Data(encodedBody.utf8) - s...
I'm not sure what value this provides, but if it's just part of tests we can leave it.
swift-openapi-generator
github_2023
others
245
apple
simonjbeaumont
@@ -12,9 +12,16 @@ // //===----------------------------------------------------------------------===// import XCTest +import HTTPTypes extension Operations.listPets.Output { static var success: Self { .ok(.init(headers: .init(My_hyphen_Response_hyphen_UUID: "abcd"), body: .json([]))) } } + +ex...
Didn't this land in a runtime SPI?
swift-openapi-generator
github_2023
others
245
apple
simonjbeaumont
@@ -0,0 +1,344 @@ +//===----------------------------------------------------------------------===// +// +// 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...
Just checking you meant to include this file, as most of the methods in it `fatalError()`.
swift-openapi-generator
github_2023
others
297
apple
czechboy0
@@ -99,6 +117,16 @@ extension _GenerateOptions { } do { let data = try Data(contentsOf: config) + let configAsString = String(data: data, encoding: .utf8) + + let yamlKeys = extractYamlKeys(yamlString: configAsString!)
```suggestion let configAsString = String(decoding: data, as: UTF8.self) let yamlKeys = extractYamlKeys(yamlString: configAsString) ```
swift-openapi-generator
github_2023
others
297
apple
czechboy0
@@ -29,4 +29,12 @@ struct _UserConfig: Codable { /// A set of features to explicitly enable. var featureFlags: FeatureFlags? + + static let codingKeysRawValues = Set(CodingKeys.allCases.map({ $0.rawValue }))
Please add a comment for the symbol.
swift-openapi-generator
github_2023
others
297
apple
czechboy0
@@ -86,7 +86,25 @@ extension _GenerateOptions { if !featureFlag.isEmpty { return Set(featureFlag) } - return Set(config?.featureFlags ?? []) + return config?.featureFlags ?? [] + } + + /// Extracts keys from a YAML string. + /// + /// - Parameter yamlString: The ...
I agree we need to extract the keys somehow, but I don't think we should try to write our own YAML parser here. Can you see if you can use the lower level Yams API to do the same? https://www.jpsim.com/Yams/Classes/Parser.html
swift-openapi-generator
github_2023
others
297
apple
czechboy0
@@ -86,7 +86,42 @@ extension _GenerateOptions { if !featureFlag.isEmpty { return Set(featureFlag) } - return Set(config?.featureFlags ?? []) + return config?.featureFlags ?? [] + } + + /// Extracts the top-level keys from a YAML string. + /// + /// - Parameter ya...
I think it's better to just let the error be thrown one level up, and there emit a ValidationError saying the config isn't valid and include the description of the error thrown by Yams. So you can remove the do/catch here.
swift-openapi-generator
github_2023
others
254
apple
gjcairo
@@ -305,24 +308,24 @@ A reminder that the exact spelling of integrating `HTTPBody` into the transport /// /// ## Consuming a body as a buffer /// If you need to collect the whole body before processing it, use one of -/// the convenience `collect` methods on `HTTPBody`. +/// the convenience initializers on the targe...
Tiny nit: you use this new initialiser here but I don't think it's included in the code snippet below.
swift-openapi-generator
github_2023
others
254
apple
gjcairo
@@ -470,71 +505,52 @@ extension HTTPBody { /// - Parameters: /// - string: A string to encode as bytes. /// - length: The total length of the body. - @inlinable public convenience init(string: some StringProtocol, length: Length) + @inlinable public convenience init(_ string: some StringProtoco...
Nit: extra "the" ```suggestion /// - Throws: `TooManyBytesError` if the sequence contains more ``` Also, isn't `body` more accurate here?
swift-openapi-generator
github_2023
others
283
apple
czechboy0
@@ -82,7 +93,8 @@ struct TestClient: APIProtocol { return try await block(input) } - typealias UploadAvatarForPetSignature = @Sendable (Operations.uploadAvatarForPet.Input) async throws -> Operations + typealias UploadAvatarForPetSignature = @Sendable (Operations.uploadAvatarForPet.Input) async th...
Please also add corresponding tests to Test_Client and Test_Server that ensures at runtime everything is correctly propagated.
swift-openapi-generator
github_2023
others
283
apple
czechboy0
@@ -113,6 +113,47 @@ paths: $ref: '#/components/schemas/Pet' '4XX': $ref: '#/components/responses/ErrorBadRequest' + /pets/create:
Let's simplify this to only test what we want to test here - url encoded request bodies. - remove X-Extra-Arguments from the request and response headers - remove the 400 response - make the success response be 204 and return no content at all
swift-openapi-generator
github_2023
others
283
apple
czechboy0
@@ -48,7 +48,8 @@ public struct Client: APIProtocol { try await client.send( input: input, forOperation: Operations.listPets.id, - serializer: { input in let path = try converter.renderedPath(template: "/pets", parameters: []) + serializer: { input in + ...
Could this be due to the swift-format version mismatch again? We'll upgrade at some point, but you'll likely need to revert this to pass CI :)
swift-openapi-generator
github_2023
others
280
apple
czechboy0
@@ -33,23 +33,29 @@ extension _Tool { outputDirectory: URL, isDryRun: Bool, diagnostics: any DiagnosticCollector - ) throws { + ) async throws { let docData: Data do { docData = try Data(contentsOf: doc) } catch { throw ValidationErro...
Can you make the YAML diagnostics collector thread-safe please? I think that's the only one that could encounter problems with this change.
swift-openapi-generator
github_2023
others
281
apple
czechboy0
@@ -23,6 +24,15 @@ swiftSettings.append( // Require `any` for existential types. .enableUpcomingFeature("ExistentialAny") ) + +// Strict concurrency is enabled in CI; use this environment variable to enable it locally. +if ProcessInfo.processInfo.environment["SWIFT_OPENAPI_STRICT_CONCURRENCY"].flatMap(Bool.i...
Do we need this one if we already have this one? https://github.com/apple/swift-openapi-generator/pull/281/files#diff-cae86870418d35877d5f11c0ea0b536fdec37236d6ea5c0951eec4723f508ccfR15
swift-openapi-generator
github_2023
others
274
apple
czechboy0
@@ -61,7 +61,7 @@ extension FileTranslator { guard let rawValue = anyValue as? Int else { throw GenericError(message: "Disallowed value for an integer enum '\(typeName)': \(anyValue)") } - let caseName = "_\(rawValue)" + ...
Thoughts on whether we should also make positive numbers spelled "p1" for consistency or keep the current "_1", @glbrntt @simonjbeaumont @gjcairo?
swift-openapi-generator
github_2023
others
266
apple
simonjbeaumont
@@ -27,7 +29,10 @@ func validateDoc(_ doc: ParsedOpenAPIRepresentation, config: Config) throws -> [ // block the generator from running. // Validation errors continue to be fatal, such as // structural issues, like non-unique operationIds, etc. - let warnings = try doc.validate(strict: false) + let...
Looks like we're opting into more than the default now? Is that now _more_ strict than before? Given we're emitting warnings for all of these, are there any more we can be enabling?
swift-openapi-generator
github_2023
others
130
apple
simonjbeaumont
@@ -122,7 +122,39 @@ func makeGeneratorPipeline( diagnostics: diagnostics ) }, - postTransitionHooks: [] + postTransitionHooks: [ + { doc in + + // Run OpenAPIKit's built-in validation. + try do...
Why not do it for all parts of `components`, rather than just the ones we use _today_? Otherwise I'd be concerned that we'd forget to update this as we move forward. If there's a reference cycle in the OpenAPI document provided to the generator then it's a wonky input regardless of whether we try to make use of _...
swift-openapi-generator
github_2023
others
130
apple
simonjbeaumont
@@ -122,7 +122,39 @@ func makeGeneratorPipeline( diagnostics: diagnostics ) }, - postTransitionHooks: [] + postTransitionHooks: [ + { doc in + + // Run OpenAPIKit's built-in validation. + try do...
Are we happy just surfacing the errors, as-is, from OpenAPIKit?
swift-openapi-generator
github_2023
others
89
apple
czechboy0
@@ -0,0 +1,52 @@ +# 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...
I'd like to see the map of special characters to names in this proposal, not just as a future direction. I like that you started without it, as it's simpler, but since this is a breaking change anyway, we might as well make the experience nicer for a hard-coded set of characters. I'd start with: +, -, #, and also take...
swift-openapi-generator
github_2023
others
89
apple
siemensikkema
@@ -56,18 +56,19 @@ fileprivate extension String { /// Returns a string sanitized to be usable as a Swift identifier. /// - /// For example, the string `$nake` would be returned as `_nake`, because - /// the dollar sign is not a valid character in a Swift identifier. + /// For example, the string `...
```suggestion /// So, it replaces such characters with their html entity equivalents or unicode hex representation, ```
swift-openapi-generator
github_2023
others
89
apple
siemensikkema
@@ -56,18 +56,19 @@ fileprivate extension String { /// Returns a string sanitized to be usable as a Swift identifier. /// - /// For example, the string `$nake` would be returned as `_nake`, because - /// the dollar sign is not a valid character in a Swift identifier. + /// For example, the string `...
```suggestion /// in case it’s not present in the `specialCharsMap`. It marks this replacement with `_` as a delimiter. ```
swift-openapi-generator
github_2023
others
236
apple
gjcairo
@@ -143,21 +182,25 @@ struct ContentType: Hashable { "\(lowercasedType)/\(lowercasedSubtype)" } - /// Returns the type and subtype as a "<type>\/<subtype>" string. + /// Returns the type and subtype as a "<type>\/<subtype>[;<param>...]" string.
Small nit: maybe worth updating to something like this? ```suggestion /// Returns the type, subtype and parameters (if present) as a "<type>\/<subtype>[;<param>...]" string. ```
swift-openapi-generator
github_2023
others
236
apple
glbrntt
@@ -39,6 +39,10 @@ final class Test_ContentSwiftName: Test_Core { // Generic names. ("application/myformat+json", "application_myformat_plus_json"), ("foo/bar", "foo_bar"), + + // Names with a parameter. + ("application/foo", "application_foo"), + ...
Is it worth testing that additional whitespace is handled too? e.g. `"application/foo; bar = baz"`?
swift-openapi-generator
github_2023
others
237
apple
czechboy0
@@ -1,6 +1,6 @@ # Converting between data and Swift types -Learn about the type responsible for convertering between binary data and Swift types.
`convertering` 😆
swift-openapi-generator
github_2023
others
237
apple
czechboy0
@@ -6,7 +6,7 @@ Learn about the internals of Swift OpenAPI Generator. Swift OpenAPI Generator contains multiple moving pieces, from the runtime library, to the generator CLI, plugin, to extension packages using the transport and middleware APIs. -Use the resources below if you'd like to learn more about how the ge...
`contribututing` 😆 wow these are gems
swift-openapi-generator
github_2023
others
225
apple
glbrntt
@@ -124,55 +124,71 @@ extension FileTranslator { discriminator: OpenAPI.Discriminator?, schemas: [JSONSchema] ) throws -> Declaration { - // > When using the discriminator, inline schemas will not be considered. - // > — https://spec.openapis.org/oas/v3.0.3#discriminator-object - ...
Might be worth referencing the 3.1.x docs now
swift-openapi-generator
github_2023
others
219
apple
Kyle-Ye
@@ -1,4 +1,4 @@ -openapi: "3.0.3"
Since we are supporing both 3.0.x and and 3.1, maybe add a new petstore_3_1.yaml file and a new test case while keeping the original 3.0.3 test case is better IMO.
swift-openapi-generator
github_2023
others
219
apple
Kyle-Ye
@@ -104,7 +112,7 @@ extension Diagnostic { static func openAPIVersionError(versionString: String, location: Location) -> Diagnostic { return error( message: - "Unsupported document version: \(versionString). Please provide a document with OpenAPI versions in the 3.0.x set.", + ...
When the user accidentally uses the non-existent version 3.0.4, the error message here may be confusing.
swift-openapi-generator
github_2023
others
219
apple
glbrntt
@@ -4,9 +4,9 @@ Learn which OpenAPI features are supported by Swift OpenAPI Generator. ## Overview -Swift OpenAPI Generator is currently focused on supporting [OpenAPI 3.0.3][0]. +Swift OpenAPI Generator is currently focused on supporting [OpenAPI 3.0.3][0] and [OpenAPI 3.1.0][1].
The yams parser suggests `3.0.{0,1,2}` are also supported. Should they be listed here as well? More generally how good are OpenAPI document vendors at switching to newer versions?
swift-openapi-generator
github_2023
others
219
apple
glbrntt
@@ -155,7 +155,7 @@ Supported features are always provided on _both_ client and server. - [x] description - [x] format - [ ] default -- [ ] nullable +- [ ] nullable (only in 3.0, removed in 3.1)
Does this mean the types generated from a 3.0.x document prior to this change will be different to that of the same document after this change as it's converted to 3.1.x first?
swift-openapi-generator
github_2023
others
201
apple
gjcairo
@@ -0,0 +1,265 @@ +# SOAR-0003: Type-safe Accept headers + +Generate a dedicated Accept header enum for each operation. + +## Overview + +- Proposal: SOAR-0003 +- Author(s): [Honza Dvorsky](https://github.com/czechboy0), [Si Beaumont](https://github.com/simonjbeaumont) +- Status: **Awaiting Review** +- Issue: [apple/sw...
Nit: now that https://github.com/apple/swift-openapi-generator/pull/205 has been merged, this has/will become kind of irrelevant - does it make sense to have this reference to `undocumented` here?
swift-openapi-generator
github_2023
others
185
apple
gjcairo
@@ -1066,8 +1066,48 @@ public enum Operations { } public var query: Operations.getStats.Input.Query public struct Headers: Sendable, Equatable, Hashable { + public enum AcceptableContentType: AcceptableProtocol { + case json + c...
Should we consider all types ending in `+json` as JSON too?
swift-openapi-generator
github_2023
others
185
apple
glbrntt
@@ -1066,8 +1066,48 @@ public enum Operations { } public var query: Operations.getStats.Input.Query public struct Headers: Sendable, Equatable, Hashable { + public enum AcceptableContentType: AcceptableProtocol { + case json + c...
FWIW I think just using the type directly is clearer for the caller.
swift-openapi-generator
github_2023
others
185
apple
glbrntt
@@ -61,6 +67,48 @@ final class Test_Client: XCTestCase { } } + func testGetStats_200_text_customAccept() async throws { + transport = .init { request, baseURL, operationID in + XCTAssertEqual(operationID, "getStats") + XCTAssertEqual(request.path, "/pets/stats") + ...
This feels backwards, I'd expect to specify the content type and then it's q-factor.
swift-openapi-generator
github_2023
others
185
apple
gjcairo
@@ -0,0 +1,216 @@ +//===----------------------------------------------------------------------===// +// +// 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 document that, if absent, we won't generate unknown cases?
swift-openapi-generator
github_2023
others
208
apple
gjcairo
@@ -72,3 +72,56 @@ MyOpenOneOf: - #/components/schemas/Baz - type: object ``` + +### Server-sent Events/EventSource + +While [Server-sent Events](https://en.wikipedia.org/wiki/Server-sent_events) are not explicitly part of the OpenAPI 3.0 or 3.1 specification, you can document an operation that returns S...
```suggestion > Important: Until [async bodies](https://github.com/apple/swift-openapi-generator/issues/9) are supported in Swift OpenAPI Generator, SSE are of limited value, as bodies are fully buffered before being returned to the caller. ```
swift-openapi-generator
github_2023
others
196
apple
czechboy0
@@ -43,7 +43,11 @@ extension TypesFileTranslator { } else { associatedDeclarations = [] } + + let comment: Comment? = parent.docCommentWithUserDescription(nil, + subPath: "\(parameter.location.rawValue)/\(pa...
```suggestion let comment: Comment? = parent.docCommentWithUserDescription( nil, subPath: "\(parameter.location.rawValue)/\(parameter.name)" ) ``` Nit: whitespace
swift-openapi-generator
github_2023
others
196
apple
czechboy0
@@ -41,6 +41,7 @@ extension TypesFileTranslator { /// - Returns: A list of declarations; empty if the request body is /// unsupported. func requestBodyContentCases( + typeName: TypeName,
```suggestion ``` You shouldn't need to pass this type in, it's already present on `requestBody.typeUsage.typeName`.
swift-openapi-generator
github_2023
others
196
apple
czechboy0
@@ -54,13 +55,20 @@ extension TypesFileTranslator { } let identifier = contentSwiftName(content.content.contentType) let associatedType = content.resolvedTypeUsage - let contentCase: Declaration = .enumCase( - .init( + + let subPath...
```suggestion .enumCase( ``` I think we have a utility function on `Declaration` that allows passing in the parameters directly, don't we?
swift-openapi-generator
github_2023
others
196
apple
czechboy0
@@ -131,7 +139,8 @@ extension TypesFileTranslator { requestBody: TypedRequestBody ) throws -> Declaration { let type = requestBody.typeUsage.typeName - let members = try requestBodyContentCases(for: requestBody) + let members = try requestBodyContentCases(typeName: type, + ...
```suggestion let members = try requestBodyContentCases(for: requestBody) ``` As commented above, I don't think we need to pass it in, the type name should already be present on `requestBody`.
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 = "",
```suggestion responseKind: ResponseKind, ``` If the response kind is needed, pass it in as the typesafe type `ResponseKind` and don't provide a default value, we want to make sure all callers are updated.
swift-openapi-generator
github_2023
others
196
apple
czechboy0
@@ -34,10 +35,19 @@ extension TypesFileTranslator { inParent: headersTypeName ) let headerProperties: [PropertyBlueprint] = try headers.map { header in - try parseResponseHeaderAsProperty(for: header) + try parseResponseHeaderAsProperty( + responseKind...
```suggestion : "responses/\(responseKind)/headers" ``` Typo