-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generating client for Weather.gov API fails to generate compilable code #135
Comments
Hi @zabelc, thanks for filing the issue with this great detail! The The other issues we'll need a bit more time to look into, I'll update this issue as we identify what features we're missing, and where we're tracking them. |
Hi @czechboy0, I'm not sure about the relationship between the YAML & JSON parsers, but I get the same Zone error above with JSON as well, and I was able to work around the error in the same fashion, by changing the original JSON from the original definition (below) to the simplified definition (further down). Original JSON:
Simplified JSON:
Unfortunately, I get the same 2 compilation errors. Just to help with troubleshooting, I'm attaching the openapi.yaml file (with the commented out lines), as well as the original and edited openapi.json files with the changes above. |
Thanks for all this detail, @zabelc – I took another look. Unfortunately, with build errors, I don't know how many blockers remain. The current ones are:
The first one you were able to work around by folding in the enum, but the second one will need to get fixed in the generator. Once it's resolved, we'll be able to move onto the next blocker. Thanks for your help here 🙏 |
Thank you for looking into these issues, @czechboy0! I saw Xcode was updated to Beta 5 & this openapi-generator to 0.16, so I took another stab at the weather service openapi definition, I was able to get it to compile...but I had to comment out many operations. I also discovered a new (to me) issue wherein the generator has a problem with an object type definition that contains two fields with similar names: Error 1: on "try await client.send(" To get around this I simply removed the following operations: It strikes me that the generator issue may be due to the fact that the various versions of URL's for the operations above are similar, but have parameters embedded in the URL which aren't being handled carefully enough in generation: i.e. the generator should be adding additional type casting annotations to these methods. This obvious with respect to /offices/, but there are several variations on the /alerts/ and /stations/ paths as well. (It's easy to see a consolidated list of similar paths under the "Specification" tab at the Weather.gov API Documentation Page). Error 2: Instance method 'setQueryItemAsText(in:name:value:)' requires that 'Components.Schemas.ISO8601Interval' conform to '_StringConvertible' I believe you covered this in #144. I worked around it by commenting out the following operations: NEW: Error 3: Invalid redeclaration of '_type' in Zone with Protocol Conformance Issues It appears that because the Zone object definition contains both
Here is the definition of the zone object:
I can work around and get everything to compile, by commenting out one definition for "_type" either:
or:
As long as only one of the above definitions are in the spec, the generated Zone struct will be fine. I've attached my working openapi.yaml file: Underlying issue with handling "type" fields in API object definitions It appears that additional logic needs to be added to generated field names in this instance. I was unable to find any open issues similar to this problem, so this seems to be a new issue. |
Well, you're in luck, because SOAR-0001 just recently landed under a feature flag, and it should address the issue with name collisions! You can try it by adding this to your config file:
Let me know if that at least helps with the collisions! It'll become the default behavior in 0.2.0 |
Hi @CzechBoy, I saw there was a 0.18 version update, so I decided to take another look at the WeatherA API. I can confirm that the SOAR-0001 featureFlag took care of the type collisions and the planned approach in that proposal looks good (though I have to admit that I was unaware that "@" is referred to as "commat"). (Actually, this worked in 0.16 last Friday, but I didn't get a chance to write that up before today.) After re-processing the API I've discovered a couple errors, and a runtime problem that I can't work around:
1. #118 didn't succeed in fixing my "Disallowed value for a string enum"I hate to say it but, #118 didn't fix the Zone problem above. As a reminder this spec defines a
Unless I change it to a simple $ref, the openapi-generator crashes saying:
You would know better, but the behavior here is actually crashes the generator before it can generate any code (My "Generated Sources" directory is empty) FWIW, I worked around this issue in the same way as previously. Three brand new types of errors relating to a type made up of oneOf two enumsI'm seeing a some brand new errors where the compiler is trying to convert instances of various codes to a Version 1
This occurs in two operations: Operation 1:
Operation 2:
Both /alerts & /alerts/active contain similar opanapi.yaml Parameters Definitions:
AlertArea is defined as:
Version 2
This occurs in three different operations: Operation 1
Operation 2:
Operation 3:
The YAML defines the state as follows:
The YAML defines the AreaCode as:
Where StateTerritoryCode, and MarineAreaCode are separate enum's of two character strings. I was able to work around this by replacing the AreaCode with the following definition:
Version 3
Like AreaCode is
I'm not sure why this wasn't caught in the first compilation, but I worked around it in the same way as the AreaCode ###4. Runtime API calls fail because fields were skipped during generation Although I can comment-out parts of the API and get compilable code, the generated code breaks at runtime because numerous fields are skipped during generation, which results in DecodingErrors when the service returns those unsupported fields. (In fairness, 0.16 had 176 unsupported feature warnings, and 0.18 now has just 96, so it's definitely improving) Could be a way to configure the generated code to ignore unexpected/unsupported fields? This could be at build time via a featureFlag, or at runtime via configuration on the Client. One particularly troubling instance is that most responses of the Weather API feature an
The generator produces the following warning (30 times):
The In this case, I wonder if |
Hi @zabelc,
Yes, that only got fixed earlier today, but the fix hasn't been released yet, but you can try with the generator on the
I got a WIP PR for that up which I hope to land tomorrow: #179 The issue with a query parameter that is an array of a oneOf, where each schema is a string enum, which is tracked by #144, which hasn't been started yet. Thanks for checking every new version and for your patience, we'll get there 🙂 |
Thanks for your patience, @zabelc - I just confirmed that with Swift OpenAPI Generator 0.1.13, the Weather.gov OpenAPI document produces compiling code. Note that you'll need to enable all these feature flags, e.g. in your featureFlags:
- proposal0001
- multipleContentTypes
- strictOpenAPIValidation
- closedEnumsAndOneOfs They will become the default in the upcoming 0.2.0 as well, at which point you won't need to explicitly specify them. But you should be unblocked now, please file new issues if you find anything else. |
In a new swift project in Xcode Version 15.0 beta 4 (15A5195m), using swift-openapi-generator 0.15 I was attempting to generate a client for the Weather.gov API; however, this fails in a couple ways:
1. Spec contains unsupported enum features
Generating a client fails with both Json version of the spec: https://api.weather.gov/openapi.json and the YAML version of the spec: https://api.weather.gov/openapi.yaml
Either way, the build fails with the following error:
Workaround
I was able to work around this issue after reading the solution to Issue #102, and reading through the currently supported features: https://swiftpackageindex.com/apple/swift-openapi-generator/0.1.5/documentation/swift-openapi-generator/supported-openapi-features
Based on the currently supported features & the diff solution to Issue #102, I simplified the Zone yaml definition as follows
2. The resulting client contains numerous compilation errors
With the modified openapi.yaml file above, I was able to generate a client successfully, but the Client.swift.txt had two types of compilation errors:
try await client.send(
error: Type of expression is ambiguous without more contextError 1:
try await client.send(
error: Type of expression is ambiguous without more contextThis occurred for the following operations:
Error 2: Instance method 'setQueryItemAsText(in:name:value:)' requires that 'Components.Schemas.ISO8601Interval' conform to '_StringConvertible'
Which occurs for the following operations:
Based on some initial analysis, I don't believe any of the generated code is using the Zone datatypes, so I believe that the workaround above is unrelated to these compilation errors.
The text was updated successfully, but these errors were encountered: