Import swagger file into Developer Portal using an API

Not applicable

Hello,

I am trying to import a swagger spec into the Developer Portal using the API, i make the following request (minimalistic petstore example as payload from OpenAPISpec ) at

https://api.enterprise.apigee.com/v1/organizations/{orgName}/apimodels/{modelName}/import/file?forma...

And i get the following response

{
  "id": "306b89d2-90e2-4818-9816-777517c11131",
  "revisionNumber": 7,
  "baseUrl": "http://petstore.swagger.io/api",
  "releaseVersion": "1.0.0",
  "resources": [
    {
      "id": "57da2edf-7431-4061-a124-1de4837d0936",
      "name": "pets",
      "baseUrl": "http://petstore.swagger.io/api",
      "path": "/pets",
      "parameters": [
        {
          "dataType": "string",
          "name": "Content-Type",
          "options": [
            "application/json"
          ],
          "type": "header"
        }
      ],
      "methods": [
        {
          "id": "b83c49bb-6bb7-4277-b665-13ecfca6f01d",
          "name": "addPet",
          "description": "Creates a new pet in the store.  Duplicates are allowed",
          "verb": "post",
          "parameters": [],
          "body": {
            "accept": "application/json",
            "attachments": [],
            "doc": "Pet to add to the store",
            "parameters": [
              {
                "allowMultiple": false,
                "dataType": "object",
                "name": "pet",
                "required": true,
                "schema": "{\n  \"$ref\" : \"#/definitions/NewPet\"\n}",
                "type": "body"
              }
            ]
          },
          "response": {
            "errors": [],
            "parameters": [],
            "schema": {
              "dataType": "{\n  \"$ref\" : \"#/definitions/Pet\"\n}{\n  \"$ref\" : \"#/definitions/ErrorModel\"\n}"
            }
          },
          "apiSchema": {
            "type": "json"
          },
          "customAttributes": {
            "SWAGGER_PRODUCES": "[ \"application/json\" ]",
            "SWAGGER_METHOD_AUTH": ""
          },
          "createdTime": 1471461176019,
          "apiRevisionId": "306b89d2-90e2-4818-9816-777517c11131",
          "baseUrl": "http://petstore.swagger.io/api",
          "methods": [],
          "path": "/pets",
          "resourceId": "57da2edf-7431-4061-a124-1de4837d0936",
          "resourceName": "pets",
          "resources": [],
          "revisionNumber": 7
        },
        {
          "id": "335fc048-a729-45ab-a48c-ad4b3858aaa1",
          "name": "findPets",
          "description": "Returns all pets from the system that the user has access to",
          "verb": "get",
          "parameters": [
            {
              "allowMultiple": false,
              "dataType": "array",
              "description": "tags to filter by",
              "items": "{\n  \"type\" : \"string\"\n}",
              "name": "tags",
              "required": false,
              "type": "query"
            },
            {
              "allowMultiple": false,
              "dataType": "integer",
              "description": "maximum number of results to return",
              "name": "limit",
              "required": false,
              "type": "query"
            }
          ],
          "body": {
            "accept": "application/json,application/xml,text/xml,text/html",
            "attachments": [],
            "parameters": []
          },
          "response": {
            "errors": [],
            "parameters": [],
            "schema": {
              "dataType": "{\n  \"type\" : \"array\",\n  \"items\" : {\n    \"$ref\" : \"#/definitions/Pet\"\n  }\n}{\n  \"$ref\" : \"#/definitions/ErrorModel\"\n}"
            }
          },
          "apiSchema": {
            "type": "json"
          },
          "customAttributes": {
            "SWAGGER_PRODUCES": "[ \"application/json\", \"application/xml\", \"text/xml\", \"text/html\" ]",
            "SWAGGER_METHOD_AUTH": ""
          },
          "createdTime": 1471461176019,
          "apiRevisionId": "306b89d2-90e2-4818-9816-777517c11131",
          "baseUrl": "http://petstore.swagger.io/api",
          "methods": [],
          "path": "/pets",
          "resourceId": "57da2edf-7431-4061-a124-1de4837d0936",
          "resourceName": "pets",
          "resources": [],
          "revisionNumber": 7
        }
      ],
      "customAttributes": {
        "SWAGGER_RESOURCE_PATH": "/pets",
        "SWAGGER_PRODUCES": "[ \"application/json\" ]",
        "SWAGGER_PROTOCOLS": "[ \"http\" ]"
      },
      "createdTime": 1471461176017,
      "apiRevisionId": "306b89d2-90e2-4818-9816-777517c11131",
      "resources": [],
      "revisionNumber": 7
    },
    {
      "id": "8451e805-1b7c-4dad-9f3d-3e2b79d63a54",
      "name": "pets-id",
      "baseUrl": "http://petstore.swagger.io/api",
      "path": "/pets/{id}",
      "parameters": [
        {
          "dataType": "string",
          "name": "Content-Type",
          "options": [
            "application/json"
          ],
          "type": "header"
        }
      ],
      "methods": [
        {
          "id": "b3e6721f-fe3a-4973-af32-29a9a05e1c77",
          "name": "findPetById",
          "description": "Returns a user based on a single ID, if the user does not have access to the pet",
          "verb": "get",
          "parameters": [
            {
              "allowMultiple": false,
              "dataType": "integer",
              "description": "ID of pet to fetch",
              "name": "id",
              "required": true,
              "type": "template"
            }
          ],
          "body": {
            "accept": "application/json,application/xml,text/xml,text/html",
            "attachments": [],
            "parameters": []
          },
          "response": {
            "errors": [],
            "parameters": [],
            "schema": {
              "dataType": "{\n  \"$ref\" : \"#/definitions/Pet\"\n}{\n  \"$ref\" : \"#/definitions/ErrorModel\"\n}"
            }
          },
          "apiSchema": {
            "type": "json"
          },
          "customAttributes": {
            "SWAGGER_PRODUCES": "[ \"application/json\", \"application/xml\", \"text/xml\", \"text/html\" ]",
            "SWAGGER_METHOD_AUTH": ""
          },
          "createdTime": 1471461176019,
          "apiRevisionId": "306b89d2-90e2-4818-9816-777517c11131",
          "baseUrl": "http://petstore.swagger.io/api",
          "methods": [],
          "path": "/pets/{id}",
          "resourceId": "8451e805-1b7c-4dad-9f3d-3e2b79d63a54",
          "resourceName": "pets-id",
          "resources": [],
          "revisionNumber": 7
        },
        {
          "id": "dff7d062-af91-47b3-8829-2cccf9c991c1",
          "name": "deletePet",
          "description": "deletes a single pet based on the ID supplied",
          "verb": "delete",
          "parameters": [
            {
              "allowMultiple": false,
              "dataType": "integer",
              "description": "ID of pet to delete",
              "name": "id",
              "required": true,
              "type": "template"
            }
          ],
          "body": {
            "attachments": [],
            "parameters": []
          },
          "response": {
            "errors": [
              {
                "code": "204",
                "description": "pet deleted",
                "httpStatusCode": "204"
              }
            ],
            "parameters": [],
            "schema": {
              "dataType": "{\n  \"$ref\" : \"#/definitions/ErrorModel\"\n}"
            }
          },
          "apiSchema": {
            "type": "json"
          },
          "customAttributes": {
            "SWAGGER_METHOD_AUTH": ""
          },
          "createdTime": 1471461176019,
          "apiRevisionId": "306b89d2-90e2-4818-9816-777517c11131",
          "baseUrl": "http://petstore.swagger.io/api",
          "methods": [],
          "path": "/pets/{id}",
          "resourceId": "8451e805-1b7c-4dad-9f3d-3e2b79d63a54",
          "resourceName": "pets-id",
          "resources": [],
          "revisionNumber": 7
        }
      ],
      "customAttributes": {
        "SWAGGER_RESOURCE_PATH": "/pets/{id}",
        "SWAGGER_PRODUCES": "[ \"application/json\" ]",
        "SWAGGER_PROTOCOLS": "[ \"http\" ]"
      },
      "createdTime": 1471461176017,
      "apiRevisionId": "306b89d2-90e2-4818-9816-777517c11131",
      "resources": [],
      "revisionNumber": 7
    }
  ],
  "customAttributes": {
    "SWAGGER_INFO": "{\n  \"description\" : \"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification\",\n  \"version\" : \"1.0.0\",\n  \"title\" : \"Swagger Petstore\",\n  \"termsOfService\" : \"http://swagger.io/terms/\",\n  \"contact\" : {\n    \"name\" : \"Swagger API Team\"\n  },\n  \"license\" : {\n    \"name\" : \"MIT\"\n  }\n}",
    "SWAGGER_VERSION": "2.0"
  },
  "createdTime": 1471461175983
}


Everything seems to fine, but when i go to the UI to publish the spec, i see that the parameters are missing and the final documentation rendered is almost empty (nothing besides description for POST API's as well, no button to send request,etc.)

What am i doing wrong? Any guidance will be appreciated

Solved Solved
0 9 2,461
1 ACCEPTED SOLUTION

Not applicable
templatejson.txt

@Rahul Ok After some research and help from our expert @Gitesh Koli we are able to resolve this.

You were getting this error in Rendering and publishing because there is a template that goes with this API. This template is automatically loaded when you use the dev portal UI to import the swagger file. However, this template was missing when you uploaded the swagger file through Smartdoc api.

All you need to do is upload the template as follows and it should fix your problem.

use the api call to post the template as follows:

  • provide userid / password as Basic Authorization header
  • Content-Type is text/html
  • Body: copy the content of attached file (this is the template)

Also, now your api sequence will be as follows:

  • Create model
  • Post template
  • Post swagger file

Thanks and hope this helps.

--Pradeep

View solution in original post

9 REPLIES 9

Not applicable

hi @Rahul,

After you import the Open API specification - do you see that entry from your dev portal UI. (you should, based on the 201 response on your API call)

If yes, when you go in to that model - do you see the option to 'render and publish' nodes? (you have to select all nodes before you do this - otherwise the published docs might not have any nodes)

When you do that- do you see the documentation page with all your nodes published?

I followed these steps on the sample API in your link - and I am able to see my smartdocs here

3403-screen-shot-2016-08-18-at-103529-am.png

3404-screen-shot-2016-08-18-at-10-36-03-am.png

Not applicable

@Sandeep Murusupalli

Yes, i am able to see the option to publish them in Dev Portal UI exactly the way you described.

After i publish them, i am able to see the nodes as well. However, there are no details on these published nodes (no parameters, no option to send request). It appears that the UI Rendering is incomplete.

I am attaching a snapshot of what i see devportal-smartdocsnotrendering.jpg

As you notice , no documentation is rendered.

Not applicable

Hmmm.. that is weird... Can you try flushing your portal cache and see if the docs appear properly?

3406-screen-shot-2016-08-18-at-113839-am.png

And can you check it on a different browser (and incognito mode) if flushing the cache does not fix it.

Not applicable

@Sandeep Murusupalli Doesn't help, on a side note i have also been talking to @pdani through official channels. He has been able to replicate the issue, so i don't think it's limited to my browser or my dev portal.

Not applicable

@Rahul I tried it yesterday. I am able to reproduce the problem on my side. I tried different options and it almost seems like there might be a problem with the API.

I will follow up on this and let you know when this is resolved.

Thanks and apologies for the inconvenience.

Check out this community post on how publish an OpenAPI spec through the API:

https://community.apigee.com/questions/25517/publish-swagger-file-through-api.html

@Chris Novak Yeah, I looked at this post. I think @Rahul also followed this post but seems like the api is importing the swagger successfully but is not rendering and publilshing it properly. I did manual "render and publish".

Not applicable
templatejson.txt

@Rahul Ok After some research and help from our expert @Gitesh Koli we are able to resolve this.

You were getting this error in Rendering and publishing because there is a template that goes with this API. This template is automatically loaded when you use the dev portal UI to import the swagger file. However, this template was missing when you uploaded the swagger file through Smartdoc api.

All you need to do is upload the template as follows and it should fix your problem.

use the api call to post the template as follows:

  • provide userid / password as Basic Authorization header
  • Content-Type is text/html
  • Body: copy the content of attached file (this is the template)

Also, now your api sequence will be as follows:

  • Create model
  • Post template
  • Post swagger file

Thanks and hope this helps.

--Pradeep

Not applicable

@pdani, Thank you, this worked.