cloudflare / doca

A CLI tool that scaffolds API documentation based on JSON HyperSchemas.
BSD 3-Clause "New" or "Revised" License
228 stars 36 forks source link

JSON Schemas external files #80

Closed Reedian closed 7 years ago

Reedian commented 7 years ago

I have a project where during the tests I'm validating API JSON responses against written JSON schemas. My idea is to generate API documentation from it with minimal effort.

I have tried to reference to my schemas from the base schema without any result.

For example, I have base schema file for /confirmation resource - confirmation_api.json:

{
  "id": "/confirmation",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Confirmation",
  "description": "Requests within confirmation path",
  "type": "object",
  "definitions": {
    "confirmation_token": {
      "type": "integer",
      "description": "Confirmation token",
      "example": 1
    }
  },
  "links": [
    {
      "title": "Confirm account",
      "description": "Confirm your account",
      "rel": "self",
      "href": "/api/v1/confirmation?confirmation_token={#/definitions/confirmation_token}",
      "method": "GET",
      "authentication_needed": false,
      "targetSchema": { "$ref": "show_confirmation.json" }
    }
  ]
}

and my schema file which I use for testing etc. show_confirmation.json

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "required": ["id", "email", "created_at", "updated_at"],
  "properties": {
    "id" : { "type" : "string" },
    "email" : { "type" : "string" },
    "created_at" : { "type" : "string", "format": "date-time" },
    "updated_at" : { "type" : "string", "format": "date-time" }
  }
}

I was only able to load it to the base schema properties by properties: { "$ref": "show_confirmation.json#/properties" } but that is not what I want to achieve.

Is doca supporting reference to the schema from an external file? If yes what am I missing?

handrews commented 7 years ago

@Reedian in general, references to external files are supported.

Where is the properties: { "$ref": "show_confirmation.json#/properties" } part? I don't see it in either file. Also, what are the file names of each of these and are they in the same directory? Is the second one show_confirmation.json?

Reedian commented 7 years ago

@handrews I haven't included properties because it is not the part of my question, only the sidenote. Updated original message with file names.

handrews commented 7 years ago

@Reedian assuming those two files are in the same directory, that should work.

What is the error you are seeing?

Reedian commented 7 years ago

@handrews exactly, they are in the same directory. I'm not seeing any error. It just does not get rendered.

image

As you can see on the screenshot above the response object is empty. My expectations were rather to see the response which I have defined in show_confirmation.json.

handrews commented 7 years ago

@Reedian I have reproduced this with both the bootstrap and internal cloudflare theme, and I am baffled. Although this seems to be the same as #75 which I have shamefully forgotten about repeatedly (for a variety of reasons). I'm going to poke at both examples a bit more, but may close this in favor of tracking the issue in the older ticket.

Reedian commented 7 years ago

@handrews okay I will close the issue. Just for information please tell me are you planning to fix it anytime soon?

handrews commented 7 years ago

@Reedian I'm still trying to figure out why it happens, given that a similar construct works in numerous other doca-generated projects. I definitely want to fix it.

Reedian commented 7 years ago

@handrews closing this one. Fingers crossed that you will find solution :)