How to resolve Swagger error “instance type (string) does not match any allowed primitive type…”

2,186 views
Skip to first unread message

Justin Andrews

unread,
Apr 18, 2017, 3:30:03 PM4/18/17
to Swagger
Background

I've just started a new project and would like to use Swagger for my API Documentation. I am currently running my project locally, hosted in IIS.

I have modified my hosts file to give the site a valid header. For this post, let's say the header is publicapiurl.domain.com. So, I have added the following entry to my hosts file:

127.0.0.1   publicapiurl.domain.com

Now, when I type publicapiurl.domain.com/swagger I get the swagger docs. The initial setup seemed simple enough but I have a red 'ERROR {...}' message at the bottom right corner of my swagger doc. The error message reads as follows:

{"messages":["malformed or unreadable swagger supplied"],"schemaValidationMessages":[{"level":"error","domain":"validation","keyword":"type","message":"instance type (string) does not match any allowed primitive type (allowed: [\"object\"])","schema":{"loadingURI":"#","pointer":""},"instance":{"pointer":""}}]}

I've worked a bit with Swagger in the past so I took the provided link to the generated swagger doc and copied the code. I pasted the code into the swagger.io/tools editor to see what their validation process might tell me. The code I pasted validated without any errors. Here is the code:

swagger: '2.0'
info
:
  version
: v1
  title
: Generic.Public.Api
host
: publicapiurl.domain.com
schemes
:
 
- http
paths
:
 
/api/Values:
   
get:
      tags
:
       
- Values
      operationId
: Values_Get
      consumes
: []
      produces
:
       
- application/json
       
- text/json
       
- application/xml
       
- text/xml
      responses
:
       
'200':
          description
: OK
          schema
:
            type
: array
            items
:
              type
: string
    post
:
      tags
:
       
- Values
      operationId
: Values_PostByvalue
      consumes
:
       
- application/json
       
- text/json
       
- application/xml
       
- text/xml
       
- application/x-www-form-urlencoded
      produces
: []
      parameters
:
       
- name: value
         
in: body
          required
: true
          schema
:
            type
: string
      responses
:
       
'204':
          description
: No Content
 
'/api/Values/{id}':
   
get:
      tags
:
       
- Values
      operationId
: Values_GetByid
      consumes
: []
      produces
:
       
- application/json
       
- text/json
       
- application/xml
       
- text/xml
      parameters
:
       
- name: id
         
in: path
          required
: true
          type
: integer
          format
: int32
      responses
:
       
'200':
          description
: OK
          schema
:
            type
: string
    put
:
      tags
:
       
- Values
      operationId
: Values_PutByidvalue
      consumes
:
       
- application/json
       
- text/json
       
- application/xml
       
- text/xml
       
- application/x-www-form-urlencoded
      produces
: []
      parameters
:
       
- name: id
         
in: path
          required
: true
          type
: integer
          format
: int32
       
- name: value
         
in: body
          required
: true
          schema
:
            type
: string
      responses
:
       
'204':
          description
: No Content
   
delete:
      tags
:
       
- Values
      operationId
: Values_DeleteByid
      consumes
: []
      produces
: []
      parameters
:
       
- name: id
         
in: path
          required
: true
          type
: integer
          format
: int32
      responses
:
       
'204':
          description
: No Content
definitions
: {}

Does anyone know what the aforementioned error I am getting actually means or how I may be able to resolve it?

My best guess is it has something to do with my modification of the hosts file and some type of CORS issue perhaps... but I am seriously at a loss. Any suggestions are appreciated!

Ron Ratovsky

unread,
Apr 20, 2017, 6:55:18 AM4/20/17
to swagger-sw...@googlegroups.com

Hi Justin,

 

I just tried the provided spec, and I’m not getting any errors, so it’s a bit curious.

Is the provided spec exactly what you have?

Justin Andrews

unread,
Apr 20, 2017, 11:33:57 AM4/20/17
to Swagger
That is the part that is curious to me as well.  I copied the Swagger from the provided URL on the Swagger UI.  When I paste it into the Swagger online editor it is validated with no errors.  When I run it locally (via IIS) I get the error referenced above.  This is a pretty basic implementation at this time.  I've created a new WebApi project and added swagger.  That's pretty much it...  

The only thing I can surmise is that modifying my local hosts file to spoof the header is causing some type of issue.  I'm seriously at a loss here...

Ron Ratovsky

unread,
Apr 20, 2017, 11:41:10 AM4/20/17
to swagger-sw...@googlegroups.com

Not that it should make a difference, but which version of swagger-ui do you use?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages