Skip to content

Commit

Permalink
feat: add swift support
Browse files Browse the repository at this point in the history
  • Loading branch information
sashatalalasha committed Jan 17, 2024
1 parent ba31715 commit ce11dbb
Show file tree
Hide file tree
Showing 4 changed files with 19,442 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@ FROM openjdk:15-buster

RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates ssh bash

RUN apt-get -y install libncurses5 clang libcurl4 libpython2.7 libpython2.7-dev

RUN apt-get -y install libxml2

RUN \
curl https://download.swift.org/swift-5.9.2-release/ubuntu1804/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-ubuntu18.04.tar.gz -o swift.tar.gz &&\
tar xzf swift.tar.gz && \
mv swift-5.9.2-RELEASE-ubuntu18.04 /usr/share/swift && \
export PATH=/usr/share/swift/usr/bin:$PATH && \
swift -v

ENV PATH /usr/share/swift/usr/bin:$PATH

RUN git clone https://github.com/apple/swift-openapi-generator.git \
&& cd swift-openapi-generator \
&& swift build \
&& ln -s .build/debug/swift-openapi-generator /usr/local/bin/swift-openapi-generator \
&& swift-openapi-generator --help

RUN git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew \
&& mkdir ~/.linuxbrew/bin \
&& ln -s ../Homebrew/bin/brew ~/.linuxbrew/bin \
&& eval $(~/.linuxbrew/bin/brew shellenv) \
&& brew --version

ENV GOLANG_VERSION 1.17

RUN set -eux; \
Expand Down
26 changes: 26 additions & 0 deletions contrib/clients/swift/CustomDateTranscoder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation
import OpenAPIRuntime

/// A transcoder for dates encoded as an ISO-8601 string (in RFC 3339 format). Allows date with internet date time and fractional seconds.
public struct CustomDateTranscoder: DateTranscoder, @unchecked Sendable {

/// Creates and returns an ISO 8601 formatted string representation of the specified date.
public func encode(_ date: Date) throws -> String {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
return formatter.string(from: date) }

/// Creates and returns a date object from the specified ISO 8601 formatted string representation.
public func decode(_ dateString: String) throws -> Date {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
print(dateString)
guard let date = formatter.date(from: dateString) else {
throw DecodingError.dataCorrupted(
.init(codingPath: [], debugDescription: "Expected date string to be ISO8601-formatted.")
)
}
return date
}
}

Loading

0 comments on commit ce11dbb

Please sign in to comment.