Comments (22)
@bharathreddy-97 which version of Xcode are you using? This project requires Swift 3.1 (Xcode 8.3)
from swaggen.
oh ok I will update Xcode(currently using 8.2.1) and check it. Thank you for the fast response
from swaggen.
No problem. Let me know if you have any other trouble, or if the generated API for your spec has any problems
from swaggen.
I updated the xcode and tried. I generated xcodeproj but where should i run the command. I tried it in terminal(where .xcodeproj is generated) but i am getting SwagGen: command not found. Am i missing something?
I tried running Swaggen project. I was getting "Must provide a valid spec" in console. Where can i pass these from? I am new so please bear with me
from swaggen.
Run these two commands in the root of the repo
swift build
.build/debug/SwagGen --template Templates/Swift
For the second command append your spec and destination arguments
Let me know if you have any more trouble
from swaggen.
Thank you. I finally generated files but in other way to your suggestion. I opened .xcodeproj and in the main.swift i added paths in the command at the bottom. Thank you for replying.
One last thing how can i add prefix to model names like in Swagger we use "--model-name-prefix prefixName".
from swaggen.
I added source folder to my project(added JSONUtilities and Alamofire to my project) but was getting some compile error in one of the classes Requests folder. Below is the error
Use of undeclared type 'UNKNOWN'
json corresponding to that api
"/v1/types": {
"get": {
"operationId": "getTypes",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "param1",
"in": "query",
"required": true,
"type": "integer",
"minimum": 1.0,
"format": "int64"
},
{
"name": "param2",
"in": "query",
"description": "Session Parameter - Branch Id",
"required": true,
"type": "integer",
"format": "int64"
},
{
"name": "param3",
"in": "query",
"description": "Session Parameter - Academic Session Id",
"required": true,
"type": "integer",
"format": "int64"
},
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"type": "string",
"enum": [
"Day",
"Session",
"Period"
]
}
},
"headers": {
}
}
}
}
}
from swaggen.
If you're using a the xcode project to run the command, it's best to specify the paths as scheme arguments by editing the scheme.
In which generated file is the UNKNOWN?
from swaggen.
There's no inbuilt model prefixing, but you can change the model.swift
in the template and add the prefix there.
If you want to make the prefix dynamic you can put {{ options.modelPrefix }}
in model.swift
and then specify the model prefix in the options in the template.yml file or by passing it in as an argument: --option modelPrefix:MyPrefix
from swaggen.
Actually, thinking about it some more, just changing the model name as above wouldn't work, as all the references to it would be broken.
Another way if you want to edit the code would be to add the prefix in CodeFormatter.getSchemaType()
from swaggen.
I got Unknown type in one of the generated files in Request folder. The exact line is
extension API {
public class GetTypes: APIRequest<[UNKNOWN]> { -----> Here I am getting compile time error
from swaggen.
I actually had another major issue. For one of the Swagger json when i generated the files some of the filesnames are same which is throwing compile time error in xcode. How are you generating those files(naming) in the Requests folder?
from swaggen.
The request names are generated using the operationId of each operation. If non exists one is generated using the method type and path (can be ugly though).
Is it possible for you to share the swagger spec you are trying to generate?
The latest 0.5.2 release may also fix something
from swaggen.
Then this is the problem. In my Swagger json there are more than one operation with same operationId. What can i do in that case? Can i make use of description, summary params? Sorry I cannot give you the Swagger spec(organisation policy)
from swaggen.
Oh ok, that's not really to spec then, and SwagGen doesn't support it. Quoting the Swagger Spec:
Unique string used to identify the operation. The id MUST be unique among all operations described in the API. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to follow common programming naming conventions
from swaggen.
If you can't change the operationId's for some reason, you can change the code here to always automatically generate an operationId https://github.com/yonaskolb/SwagGen/blob/master/Sources/SwagGenKit/CodeFormatter.swift#L84
from swaggen.
I have asked my server guys to use seperate operationIds for each operation. There was a request where i have to pass a string in body but it is a enhancement right? What about that first Issue about that Type?
Just curious what is that {{ }} syntax you used for code generating? Is that syntax available in swift or what is it? I searched in the net but could not find much on it. I could only find other code-generators using it. Does it have a name or where can i learn it?
from swaggen.
Issue #21 is outstanding. I may be able to get around to it soon. Feel free to also create any pull requests though. Are you able to post an obfuscated version of your request with a string body?
The UNKNOWN type issue seems to be a bug where arrays of anonymous enums are not supported as return types. In this case it can't find what the name of the enum should be, which even a human would have trouble figuring out. I guess I'll just called it Enum
. That should be an easier fix.
In terms of the {{ }}, see the readme. It explains that that is the https://github.com/kylef/Stencil format
from swaggen.
I tried sending String in the body but I got a error saying outer most body type should be JSON type or something like that.
from swaggen.
Can you please share a version of your full operation spec where you send a string body. You can change the names if you like
from swaggen.
Just check this one. I have trimmed the json. I actually had another error but was able to solve that error by changing Request template. There was empty Body struct creating which was not conforming JSONValueEncodable and because of it body?.encode() was throwing error. I fixed it by conforming it and implementing encode in that body struct.
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "Spring Boot + Jersey + Swagger + Docker Example",
"contact": {
"name": "Orlando L Otero"
}
},
"host": "hostUrl",
"basePath": "/basePathUrl",
"schemes": [
"http",
"https"
],
"paths": {
"/v1/somePath/someuri": {
"post": {
"operationId": "opId",
"consumes": [
"text/plain"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "opId",
"in": "cookie",
"required": false,
"type": "string"
},
{
"in": "body",
"name": "body",
"required": false,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"description": "successful operation"
}
}
}
}
},
"definitions": {
}
}
from swaggen.
@bharathreddy-97, just so you know the UKNOWN
type for responses containing enums has been fixed in master 👍
from swaggen.
Related Issues (20)
- illegal hardware instruction swaggen generate HOT 1
- Issue with swagger_2 Xcode 13
- Send multiple requests
- Default language "swift" doesn't work on Linux due to case sensitivity HOT 4
- Enum type ignores modelsuffix HOT 1
- "description" aka doc comments don't get generated nicely
- segmentation fault when attempting to generate from spec that contains `allOf` groups HOT 5
- The spec yaml files in this repo fail lots of Swagger validations
- Too many cases generated when oneOf discriminator has explicit mappings
- oneOf does not generate cases when the type is object HOT 2
- You don’t have permission to save the file “security” in the folder “org.swift.swiftpm” HOT 4
- Issue with decoding when element is nullable array
- SwagGen doesn't process the media type application/json;charset=UTF8
- Version 4.7.0 not available on brew due to failed GH Action HOT 5
- Could not install HOT 3
- [macOS Ventura, Xcode 14.2, M1 Pro] Get an error when install SwagGen HOT 1
- Comparison with OpenAPI generator HOT 1
- When enum case is unrecognised and `enumUndecodableCase`=true, how can I know the value?
- Any plans for async\await from URLSession?
- is development over? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swaggen.