Giter Club home page Giter Club logo

Comments (22)

yonaskolb avatar yonaskolb commented on July 17, 2024

@bharathreddy-97 which version of Xcode are you using? This project requires Swift 3.1 (Xcode 8.3)

from swaggen.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

oh ok I will update Xcode(currently using 8.2.1) and check it. Thank you for the fast response

from swaggen.

yonaskolb avatar yonaskolb commented on July 17, 2024

No problem. Let me know if you have any other trouble, or if the generated API for your spec has any problems

from swaggen.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

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.

bharathreddy-97 avatar bharathreddy-97 commented on July 17, 2024

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.

yonaskolb avatar yonaskolb commented on July 17, 2024

@bharathreddy-97, just so you know the UKNOWN type for responses containing enums has been fixed in master 👍

from swaggen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.