1
votes

I have a similar error to Swagger Schema error should NOT have additional properties, but in my case I'm referencing #/definitions so I'd appreciate some help.

I tried making an explicit object:

    responses:
          '200':
            content: application/json
            schema:
              type: object
              properties:
                id: integer

and that gives me:
Schema error at paths['/user'].post.responses['200'] should NOT have additional properties additionalProperty: content, schema Jump to line 119

I also tried:

          responses:
          '200':
            $ref: '#/definitions/UserCreateResponse'

and that gets me:
Semantic error at paths./user.post.responses.200.$ref 200 $refs cannot match any of the following: "#/definitions", "#/parameters" Jump to line 120

The object shows up as desired if I use the $ref, but the error persists in the editor.

2
Any reason you're trying to build a schema by hand, instead of using one of the many generators (provided by swagger itself and third-party implementations)?user247702
Inexperience. I'm using the Swagger Editor (swagger.io/swagger-editor) and that's where i'm seeing the error: is there a better way?tmurphree
Depends on the language and framework your working with. ASP.NET Web API for example has NSwag and Swashbuckle, both generate the spec for you based on the API you write. It's doable to write them by hand, but it's easy to make a mistake and it's not developer-friendly when it comes to maintenance.user247702

2 Answers

0
votes

Your first example is not valid. Change that to:

    produces:
      - application/json  # <-- Response Content-Type is specified by "produces"
    responses:
      '200':
        description: OK   # <-- Each response code needs a "description"
        schema:
          type: object
          properties:
            id:
              type: integer  # <---

It's hard to say what caused the 2nd error (when using $ref) because you did not post a complete spec.

-1
votes

@Stijn pointed me towards a fix: write the code, then generate the Swagger code from that.

Also, using the online editor (linked from here: https://swagger.io/swagger-editor/) instead of my local Dockerized version solved the issue as well.