Skip to content

Body parameters with inline schema definitions are not rendered properly #1133

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
davazp opened this issue Apr 9, 2015 · 12 comments
Closed
Assignees
Milestone

Comments

@davazp
Copy link

davazp commented Apr 9, 2015

The following path is not rendered correctly. The data type shows undefined instead of the model/schema. It will work if I replace the schema definition for a $ref

  /companies/{id}:
    patch:
      parameters:
        - name: id
          type: integer
          in: path
        - name: company
          in: body
          schema:
            type: object
            properties:
              Favorite:
                type: boolean

      summary: Update a company
      responses:
        200:
          desription: Successful response
      tags: [companies]
@webron webron added this to the v2.1 milestone Apr 9, 2015
@webron
Copy link
Contributor

webron commented Apr 9, 2015

Confirmed bug in master.

@pglezen
Copy link

pglezen commented Apr 10, 2015

I have confirmed this also, FWIW.

@Smolations
Copy link

I ran into this issue today, I think. Will the merged fix referenced above from the swagger-js project also fix property refs? In the following situation, the model/model schema are missing in the UI:

Global definition in swaggerConfig.definitions:

// ...
"media_experiment": {
    "type": "object",
    "required": [],
    "properties": {
        "name": {
            "type": "string"
        },
        "src": {
            "type": "string"
        },
        "media_file": {
            "properties": {
                "file_type": {
                    "type": "string"
                },
                "base64": {
                    "type": "string"
                }
            },
            "type": "object"
        },
        "media_ids": {
            "type": "array",
            "items": {
                "type": "integer",
                "format": "int32"
            }
        },
        "media_array": {
            "type": "array",
            "items": {
                "description": "Media model",
                "required": ["id"],
                "properties": {
                    "id": {
                        "type": "integer",
                        "description": "Media's id",
                        "format": "int32"
                    },
                    "name": {
                        "type": "string",
                        "description": "Media's name"
                    },
                    "description": {
                        "type": "string",
                        "description": "Media's description"
                    },
                    "caption": {
                        "type": "string",
                        "description": "Media's caption"
                    }
                },
                "type": "object"
            }
        },
        "custom_array": {
            "type": "array",
            "items": {
                "properties": {
                    "foo": {
                        "type": "string"
                    },
                    "bar": {
                        "type": "string"
                    }
                },
                "type": "object"
            }
        }
    }
},
// ...

In the Operation object:

// ...
"parameters": [{
    "name": "body",
    "in": "body",
    "schema": {
        "properties": {
            "media": {
                "$ref": "#/definitions/media_experiment"
            }
        },
        "type": "object"
    }
}],
// ...

As @davazp Mentioned, if I remove the nested schema for the body param and instead reference the "media_experiment" ref directly on the schema property in the param, the ref is resolved. Unfortunately, I need the ref to be nested under the "media" key I have defined.

Or maybe I have a malformed json config lol...

@Smolations
Copy link

Btw, I am using the dist files from develop_2.0 as of yesterday.

@ponelat
Copy link
Contributor

ponelat commented Apr 28, 2015

@Smolations the fix is in swagger-js at the moment, it'll take some time to see it in swagger-ui, which relies on the npm module of swagger-js.

If you like, I can show you how I build the bleeding edge swagger-ui. Otherwise it'll be in a release soon.

@webron
Copy link
Contributor

webron commented Apr 28, 2015

Shouldn't be a problem to build it. @ponelat - please provide with the details.

@ponelat
Copy link
Contributor

ponelat commented Apr 28, 2015

to build from latest sources...
make sure you've checked out the latest swagger-ui and swagger-js. The latest being the develop_2.0 branches on both repos.

Here's a quick recap for a fresh start...

cd /some/where

git clone https://github.com/swagger-api/swagger-ui
cd ./swagger-ui
git checkout develop_2.0

# go back up a folder, as we were in ./swagger-ui
cd ..

git clone https://github.com/swagger-api/swagger-js
cd ./swagger-js
git checkout develop_2.0

Now you should have fresh copies of the good stuff. If you already had the repos cloned, just run git pull and make sure you're on the develop_2.0 branch.

For the fun bit (isn't debugging fun :) )
inside the swagger-ui folder, you need to change the gulpfile a little.

Look for this line...
https://github.com/swagger-api/swagger-ui/blob/master/gulpfile.js#L59

...
      gulp.src([
        './src/main/javascript/**/*.js',
        './node_modules/swagger-client/browser/swagger-client.js' // <------ This line
...   

And change it to something like this...

...
      gulp.src([
        './src/main/javascript/**/*.js',
        '../swagger-js/browser/swagger-client.js' // <------ This must point to the repo we cloned above
...   

Now you're good to build....

cd /some/where/swagger-js
npm install
gulp build

cd ../swagger-ui
npm install
gulp

Voila!

That felt way.... too long for something so simple. Which means I'm going to try and make this a feature in swagger-ui.
where we run this...

# This would be easier, no?
gulp --client-path=../swagger-js/browser/swagger-client.js

@webron, should we make this feature a reality?

@webron
Copy link
Contributor

webron commented Apr 28, 2015

what feature?

@ponelat
Copy link
Contributor

ponelat commented Apr 28, 2015

@webron, the feature to build from the edge sources.
Instead of changing the line in the gulp file, we make it an optional command line parameter.

@webron
Copy link
Contributor

webron commented Apr 28, 2015

That's probably better for @fehguy / @mohsen1 / @whitlockjc to reply.

@fehguy
Copy link
Contributor

fehguy commented Apr 28, 2015

@ponelat I agree this is kinda nasty. I think adding a commandline param is fine, it'll probably be used by swagger-ui developers only, which is fine by me!

@Smolations
Copy link

Thanks guys, that is GREAT info!

And btw, for anyone else reading, the manual build totally worked!

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

6 participants