Skip to content

Generating client for Weather.gov API fails to generate compilable code #135

@zabelc

Description

@zabelc

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. Part of the spec contains currently unsupported enum features (though I was able work around this)
  2. The resulting client contains numerous compilation errors

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:

Error: Disallowed value for a string enum 'Components.Schemas.Zone.statePayload.Case2Payload (#/components/schemas/Zone/state/case2)': ()
LLVM Profile Error: Failed to write file "default.profraw": Operation not permitted

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

    Zone:
        state:
          $ref: '#/components/schemas/StateTerritoryCode' # added
#          oneOf:
#            -
#              $ref: '#/components/schemas/StateTerritoryCode'
#            -
#              enum:
#                - ''
#              type: string
#              nullable: true

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:

  1. try await client.send( error: Type of expression is ambiguous without more context
  2. Instance method 'setQueryItemAsText(in:name:value:)' requires that 'Components.Schemas.ISO8601Interval' conform to '_StringConvertible

Error 1: try await client.send( error: Type of expression is ambiguous without more context
This occurred for the following operations:

Generated from `#/paths//alerts/active/area/{area}/get(alerts_active_area)`.
Generated from `#/paths//aviation/cwsus/{cwsuId}/cwas/{date}/{sequence}/get(cwa)`.
Generated from `#/paths//aviation/sigmets/{atsu}/{date}/get(sigmetsByATSUByDate)`.
Generated from `#/paths//aviation/sigmets/{atsu}/{date}/{time}/get(sigmet)`.
Generated from `#/paths//stations/{stationId}/observations/{time}/get(station_observation_time)`.
Generated from `#/paths//stations/{stationId}/tafs/{date}/{time}/get(taf)`.
Generated from `#/paths//offices/{officeId}/get(office)`.
Generated from `#/paths//offices/{officeId}/headlines/{headlineId}/get(office_headline)`.
Generated from `#/paths//offices/{officeId}/headlines/get(office_headlines)`.

Error 2: Instance method 'setQueryItemAsText(in:name:value:)' requires that 'Components.Schemas.ISO8601Interval' conform to '_StringConvertible'

Which occurs for the following operations:

Generated from `#/paths//radar/queues/{host}/get(radar_queue)`.
Generated from `#/paths//radar/profilers/{stationId}/get(radar_profiler)`.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/openapiAdding/updating a feature defined in OpenAPI.kind/bugFeature doesn't work as expected.status/blockedWaiting for another issue.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions