apple / swift-openapi-generator

Generate Swift client and server code from an OpenAPI document.
https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
Apache License 2.0
1.21k stars 87 forks source link

empty: Kick CI #555

Closed simonjbeaumont closed 1 month ago

simonjbeaumont commented 1 month ago

Motivation

[Explain here the context, and why you're making that change. What is the problem you're trying to solve.]

Modifications

[Describe the modifications you've made.]

Result

[After your change, what will change.]

Test Plan

[Describe the steps you took, or will take, to qualify the change - such as adjusting tests and manual testing.]

simonjbeaumont commented 1 month ago

OK, some of these tests are failing. Here's one example from the above CI run:

Test Case 'CompatibilityTest.testDiscourse' started at 2024-03-28 07:23:56.460
CompatibilityTest.testDiscourse Warning: Compatility test running in debug mode
CompatibilityTest.testDiscourse Downloading OpenAPI document: https://raw.githubusercontent.com/discourse/discourse_api_docs/fa2391353e9c3eb016ccae30daa34467d2ac2616/openapi.yml
CompatibilityTest.testDiscourse Generating Swift code (document size: 401 KB)
/code/Tests/OpenAPIGeneratorReferenceTests/CompatabilityTest.swift:258: error: CompatibilityTest.testDiscourse : failed - unexpected error openapi.yaml: error: Found neither a JSONType nor a Array<JSONType> in .content['application/json'].schema.properties.score.type for the status code '200' response of the **GET** endpoint under `/posts/{id}.json`. 

JSONType could not be decoded because:
Inconsistency encountered when parsing `[unknown object]`: Cannot initialize JSONType from invalid String value .

Array<JSONType> could not be decoded because:
Expected value to be parsable as Sequence but it was not.. thrown
/code/Tests/OpenAPIGeneratorReferenceTests/CompatabilityTest.swift:258: error: CompatibilityTest.testDiscourse : failed - unexpected error openapi.yaml: error: Found neither a JSONType nor a Array<JSONType> in .content['application/json'].schema.properties.score.type for the status code '200' response of the **GET** endpoint under `/posts/{id}.json`. 

JSONType could not be decoded because:
Inconsistency encountered when parsing `[unknown object]`: Cannot initialize JSONType from invalid String value .

Array<JSONType> could not be decoded because:
Expected value to be parsable as Sequence but it was not.. thrown
/code/Tests/OpenAPIGeneratorReferenceTests/CompatabilityTest.swift:258: error: CompatibilityTest.testDiscourse : failed - unexpected error openapi.yaml: error: Found neither a JSONType nor a Array<JSONType> in .content['application/json'].schema.properties.score.type for the status code '200' response of the **GET** endpoint under `/posts/{id}.json`. 

JSONType could not be decoded because:
Inconsistency encountered when parsing `[unknown object]`: Cannot initialize JSONType from invalid String value .

Array<JSONType> could not be decoded because:
Expected value to be parsable as Sequence but it was not.. thrown
<EXPR>:0: error: CompatibilityTest.testDiscourse : threw error "openapi.yaml: error: Found neither a JSONType nor a Array<JSONType> in .content['application/json'].schema.properties.score.type for the status code '200' response of the **GET** endpoint under `/posts/{id}.json`. 

JSONType could not be decoded because:
Inconsistency encountered when parsing `[unknown object]`: Cannot initialize JSONType from invalid String value .

Array<JSONType> could not be decoded because:
Expected value to be parsable as Sequence but it was not.."
Test Case 'CompatibilityTest.testDiscourse' failed (2.535 seconds)

This is weird because I can run this locally just fine:

Test Case '-[OpenAPIGeneratorReferenceTests.CompatibilityTest testDiscourse]' started.
-[CompatibilityTest testDiscourse] Warning: Compatility test running in debug mode
-[CompatibilityTest testDiscourse] Downloading OpenAPI document: https://raw.githubusercontent.com/discourse/discourse_api_docs/fa2391353e9c3eb016ccae30daa34467d2ac2616/openapi.yml
-[CompatibilityTest testDiscourse] Generating Swift code (document size: 401 KB)
-[CompatibilityTest testDiscourse] Creating Swift package: /var/folders/06/__qdhxzn7ld3_bsvfcfz0kch0000gn/T/swift-openapi-compatibility-test-testDiscourse-5522BF90
-[CompatibilityTest testDiscourse] Building Swift package: ["swift", "build", "--package-path", "/var/folders/06/__qdhxzn7ld3_bsvfcfz0kch0000gn/T/swift-openapi-compatibility-test-testDiscourse-5522BF90", "-Xswiftc", "-Xllvm", "-Xswiftc", "-vectorize-slp=false"]
-[CompatibilityTest testDiscourse] Finished compatibility test
Test Case '-[OpenAPIGeneratorReferenceTests.CompatibilityTest testDiscourse]' passed (55.272 seconds).
czechboy0 commented 1 month ago

This is weird because I can run this locally just fine:

Are you using the same resolved Yams version locally as the CI? I suspect that's where the mismatch might be.

simonjbeaumont commented 1 month ago

This is weird because I can run this locally just fine:

Are you using the same resolved Yams version locally as the CI? I suspect that's where the mismatch might be.

This was my thought exactly. And it made me wonder whether we should be checking in Package.resolved for this project, given its main utility is as leaf executable. Which got me further wondering whether that would be honoured when being consumed as a Swift package plugin.

In the meantime, let me try and work out what versions of the dependencies are running in CI.

simonjbeaumont commented 1 month ago

In the meantime, let me try and work out what versions of the dependencies are running in CI.

+ swift test --filter OpenAPIGeneratorReferenceTests.CompatibilityTest
...
Working copy of https://github.com/apple/swift-openapi-runtime resolved at 1.3.2
Working copy of https://github.com/apple/swift-docc-symbolkit resolved at 1.0.0
Working copy of https://github.com/apple/swift-algorithms resolved at 1.2.0
Working copy of https://github.com/jpsim/Yams resolved at 5.1.0
Working copy of https://github.com/apple/swift-docc-plugin resolved at 1.3.0
Working copy of https://github.com/mattpolzin/OpenAPIKit resolved at 3.1.3
Working copy of https://github.com/apple/swift-numerics.git resolved at 1.0.2
Working copy of https://github.com/apple/swift-argument-parser resolved at 1.3.1
Working copy of https://github.com/apple/swift-http-types resolved at 1.0.3
...
simonjbeaumont commented 1 month ago

I hadn't realised that Package.resolved wasn't checked in. Once I realised that it was not, I am able to reproduce the failure locally after a swift package update.

simonjbeaumont commented 1 month ago

I hadn't realised that Package.resolved wasn't checked in. Once I realised that it was not, I am able to reproduce the failure locally after a swift package update.

And, I can confirm that the following restriction in Package.swift restored working behaviour:

-        .package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"6.0.0"),
+        .package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"5.1.0"),
simonjbeaumont commented 1 month ago

Latest release of Yams, 4 days ago, has the following in the release notes^1:

Change how empty strings are decoded into nullable properties.

@czechboy0 I'm just catching up on #553, which appears to cover this exact issue.

czechboy0 commented 1 month ago

Yeah, we'll need to dig into this. Based on Matt's comments, the new behavior seems to be the correct behavior, so it's possible we've been silently skipping/ignoring some other syntax errors in OpenAPI documents that now will emit a warning/error diagnostic.

czechboy0 commented 1 month ago

Superseded by https://github.com/apple/swift-openapi-generator/pull/561