Swagger-ui: Bad schema rendering for primitive values in OAS 3.0

Created on 1 Aug 2017  路  9Comments  路  Source: swagger-api/swagger-ui

For OAS 3.0 rendering of primitive values (not object or array) in the schema somehow broken:

  1. The schema doesn't have a name.
  2. Any usages of the schema with the primitive value inside another schema leaves blank space.

Rendering screenshot: http://imgur.com/IJdpWlk

Reproducible for both swagger-editor and standalone swagger-ui.

Swagger version:

{
  "swaggerEditor": "3.1.0/g66e6130-dirty",
  "swaggerUi": {
    "buildTimestamp": "Sat, 29 Jul 2017 19:20:17 GMT",
    "gitDirty": false,
    "gitRevision": "g0f7fa1f",
    "machine": "testing-gce-6bc5f0a0-dfd8-49cf-a163-82f7473df464",
    "version": "3.1.0"
  }
}

Minimal reproducible config:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Test
paths:
  /test:
    get:
      responses:
        200:
          description: test
components:
  schemas:
    primitive:
      type: integer
      format: int64
    array-of-primitives:
      type: array
      items: 
        - $ref: '#/components/schemas/primitive'
      default: [1]
P2 lock-bot 3.x bug 3.x

All 9 comments

  1. Any usages of the schema with the primitive value inside another schema leaves blank space.

This is because the spec is not valid. It should be

      items: 
         $ref: '#/components/schemas/primitive'

without the - before $ref. items is an object, not an array.

Also, OAS 3.0 says the response status codes must be quoted: '200'

I tried your fixes in the swagger editor. Array rendering is fixed. But, primitive value still doesn't have a name and I got this errors in the editor:

Schema error at components.schemas['array-of-primitives']
should have required property '$ref'
missingProperty: $ref
Jump to line 16
Schema error at components.schemas['array-of-primitives']
should match exactly one schema in oneOf
Jump to line 16
Schema error at components.schemas['array-of-primitives'].items
should be array
Jump to line 18

@owenconti - I think you dealt with a similar issue before.

@LMnet, items should be an array was a bug (https://github.com/swagger-api/swagger-editor/issues/1439) that was just fixed (in https://github.com/swagger-api/swagger-editor/pull/1449). Apologies for the misleading error message!

@shockey :+1:
But rendering primitives without a name is still here.

@LMnet working on it now.

I'm using the swagger editor online (http://editor.swagger.io/) and still have the same issue:

openapi: "3.0.0"
info:
  title: api
  version: "1.0.0"
paths:
  /tenant:
    get:
      tags: ["Tenant"]
      responses:
        200:
          description: A list of Tenants
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/tenant"
components:
  schemas:
    tenant:
      type: object
      properties:
        id:
          type: integer
        code:
          type: string
        name:
          type: string
        owner_user_id:
          type: integer

This causes a lot of errors:

Schema error at paths['/tenant'].get.responses['200']
should have required property '$ref'
missingProperty: $ref
Jump to line 10
Schema error at paths['/tenant'].get.responses['200']
should match exactly one schema in oneOf
Jump to line 10
Schema error at paths['/tenant'].get.responses['200'].content['application/json']
should have required property 'examples'
missingProperty: examples
Jump to line 13
Schema error at paths['/tenant'].get.responses['200'].content['application/json']
should match exactly one schema in oneOf
Jump to line 13
Schema error at paths['/tenant'].get.responses['200'].content['application/json'].schema
should have required property '$ref'
missingProperty: $ref
Jump to line 14
Schema error at paths['/tenant'].get.responses['200'].content['application/json'].schema
should match exactly one schema in oneOf
Jump to line 14
Schema error at paths['/tenant'].get.responses['200'].content['application/json'].schema
should have required property '$ref'
missingProperty: $ref
Jump to line 14
Schema error at paths['/tenant'].get.responses['200'].content['application/json'].schema
should match exactly one schema in oneOf
Jump to line 14
Schema error at paths['/tenant'].get.responses['200'].content['application/json'].schema.items
should be array
Jump to line 16
Schema error at paths['/tenant'].get.responses['200'].content['application/json'].schema.items
should be array
Jump to line 16

If I add the dash before $ref, it works.

@iget-master I found what when I add $ref field to my definition with self pointed value this error

should have required property '$ref'
missingProperty: $ref

error is gone.
For example:

Courses:
    $ref: '#/components/schemas/Courses'

Locking due to inactivity.

This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.

If you think you're experiencing something similar to what you've found here: please open a new issue, follow the template, and reference this issue in your report.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SzymonKlimuk picture SzymonKlimuk  路  32Comments

peter004 picture peter004  路  49Comments

newtechfellas picture newtechfellas  路  47Comments

reginaldlouis picture reginaldlouis  路  43Comments

hkosova picture hkosova  路  40Comments