yonaskolb / SwagGen

OpenAPI/Swagger 3.0 Parser and Swift code generator
MIT License
626 stars 146 forks source link

SplitMode for SPM Package #232

Closed mackoj closed 3 years ago

mackoj commented 4 years ago

This is another try at https://github.com/yonaskolb/SwagGen/pull/225.

TL;DR

This change nothing to all actual users of Swaggen. It add the support of splitting the generated code for SPM user only and only if they want to. This is the first step to remove Alamofire. It allow to run generated code on Linux if you only use the request and model targets. And finally it add dynamic library support when using SPM.

What have been done

This PR is focus to mainly focus to split in SPM the generated code into 4 part:

├── Client
│   ├── APIClient.swift
│   └── RequestBehaviour.swift
├── Models
│   ├── APIModel.swift
│   ├── AnyCodable.swift
│   ├── Coding.swift
│   ├── Enum.swift
│   └── Model.swift
├── Requests
│   ├── API.swift
│   ├── APIRequest.swift
│   ├── APIResponse.swift
│   ├── APIService.swift
│   ├── AnyRequest.swift
│   └── Request.swift
└── SharedCode
    ├── APIClientError.swift
    └── APIResult.swift
    └── Timeline.swift

Why

I did these changes because:

Remarks

I don't think this should be another template because it doesn’t change the main template it make it more flexible.

Point of interest to the reviewer

In order to make everything works I have to make createURLRequest but it worked with Alamofire so I needed to import the relevant part from Alamofire to make it work. I did copy the Alamofire Timeline file in order to keep the feature.

Todo after review (in order to not clutter the main work of this PR)

I hope it helps.

mackoj commented 4 years ago

Update from #230 modifications.

mackoj commented 4 years ago

Rebase for #239