Add soundness, generate-contributors scripts

This commit is contained in:
Adam Fowler 2023-05-14 10:56:38 +02:00
parent 9804387fd1
commit f581c5533a
13 changed files with 490 additions and 58 deletions

58
.swift-format Normal file
View File

@ -0,0 +1,58 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentation" : {
"spaces" : 4
},
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : true,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 120,
"maximumBlankLines" : 1,
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : false,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : false,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : false,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : false,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : true,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 8,
"version" : 1
}

View File

@ -1,26 +0,0 @@
# Minimum swiftformat version
--minversion 0.47.4
# Swift version
--swiftversion 5.3
# file options
--exclude .build
# rules
--disable redundantReturn, extensionAccessControl
# format options
--ifdef no-indent
--nospaceoperators ...,..<
--patternlet inline
--self insert
--stripunusedargs unnamed-only
#--maxwidth 150
--wraparguments before-first
--wrapparameters before-first
--wrapcollections before-first
#file header
# --header "//===----------------------------------------------------------------------===//\n//\n// This source file is part of the Hummingbird server framework project\n//\n// Copyright (c) {created.year}-{year} the Hummingbird authors\n// Licensed under Apache License v2.0\n//\n// See LICENSE.txt for license information\n// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors\n//\n// SPDX-License-Identifier: Apache-2.0\n//\n//===----------------------------------------------------------------------===//"

18
CONTRIBUTORS.txt Normal file
View File

@ -0,0 +1,18 @@
For the purpose of tracking copyright, this is the list of individuals and
organizations who have contributed source code to SwiftOpenAPIGenerator.
For employees of an organization/company where the copyright of work done
by employees of that company is held by the company itself, only the company
needs to be listed here.
## COPYRIGHT HOLDERS
- Apple Inc. (all contributors with '@apple.com')
### Contributors
- Adam Fowler <adamfowler71@gmail.com>
**Updating this list**
Please do not edit this file manually. It is generated using `./scripts/generate-contributors-list.sh`. If a name is misspelled or appearing multiple times: add an entry in `./.mailmap`

View File

@ -80,7 +80,9 @@ extension HBRequest {
func makeOpenAPIRequestMetadata() -> ServerRequestMetadata {
let keyAndValues = self.parameters.map { (key: String($0.0), value: String($0.1)) }
let openAPIParameters = [String: String](keyAndValues) { first, _ in first }
let openAPIQueryItems = self.uri.queryParameters.map { URLQueryItem(name: String($0.key), value: String($0.value)) }
let openAPIQueryItems = self.uri.queryParameters.map {
URLQueryItem(name: String($0.key), value: String($0.value))
}
return .init(
pathParameters: openAPIParameters,
queryParameters: openAPIQueryItems

View File

@ -1,19 +1,23 @@
import Hummingbird
import HummingbirdXCT
@testable import OpenAPIHummingbird
import OpenAPIRuntime
import XCTest
@testable import OpenAPIHummingbird
final class HBOpenAPITransportTests: XCTestCase {
func test_makeHummingbirdPath() throws {
XCTAssert(function: HBOpenAPITransport.makeHummingbirdPath(from:), behavesAccordingTo: [
([], ""),
([.constant("hello")], "hello"),
([.constant("hello"), .constant("world")], "hello/world"),
([.constant("hello"), .parameter("name")], "hello/${name}"),
([.parameter("greeting"), .constant("world")], "${greeting}/world"),
([.parameter("greeting"), .parameter("name")], "${greeting}/${name}"),
])
XCTAssert(
function: HBOpenAPITransport.makeHummingbirdPath(from:),
behavesAccordingTo: [
([], ""),
([.constant("hello")], "hello"),
([.constant("hello"), .constant("world")], "hello/world"),
([.constant("hello"), .parameter("name")], "hello/${name}"),
([.parameter("greeting"), .constant("world")], "${greeting}/world"),
([.parameter("greeting"), .parameter("name")], "${greeting}/${name}"),
]
)
}
func test_requestConversion() async throws {
@ -26,7 +30,7 @@ final class HBOpenAPITransportTests: XCTestCase {
query: "greeting=Howdy",
method: .post,
headerFields: [
.init(name: "X-Mumble", value: "mumble"),
.init(name: "X-Mumble", value: "mumble")
],
body: Data("👋".utf8)
)
@ -42,7 +46,7 @@ final class HBOpenAPITransportTests: XCTestCase {
let response = Response(
statusCode: 201,
headerFields: [
.init(name: "X-Mumble", value: "mumble"),
.init(name: "X-Mumble", value: "mumble")
],
body: Data("👋".utf8)
)
@ -66,26 +70,32 @@ final class HBOpenAPITransportTests: XCTestCase {
}
func testHTTPMethodConversion() throws {
XCTAssert(function: Hummingbird.HTTPMethod.init(_:), behavesAccordingTo: [
(.get, .GET),
(.put, .PUT),
(.post, .POST),
(.delete, .DELETE),
(.options, .OPTIONS),
(.head, .HEAD),
(.patch, .PATCH),
(.trace, .TRACE),
])
XCTAssert(function: OpenAPIRuntime.HTTPMethod.init(_:), behavesAccordingTo: [
(.GET, .get),
(.PUT, .put),
(.POST, .post),
(.DELETE, .delete),
(.OPTIONS, .options),
(.HEAD, .head),
(.PATCH, .patch),
(.TRACE, .trace),
])
XCTAssert(
function: Hummingbird.HTTPMethod.init(_:),
behavesAccordingTo: [
(.get, .GET),
(.put, .PUT),
(.post, .POST),
(.delete, .DELETE),
(.options, .OPTIONS),
(.head, .HEAD),
(.patch, .PATCH),
(.trace, .TRACE),
]
)
XCTAssert(
function: OpenAPIRuntime.HTTPMethod.init(_:),
behavesAccordingTo: [
(.GET, .get),
(.PUT, .put),
(.POST, .post),
(.DELETE, .delete),
(.OPTIONS, .options),
(.HEAD, .head),
(.PATCH, .patch),
(.TRACE, .trace),
]
)
}
}

View File

@ -0,0 +1,37 @@
#!/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 v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)"
log "Checking for broken symlinks..."
NUM_BROKEN_SYMLINKS=0
while read -r -d '' file; do
if ! test -e "${REPO_ROOT}/${file}"; then
error "Broken symlink: ${file}"
((NUM_BROKEN_SYMLINKS++))
fi
done < <(git -C "${REPO_ROOT}" ls-files -z)
if [ "${NUM_BROKEN_SYMLINKS}" -gt 0 ]; then
fatal "❌ Found ${NUM_BROKEN_SYMLINKS} symlinks."
fi
log "✅ Found 0 symlinks."

View File

@ -0,0 +1,40 @@
#!/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 v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
log "Checking required environment variables..."
test -n "${DOCC_TARGET:-}" || fatal "DOCC_TARGET unset"
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)"
swift package --package-path "${REPO_ROOT}" plugin generate-documentation \
--product "${DOCC_TARGET}" \
--analyze \
--level detailed \
--warnings-as-errors \
&& DOCC_PLUGIN_RC=$? || DOCC_PLUGIN_RC=$?
if [ "${DOCC_PLUGIN_RC}" -ne 0 ]; then
fatal "❌ Generating documentation produced warnings and/or errors."
exit "${DOCC_PLUGIN_RC}"
fi
log "✅ Generated documentation with no warnings."

View File

@ -0,0 +1,37 @@
#!/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 v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)"
UNACCEPTABLE_LANGUAGE_PATTERNS_PATH="${CURRENT_SCRIPT_DIR}/unacceptable-language.txt"
log "Checking for unacceptable language..."
PATHS_WITH_UNACCEPTABLE_LANGUAGE=$(git -C "${REPO_ROOT}" grep \
-l -F -w \
-f "${UNACCEPTABLE_LANGUAGE_PATTERNS_PATH}" \
-- \
":(exclude)${UNACCEPTABLE_LANGUAGE_PATTERNS_PATH}" \
) || true | /usr/bin/paste -s -d " " -
if [ -n "${PATHS_WITH_UNACCEPTABLE_LANGUAGE}" ]; then
fatal "❌ Found unacceptable language in files: ${PATHS_WITH_UNACCEPTABLE_LANGUAGE}."
fi
log "✅ Found no unacceptable language."

View File

@ -0,0 +1,100 @@
#!/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 v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)"
EXPECTED_FILE_HEADER_TEMPLATE="@@===----------------------------------------------------------------------===@@
@@
@@ This source file is part of the SwiftOpenAPIGenerator open source project
@@
@@ Copyright (c) YEARS Apple Inc. and the SwiftOpenAPIGenerator project authors
@@ Licensed under Apache License v2.0
@@
@@ See LICENSE.txt for license information
@@ See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
@@
@@ SPDX-License-Identifier: Apache-2.0
@@
@@===----------------------------------------------------------------------===@@"
PATHS_WITH_MISSING_LICENSE=( )
read -ra PATHS_TO_CHECK_FOR_LICENSE <<< "$( \
git -C "${REPO_ROOT}" ls-files -z \
":(exclude).gitignore" \
":(exclude).spi.yml" \
":(exclude).swift-format" \
":(exclude).github/*" \
":(exclude)CODE_OF_CONDUCT.md" \
":(exclude)CONTRIBUTING.md" \
":(exclude)CONTRIBUTORS.txt" \
":(exclude)LICENSE.txt" \
":(exclude)NOTICE.txt" \
":(exclude)Package.swift" \
":(exclude)Package.resolved" \
":(exclude)README.md" \
":(exclude)SECURITY.md" \
":(exclude)scripts/unacceptable-language.txt" \
":(exclude)Tests/PetstoreConsumerTests/Generated" \
":(exclude)Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/*" \
":(exclude)docker/*" \
":(exclude)**/*.docc/*" \
":(exclude)**/.gitignore" \
":(exclude)**/Package.swift" \
":(exclude)**/Package.resolved" \
":(exclude)**/README.md" \
":(exclude)**/openapi.yaml" \
":(exclude)**/petstore.yaml" \
":(exclude)**/openapi-generator-config.yaml" \
| xargs -0 \
)"
for FILE_PATH in "${PATHS_TO_CHECK_FOR_LICENSE[@]}"; do
FILE_BASENAME=$(basename -- "${FILE_PATH}")
FILE_EXTENSION="${FILE_BASENAME##*.}"
case "${FILE_EXTENSION}" in
swift) EXPECTED_FILE_HEADER=$(sed -e 's|@@|//|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}") ;;
yml) EXPECTED_FILE_HEADER=$(sed -e 's|@@|##|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}") ;;
sh) EXPECTED_FILE_HEADER=$(cat <(echo '#!/usr/bin/env bash') <(sed -e 's|@@|##|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}")) ;;
*) fatal "Unsupported file extension for file (exclude or update this script): ${FILE_PATH}" ;;
esac
EXPECTED_FILE_HEADER_LINECOUNT=$(wc -l <<<"${EXPECTED_FILE_HEADER}")
FILE_HEADER=$(head -n "${EXPECTED_FILE_HEADER_LINECOUNT}" "${FILE_PATH}")
NORMALIZED_FILE_HEADER=$(
echo "${FILE_HEADER}" \
| sed -e 's/202[3]-202[3]/YEARS/' -e 's/202[3]/YEARS/' \
)
if ! diff -u \
--label "Expected header" <(echo "${EXPECTED_FILE_HEADER}") \
--label "${FILE_PATH}" <(echo "${NORMALIZED_FILE_HEADER}")
then
PATHS_WITH_MISSING_LICENSE+=("${FILE_PATH} ")
fi
done
if [ "${#PATHS_WITH_MISSING_LICENSE[@]}" -gt 0 ]; then
fatal "❌ Found missing license header in files: ${PATHS_WITH_MISSING_LICENSE[*]}."
fi
log "✅ Found no files with missing license header."

View File

@ -0,0 +1,52 @@
#!/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 v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -eu
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
contributors=$( cd "$here"/.. && git shortlog -es | cut -f2 | sed 's/^/- /' )
cat > "$here/../CONTRIBUTORS.txt" <<- EOF
For the purpose of tracking copyright, this is the list of individuals and
organizations who have contributed source code to SwiftOpenAPIGenerator.
For employees of an organization/company where the copyright of work done
by employees of that company is held by the company itself, only the company
needs to be listed here.
## COPYRIGHT HOLDERS
- Apple Inc. (all contributors with '@apple.com')
### Contributors
$contributors
**Updating this list**
Please do not edit this file manually. It is generated using \`./scripts/generate-contributors-list.sh\`. If a name is misspelled or appearing multiple times: add an entry in \`./.mailmap\`
EOF

View File

@ -0,0 +1,45 @@
#!/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 v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
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"
"${SWIFTFORMAT_BIN}" lint \
--parallel --recursive --strict \
"${REPO_ROOT}/Examples" \
"${REPO_ROOT}/IntegrationTests" \
"${REPO_ROOT}/Plugins" \
"${REPO_ROOT}/Sources" \
"${REPO_ROOT}/Tests" \
&& SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then
fatal "❌ Running swift-format produced errors.
To fix, run the following command:
% swift-format format --parallel --recursive --in-place Examples IntegrationTests Plugins Sources Tests
"
exit "${SWIFT_FORMAT_RC}"
fi
log "✅ Ran swift-format with no errors."

44
scripts/soundness.sh Executable file
View File

@ -0,0 +1,44 @@
#!/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 v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
NUM_CHECKS_FAILED=0
export DOCC_TARGET=swift-openapi-generator
SCRIPT_PATHS=(
"${CURRENT_SCRIPT_DIR}/check-for-broken-symlinks.sh"
"${CURRENT_SCRIPT_DIR}/check-for-unacceptable-language.sh"
"${CURRENT_SCRIPT_DIR}/check-license-headers.sh"
"${CURRENT_SCRIPT_DIR}/run-swift-format.sh"
"${CURRENT_SCRIPT_DIR}/check-for-docc-warnings.sh"
)
for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do
log "Running ${SCRIPT_PATH}..."
if ! bash "${SCRIPT_PATH}"; then
((NUM_CHECKS_FAILED+=1))
fi
done
if [ "${NUM_CHECKS_FAILED}" -gt 0 ]; then
fatal "${NUM_CHECKS_FAILED} soundness check(s) failed."
fi
log "✅ All soundness check(s) passed."

View File

@ -0,0 +1,15 @@
blacklist
whitelist
slave
master
sane
sanity
insane
insanity
kill
killed
killing
hang
hung
hanged
hanging