Skip to content

Base Model properties are not resolved when extended #666

@kendzi

Description

@kendzi

I fall down into the same problem as described in swagger-api/swagger-ui#1723 I try to debug it and I think the problem is with swagger-js not the ui. Here I created simple junit test (in resolver.js):

  it('base model properties', function(done) {

        var api = new Resolver();
        var spec = {
          swagger:'2.0',
          info:{    
          },
          host:"localhost:9000",
          schemes:[
            "http"
          ],
          basePath:"/2.0",
          paths:{
            '/':{
              get:{
                responses:{
                  "200":{
                    description:"Pets",
                    schema:{
                      "$ref":"#/definitions/Pet"
                    }
                  }
                },
                parameters:[
                ]
              }
            }
          },
          definitions:{    
            Cat:{
              allOf: [
                {
                  "$ref": "#/definitions/Pet"
                }, 
                {
                  type: "object",
                  properties:{
                    size:{
                      type: "number"
                    }
                  }
                }
              ]
            },
            Pet:{  
              type: "object",    
              properties:{       
                color:{
                  "$ref":"#/definitions/Color"
                }
              }
            },
            Color:{
              "type": "string"
            }
          }
        };
        api.resolve(spec, 'http://localhost:8000/v2/swagger.json', function (spec, unresolved) {

          expect(spec.definitions.Pet.properties.color['$ref']).toBe('#/definitions/Color');
          expect(spec.definitions.Cat.properties.color['$ref']).toBe('#/definitions/Color');

          done();
        });
    });

It fails because method as the result returns values like: "http://localhost:8000/v2/swagger.json#/definitions/Color".
I'm expecting here to get "#/definitions/Color" even if it is used by "inline" object. Is it right assumption?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions