FFFF How to write comment when API accepts json body? · Issue #970 · go-swagger/go-swagger · GitHub
[go: up one dir, main page]

Skip to content

How to write comment when API accepts json body? #970

Closed

Description

@Krashcan

Problem statement

My web app accepts json body instead of individual parameters, so I want to be able to submit a single json body. From the documentation it is not clear how to write comments for this purpose. I don't know how I should use swagger:model or swagger:parameter here. Can you provide me a sample commented code for this example please:-

type test struct{
    test1 string `json:"test1"`
    test2 string `json:"test2"`
}

Activity

  1. casualjim commented on Mar 23, 2017

    @casualjim
    Member
    type testresponse struct {
      // in: body
      Body test
    }
    
  2. stefanhendriks commented on Nov 23, 2021

    @stefanhendriks

    I know this is a very old issue - but I do wonder how this would work with a linter that removes deadcode. Defining a struct just so that you can define a body for swagger will result into a working swagger doc but the linter will not like it. Of course we can mark this with //nolint.

    Would'nt it be nice if we could put in: body above the type test struct { part?

  3. casualjim commented on Nov 23, 2021

    @casualjim
    Member

    You can use body:test in the swagger route

    // Responses:
    // default: body:genericError
    // 200: body:someResponse
    // 422: body:validationError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0