rapi-doc / RapiDoc

RapiDoc -WebComponent for OpenAPI Spec
https://rapidocweb.com
MIT License
1.71k stars 285 forks source link

RapiDoc not reading springfox json correctly #959

Closed RathoreGovind closed 2 months ago

RathoreGovind commented 1 year ago

I have implemented swagger using springfox in a sample spring mvc application. I want to use rapiDoc to generate API documentation from the generated API specification JSON I have specified request header in my API using the @ApiImplicitParam it is reflecting on JSON as well as on swagger-ui.html but when I use the same JSON in rapiDoc It is not showing the Request headers

I'm using swagger2 and springfox version 2.5.0. The Rapidoc looks like

this

and swagger-ui looks like

this

and the code snipett is

this

The rendered JSON found at v2/api-docs { "swagger": "2.0", "info": { "description": "Rest API Example", "version": "1", "title": "Rest API", "contact": { "name": "Edwin", "url": "http://edwin.baculsoft.con", "email": "edwin@baculsoft.com" }, "license": { "name": "Apache License" } }, "host": "localhost:8080", "basePath": "/spring-mvc-helloworld-example", "tags": [ { "name": "hello-world-controller", "description": "Hello World Controller" } ], "paths": { "/hello": { "get": { "tags": [ "hello-world-controller" ], "summary": "Testing Page", "operationId": "sayHelloUsingGET", "consumes": [ "application/json" ], "produces": [ "*/*" ], "parameters": [ { "in": "body", "name": "model", "description": "model", "required": false, "schema": { "$ref": "#/definitions/Model" } }, { "name": "header1", "in": "header", "description": "header1", "required": true, "type": "string" }, { "name": "header2", "in": "header", "description": "header2", "required": true, "type": "string" }, { "name": "header3", "in": "header", "description": "header3", "required": true, "type": "string" } ], "responses": { "200": { "description": "OK", "schema": { "type": "string" } }, "401": { "description": "Unauthorized User" }, "403": { "description": "Forbidden User" }, "404": { "description": "Not Found" } } } } } }

Please can you advice how I can fix this issue

Thanks, Govind.

prassie commented 1 year ago

rendered JSON is missing model schema referred in "schema": { "$ref": "#/definitions/Model" }

RathoreGovind commented 1 year ago

It works when the "schema": { "$ref": "#/definitions/Model" } is provided thanks for that.

When I provide it the following JSON it works. { "basePath": "/spring-mvc-helloworld-example", "definitions": { "Model": { "properties": { "name": { "type": "string" } }, "type": "object" } }, "host": "localhost:8080", "info": { "contact": { "email": "edwin@baculsoft.com", "name": "Edwin", "url": "http://edwin.baculsoft.con" }, "description": "Rest API Example", "license": { "name": "Apache License" }, "title": "Rest API", "version": "1" }, "paths": { "/hello": { "get": { "consumes": [ "application/json" ], "operationId": "sayHelloUsingGET", "parameters": [ { "description": "model", "in": "body", "name": "model", "required": true, "schema": { "$ref": "#/definitions/Model" } }, { "description": "header1", "in": "header", "name": "header1", "required": true, "type": "string" }, { "description": "header2", "in": "header", "name": "header2", "required": true, "type": "string" }, { "description": "header3", "in": "header", "name": "header3", "required": true, "type": "string" } ], "produces": [ "*/*" ], "responses": { "200": { "description": "OK", "schema": { "type": "string" } }, "401": { "description": "Unauthorized User" }, "403": { "description": "Forbidden User" }, "404": { "description": "Not Found" } }, "summary": "Testing Page", "tags": [ "hello-world-controller" ] } }, "/bye": { "post": { "consumes": [ "application/json" ], "operationId": "bye", "parameters": [ { "default": "token", "in": "header", "name": "token", "required": false, "type": "string" }, { "default": "num", "in": "header", "name": "num", "required": false, "type": "string" }, { "default": "xyz", "in": "header", "name": "xyz", "required": false, "type": "string" } ], "produces": [ "application/json" ], "responses": { "200": { "description": "OK", "schema": { "type": "string" } }, "401": { "description": "Unauthorized User" }, "403": { "description": "Forbidden User" }, "404": { "description": "Not Found" } }, "summary": "bye", "tags": [ "hello-world-controller" ] } } }, "swagger": "2.0", "tags": [ { "description": "Hello World Controller", "name": "hello-world-controller" } ] }

Take a look at the UI screen shot

Part1,Part2 Here you can see it show all the parameters and header for the request.

But with this JSON with missing schema { "basePath": "/spring-mvc-helloworld-example", "definitions": { "Model": { "properties": { "name": { "type": "string" } }, "type": "object" } }, "host": "localhost:8080", "info": { "contact": { "email": "edwin@baculsoft.com", "name": "Edwin", "url": "http://edwin.baculsoft.con" }, "description": "Rest API Example", "license": { "name": "Apache License" }, "title": "Rest API", "version": "1" }, "paths": { "/hello": { "get": { "consumes": [ "application/json" ], "operationId": "sayHelloUsingGET", "parameters": [ { "description": "model", "in": "body", "name": "model", "required": true, "schema": { "$ref": "#/definitions/Model" } }, { "description": "header1", "in": "header", "name": "header1", "required": true, "type": "string" }, { "description": "header2", "in": "header", "name": "header2", "required": true, "type": "string" }, { "description": "header3", "in": "header", "name": "header3", "required": true, "type": "string" } ], "produces": [ "*/*" ], "responses": { "200": { "description": "OK", "schema": { "type": "string" } }, "401": { "description": "Unauthorized User" }, "403": { "description": "Forbidden User" }, "404": { "description": "Not Found" } }, "summary": "Testing Page", "tags": [ "hello-world-controller" ] } }, "/bye": { "post": { "consumes": [ "application/json" ], "operationId": "bye", "parameters": [ { "description": "model", "in": "body", "name": "model", "required": true, "schema": { "$ref": "#/definitions/Model1" } }, { "default": "token", "in": "header", "name": "token", "required": false, "type": "string" }, { "default": "num", "in": "header", "name": "num", "required": false, "type": "string" }, { "default": "xyz", "in": "header", "name": "xyz", "required": false, "type": "string" } ], "produces": [ "application/json" ], "responses": { "200": { "description": "OK", "schema": { "type": "string" } }, "401": { "description": "Unauthorized User" }, "403": { "description": "Forbidden User" }, "404": { "description": "Not Found" } }, "summary": "bye", "tags": [ "hello-world-controller" ] } } }, "swagger": "2.0", "tags": [ { "description": "Hello World Controller", "name": "hello-world-controller" } ] } it will outright ignore all of the parameters, take look at these examples Part1,Part2

If I try to open the same JSON on Swagger.io it will show the available parameters take a look at these Part1,Part2

Is necessary for the JSON not to miss any thing or is there a way I can make it work.

Thanks, Govind

prassie commented 1 year ago
  1. Please embed the images instead of separate links for easier reading as shown below
  2. Seems the definitions are stored in a separate file in the basePath, which is accessible/loaded/used by Swagger, but RapiDoc might need more info. In RapiDoc need to include the other file path in ref, if the referenced detail is not part of the same file like $ref: 'templates.json#/paths/~1templates'; templates.json is a different file from main.json which has this reference.
  3. Check this example for remote reference: https://rapidocweb.com/examples/external-refs.html#servers

image

RathoreGovind commented 1 year ago

I will use embedded images thanks for the feedback. It seems I was unable to explain myself. I only have one JSON file, but it is missing some references.

Due to my application constraints it is only possible to use the springfox swagger 2 implementation.

Due to my application constraints it is producing JSON with missing references in some API's which I'm unable to fix and rapiDoc is not showing parameters of any API even if the references to those parameters are present in my JSON.

On the other hand if I open the same JSON on swagger.io it is able to show me the API parameter and also show me the error in my JSON file

image and image

but rapiDoc is not showing the same image

So is there a way by which rapiDoc can show the parameters present in my JSON

Thanks.

mrin9 commented 2 months ago

if the spec is not valid RapiDoc's behavior cannot be predicted. Provide a valid spec and report if there is any issue wid rendering via RapiDoc