khrt / Raisin

Raisin - a REST API micro framework for Perl 🐫 🐪
61 stars 30 forks source link

Swagger file incomplete and with errors #59

Closed beccon4 closed 5 years ago

beccon4 commented 5 years ago

I noticed a difference in the Swagger file genererated when I switch from Yaml to Json format and vice versa. Both seem to be incomplete in the way that they lack the definition of the Album entity causing the Swagger output description to be incomplete ("null")

{
  "artist": "string",
  "name": "string",
  "hash": "string",
  "id": 0,
  "albums": [
    null
  ]
}

YAML:

basePath: /
consumes: &1
  - application/x-yaml
  - application/json
definitions:
  MusicApp::Entity::Artist-302668EB84:
    properties:
      albums:
        items:
          $ref: '#/definitions/MusicApp::Entity::Album-AFC2856845'
        type: array
      artist:
        description: Artist name
        type: string
      hash:
        description: ID*10
        type: string
      id:
        description: ID
        format: int32
        type: integer
      name:
        description: Artist name /shown only if it equals to Nirvana/
        type: string
    required:
      - id
      - name
      - artist
      - hash
      - albums
    type: object
host: localhost:5004
info:
  title: API
  version: 0.0.1
paths:
  /albums:
    get:
      consumes: *1
      description: ''
      operationId: get_albums
      produces: *1
      responses:
        default:
          description: Unexpected error
      summary: List
      tags:
        - albums
  '/albums/{id}':
    get:
      consumes: *1
      description: ''
      operationId: get_albums__id
      parameters:
        - description: ''
          format: int32
          in: path
          name: id
          required: &2 !!perl/scalar:JSON::PP::Boolean 1
          type: integer
      produces: *1
      responses:
        default:
          description: Unexpected error
      summary: ''
      tags:
        - albums
  /artists:
    get:
      consumes: *1
      description: ''
      operationId: get_artists
      produces: *1
      responses:
        200:
          description: List
          schema:
            $ref: '#/definitions/MusicApp::Entity::Artist-302668EB84'
        default:
          description: Unexpected error
      summary: List
      tags:
        - artists
  '/artists/{id}':
    get:
      consumes: *1
      description: ''
      operationId: get_artists__id
      parameters:
        - description: ''
          format: int32
          in: path
          name: id
          required: *2
          type: integer
      produces: *1
      responses:
        200:
          description: ''
          schema:
            $ref: '#/definitions/MusicApp::Entity::Artist-302668EB84'
        default:
          description: Unexpected error
      summary: ''
      tags:
        - artists
produces: *1
schemes:
  - http
security: []
securityDefinitions: {}
swagger: 2.0
tags:
  - description: Artist API
    name: artists
  - description: Albums API
    name: albums

The first complain is about the line 60:

required: &2 !!perl/scalar:JSON::PP::Boolean 1

which is: unknown tag !<tag:yaml.org,2002:perl/scalar:JSON::PP::Boolean>

We have a definition of the Entity usicApp::Entity::Artist-302668EB84 which references the definition for the nested object Albums which links here

/definitions/MusicApp::Entity::Album-AFC2856845'

but the corresponding definition for Album doesn't exist.

Json

The Json Representation of the same application causes an additional complains about

Semantic error at definitions.MusicApp::Entity::Artist-302668EB84.properties.albums.items.$ref $refs must reference a valid location in the document Jump to line 24

due to the quoting of the object names. (probably comes from the fact that Json requires quoting)

The definition for the Album entity is missing here too.

beccon4 commented 5 years ago

I did some research and found a solution which is local to the Swagger plugin. Let me test it thoroughly and i can send a patch.

khrt commented 5 years ago

Fixed #63