Skip to content
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

Got '&errors.errorString{s:"child url is nil"}' when expanding spec. #14

Closed
pengsrc opened this issue Nov 3, 2016 · 2 comments
Closed

Comments

@pengsrc
Copy link
Contributor

pengsrc commented Nov 3, 2016

Here's my swagger json files.

api_v2.0.json

{
  "swagger": "2.0",
  "info": {
    "version": "2016-01-01",
    "title": "Test",
    "license": {
      "name": "The Apache License (Version 2)",
      "url": "https://www.apache.org/licenses/LICENSE-2.0"
    }
  },
  "paths": {
    "/TestAction0": {
      "$ref": "./action.json#/TestAction0"
    },
    "/TestAction1": {
      "get": {
        "operationId": "TestAction1",
        "summary": "TestAction1",
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "type": "object",
              "properties": {
                "action": {
                  "type": "string"
                },
                "ret_code": {
                  "type": "integer"
                },
                "data_set": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/data"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "data": {
      "type": "object",
      "properties": {
        "data_id": {
          "type": "string"
        },
        "data_name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      }
    }
  }
}

action.json

{
  "TestAction0": {
    "get": {
      "tags": [
        "Action"
      ],
      "operationId": "TestAction0",
      "summary": "TestAction0",
      "responses": {
        "200": {
          "description": "OK",
          "schema": {
            "type": "object",
            "properties": {
              "action": {
                "type": "string"
              },
              "ret_code": {
                "type": "integer"
              },
              "total_count": {
                "type": "integer"
              },
              "data_set": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/data"
                }
              }
            }
          }
        }
      }
    }
  }
}

I have also tried '"$ref": "http://127.0.0.1:9292/action.json#/TestAction0"', but same error.

@pengsrc
Copy link
Contributor Author

pengsrc commented Nov 3, 2016

Below is my test code.

package main

import (
    "testing"

    "github.com/go-openapi/loads"
    "github.com/stretchr/testify/assert"
)

func TestSpec(t *testing.T) {
    swagger, err := loads.Spec("/tmp/swagger/api_v2.0.json")
    assert.Nil(t, err)

    swaggerExpanded, err := swagger.Expanded()
    assert.Nil(t, err)
}

Got.

Error:      Expected nil, but got: &errors.errorString{s:"child url is nil"}

@pengsrc
Copy link
Contributor Author

pengsrc commented Nov 3, 2016

Hi, I submitted two pull request to fix this problem.


spec.ExpandOptions was added to provide configurations for expanding, currently there is only one option to use.

type ExpandOptions struct {
    RelativeBase string
}

RelativeBase is the base location to use when resolving relative references. If this value is not given, the working directory (os.Getwd()) will be used as RelativeBase.


Example:

package main

import (
    "testing"

    "github.com/go-openapi/loads"
    "github.com/stretchr/testify/assert"
)

func TestSpec(t *testing.T) {
    swagger, err := loads.Spec("/tmp/swagger/api_v2.0.json")
    assert.Nil(t, err)

    swaggerExpanded, err := swagger.Expanded(&spec.ExpandOptions{
        RelativeBase: "/tmp/swagger",
    })
    assert.Nil(t, err)
}

@pengsrc pengsrc changed the title Got '&errors.errorString{s:"child url is nil"}' when expand spec. Got '&errors.errorString{s:"child url is nil"}' when expanding spec. Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants