swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[Spring][Java] Bug: cannot refer to external json schemas from another schema

Open mehdijouan opened this issue 8 years ago • 1 comments

Description

Hello,

I'm facing an issue regarding external references. I have a json as following that refers to another one (address.json). The json schema is valid but the swagger codegen return me an error.

{
   "$schema": "http://json-schema.org/draft-06/schema#",
   "description": "A representation of a person, company, organization, or place",
   "type": "object",
   "required": [
      "familyName",
      "givenName"
   ],
   "properties": {
      "familyName": {
         "type": "string"
      },
      "givenName": {
         "type": "string"
      },
      "nickname": {
         "type": "string"
      },
      "addresses": {
         "type": "array",
         "items": {
            "$ref": "address.json"
         }
      }
   }
}
[ERROR] Failed to execute goal io.swagger:swagger-codegen-maven-plugin:2.3.0:generate (default) on project valid_but_not_working: Execution default of goal io.swagger:swagger-codegen-maven-plugin:2.3.0:generate failed: Could not find definitions/address.json in contents of ./schemas/card.json -> [Help 1]

In order to help and explicit my issue, I created a sample maven project HERE that you can use to reproduce my issue.

As you can see in the sample project, I have a second module that build but the json syntax is invalid.

Thanks for your help and your hard work !

Swagger-codegen version

2.3.0

Command line used for generation

mvn clean package

Steps to reproduce

build project https://github.com/mehdijouan/swagger_issue using maven.

Suggest a fix/enhancement

Could you interpret simple json references as local ones ?

mehdijouan avatar Dec 29 '17 12:12 mehdijouan

        "$ref": "address.json"

What about using "$ref": "./address.json" (relative path) instead?

wing328 avatar Dec 31 '17 03:12 wing328