Skip to content

[All] Still having a problem generating code w/ latest parser + external ref's #4103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaz-ah opened this issue Oct 31, 2016 · 18 comments
Closed
Milestone

Comments

@jaz-ah
Copy link
Contributor

jaz-ah commented Oct 31, 2016

Description

When I use a json schema with external file references, ever since the swagger parser was moved up from 1.0.19, I get empty models throughout my generated code.

Swagger-codegen version

Trying latest code from @fehguy 's update to parser.

Swagger declaration file content or url

I tried simplifying this down to an easy reproducible problem -

FooAPI.json:

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "FooAPI",
        "description": "API for all accesses to the Foo server system",
        "termsOfService": "TBD",
        "contact": {
            "name": "Foo API Team"
        },
        "license": {
            "name": "MIT"
        }
    },
    "host": "api.foo.com",
    "basePath": "",
    "schemes": [
        "https"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/bar": {
            "$ref":"./Bar.json#/bar"
        }
    },
    "definitions": {
        "BarSettingsRequest": {
	    "$ref":"./Bar.json#/definitions/BarSettingsRequest"
	},
        "BarData": {
	    "$ref":"./Bar.json#/definitions/BarData"
	}
    }
}

Bar.json:

{
    "bar": {
        "post": {
            "description": "posts stuff",
            "deprecated": true,
            "operationId": "enrollInBar",
            "produces": [
                         "application/json"
                         ],
            "parameters": [{
                           "name": "Authorization",
                           "in": "header",
                           "required": true,
                           "type": "string"
                           }, {
                           "name": "barRequest",
                           "in": "body",
                           "description": "The request body containing the amount",
                           "required": true,
                           "schema": {
                           "$ref": "#/definitions/BarSettingsRequest"
                           }
                           }],
            "responses": {
                "200": {
                    "schema": {
                        "$ref": "#/definitons/BarData"
                    }
                },
                "default": {
                }
            }
        }
    },
    "definitions": {
        "BarSettingsRequest": {
            "properties": {
                "stuff": {
                    "type": "integer"
                }
            },
            "required": [
                         "stuff"
                         ]
        },
        "BarData": {
            "properties": {
                "enabled": {
                    "type": "boolean"
                }
            }
        }
    }
}

when running this in swift3 for example, the output for BarData.swift looks like:

//
// BarData.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation


public typealias BarData = 

and the output of BarSettingsRequest.swift is:

//
// BarSettingsRequest.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation


public typealias BarSettingsRequest = 

whereas with the 1.0.19 parser, I get :

BarData.swift:

//
// BarData.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation


open class BarData: JSONEncodable {
    public var enabled: Bool?

    public init(enabled: Bool?=nil) {
        self.enabled = enabled
    }

    // MARK: JSONEncodable
    func encodeToJSON() -> Any {
        var nillableDictionary = [String:Any?]()
        nillableDictionary["enabled"] = self.enabled
        let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
        return dictionary
    }
}

BarSettingsRequest.swift:

//
// BarSettingsRequest.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation


open class BarSettingsRequest: JSONEncodable {
    public var stuff: Int

    public init(stuff: Int) {
        self.stuff = stuff
    }

    // MARK: JSONEncodable
    func encodeToJSON() -> Any {
        var nillableDictionary = [String:Any?]()
        nillableDictionary["stuff"] = self.stuff.encodeToJSON()
        let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
        return dictionary
    }
}
@jaz-ah
Copy link
Contributor Author

jaz-ah commented Oct 31, 2016

@fehguy I was hoping your parser update to 1.0.23-SNAPSHOT would help but it still produces the issue above - 1.0.19 was the last version of the parser that worked for me. Is everything valid with my json definitions above?

@fehguy
Copy link
Contributor

fehguy commented Oct 31, 2016

@jaz-ah it looks valid--are you sure you're testing from master on swagger-codegen to pick up the correct parser?

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Oct 31, 2016

@fehguy yup definitely - here is the bottom of pom.xml from latest master that i'm using:

    <properties>
        <swagger-parser-version>1.0.23-SNAPSHOT</swagger-parser-version>
        <scala-version>2.11.1</scala-version>
        <felix-version>2.3.4</felix-version>
        <swagger-core-version>1.5.10</swagger-core-version>
        <commons-io-version>2.4</commons-io-version>
        <commons-cli-version>1.2</commons-cli-version>
        <junit-version>4.8.1</junit-version>
        <maven-plugin-version>1.0.0</maven-plugin-version>
        <commons-lang-version>3.4</commons-lang-version>
        <slf4j-version>1.7.12</slf4j-version>
        <scala-maven-plugin-version>3.2.1</scala-maven-plugin-version>
        <jmustache-version>1.12</jmustache-version>
        <testng-version>6.9.6</testng-version>
        <surefire-version>2.19.1</surefire-version>
        <jmockit-version>1.25</jmockit-version>
        <reflections-version>0.9.10</reflections-version>
    </properties>

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Oct 31, 2016

same happens w/ swift and android languages...

@fehguy
Copy link
Contributor

fehguy commented Nov 1, 2016

OK I have reproduced this. Looks like the issue is having relative definitions in a remote path reference, which isn't something that was tested in 1.0.23 of the parser. I'll open a new issue and hopefully it's another easy fix.

PS you have definitions spelled incorrectly in your Bar.json file.

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Nov 1, 2016

no problem thx @fehguy

@wing328 wing328 added this to the v2.2.2 milestone Nov 2, 2016
@fehguy
Copy link
Contributor

fehguy commented Nov 2, 2016

Hi @jaz-ah I think this is fixed. Please pull master, which grabs swagger-parser-1.0.24-SNAPSHOT. Your test files generate and compile fine now.

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Nov 2, 2016

ok i'll give it a try in a minute - thx!

@fehguy
Copy link
Contributor

fehguy commented Nov 2, 2016

great, thanks

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Nov 2, 2016

hmm.. @fehguy for some reason i checked out master, verified pom.xml is using 1.0.24-SNAPSHOT, rebuilt and I still see the same problem... i cleaned/etc... then tried switching pom.xml to 1.0.19 and verified the problem went away... is snapshot definitely updated to the latest fix?

@fehguy
Copy link
Contributor

fehguy commented Nov 2, 2016

I've redeployed the snapshot. Can you run mvn clean package -U on the top-level codegen project?

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Nov 3, 2016

@fehguy ok did that, tried again and same issue...
//
// BarData.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation

public typealias BarData =

are you getting the same for BarData.swift if you generate swift3?

@fehguy
Copy link
Contributor

fehguy commented Nov 3, 2016

Here's my output:

//
// BarData.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation


open class BarData: JSONEncodable {
    public var enabled: Bool?

    public init() {}

    // MARK: JSONEncodable
    open func encodeToJSON() -> Any {
        var nillableDictionary = [String:Any?]()
        nillableDictionary["enabled"] = self.enabled
        let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
        return dictionary
    }
}

I built it like this (serving your test files on localhost:8000):

java -jar ./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://localhost:8080/swagger.json -o test -l swift3

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Nov 3, 2016

@fehguy the difference is I'm not serving test files on my localhost, I'm referencing them directly:

java -jar ./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ../activehours_apis-jaz/spec-server/public/specs/FooAPI.json -o test -l swift3

would this make a difference?

@fehguy
Copy link
Contributor

fehguy commented Nov 3, 2016

@jaz-ah do you work at Active Hours? If so, our office is 1/2 block from you and we can probably sort this out in person :)

It works fine from file-system for me:

java -jar ~/dev/projets/swagger-api/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ./jaz/swagger.json -o foo -l swift3
$ cat foo/SwaggerClient/Classes/Swaggers/Models/BarData.swift 
//
// BarData.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Foundation


open class BarData: JSONEncodable {
    public var enabled: Bool?

    public init() {}

    // MARK: JSONEncodable
    open func encodeToJSON() -> Any {
        var nillableDictionary = [String:Any?]()
        nillableDictionary["enabled"] = self.enabled
        let dictionary: [String:Any] = APIHelper.rejectNil(nillableDictionary) ?? [:]
        return dictionary
    }
}

@jaz-ah
Copy link
Contributor Author

jaz-ah commented Nov 3, 2016

@fehguy yup I do - where are you @?

@fehguy
Copy link
Contributor

fehguy commented Nov 3, 2016

437 kipling 2nd floor. If you want to come by, we can work this out in person

@wing328
Copy link
Contributor

wing328 commented Feb 17, 2017

I believe this has been addressed. Please reply to let us know if that's not the case.

@wing328 wing328 closed this as completed Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants