yonaskolb / SwagGen

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

API.Server.main not found #197

Closed haemi closed 3 years ago

haemi commented 4 years ago

my openapi.yml file has a server entry at the end:

servers:
- url: http://localhost:8080/
  description: Local development version

which leads to the following APIClient.swift:

public static var `default` = APIClient(baseURL: API.Server.main)

This gives the compiler error Type 'API' has no member 'Server'. Is this a bug in SwagGen oder is something missing in my openapi.yml?

zntfdr commented 4 years ago

I have encountered the same issue.

In my case the servers are right after info on the top of the .yml file:

openapi: 3.0.1
info:
  title: ...
  description: ...
  version: ...
servers:
- url: http://...
...

I haven't looked at SwagGen implementation, but replacing "API.Server.main" with the actual url fixes the issue:

public static var `default` = APIClient(baseURL: "http://...")
Lucien commented 4 years ago

I found that without specifying tags, servers won't show.

VitaliyZaharenko commented 3 years ago

Hi i have the same problem. I found that in the template file API.swift the {% if tags%} block is closed at the end of the file, so it turns out that the server code is generated only if there are tags. Perhaps this was done on purpose? I found a diff of a commit that looks like a random bug when refactoring and copying code https://github.com/yonaskolb/SwagGen/commit/950f667f9b1c8af428c53fd461320a4a273ce0b8#diff-5fd3bee400cfc6aadd6d9d1b798792be

syeutyu commented 3 years ago

I fixed it!