New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post Example #1772
Comments
To your point 1: You mean in a swagger definition? If yes, you may want to look here, it's basically only post. Or you mean rather the runtime stuff with JSON marshalling/encoding? |
Maybe an operation will work as well. Is the POST documented somewhere? https://goswagger.io/use/spec/operation.html#example |
it's the same as the get except you use
|
@casualjim, that part is clear, how about the body? Are the parameters type: body? Do we need to specify a body object and pass the 2 params in my case? |
yes it's the same. There can only be 1 body parameter so you prefer a schema You can learn about swagger itself here: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md |
This is what I did and I am getting this error:
|
whitespace is significant in yaml |
@casualjim so you are telling me that operation fails because of the spacing? But it doesn't pass the first line. If I name clientCredentials, api. clientCredentials, then the code fails silently skipping this operation. |
@casualjim, the actual file doesn't have white spaces. |
Would it be so hard to just provide a concrete example for this? I've literally been searching the documentation for an hour trying to find a good reference to do something simply like specify the POST body in the annotations. |
I had to search the repo to find this. Would be nice to have a more complete example:
e.g. where Pet would be defined as type Pet struct {
Name string `json:"name"`
...
} |
If it's any help I'm doing the markup a slightly different way and here's an example of how I've done it. The body is defined in the models.Application struct. // swagger:route POST /applications applications postApplication
// Creates a new application record.
// responses:
// 200: empty
// 400: error
// 500: error
// swagger:parameters postApplication
type postApplicationParameters struct {
// in:body
Application models.Application
} |
Not sure if it's a bug, or if it's intentional and is documented somewhere, but I ran into major issues where So this won't work: type (
// MyModel is a model for me.
//
// swagger:model
MyModel struct {
// required: true
MyField string `json:"myfield"`
}
) But this will: // My Model is a model for me.
//
// swagger:model
type MyModel struct {
// required: true
MyField string `json:"myfield"`
} I mention it here because it caused serious issues for Parameter declaration as well and seems unclear that a standard Go convention of |
The answer in https://goswagger.io/use/spec/model.html:
|
do you have any example of this? |
?????????????? |
swagger get body parameters ??? |
Hey everyone, I got same issue. After spend some time I finally got it. If is someone is getting same error, my approach is showed below: "// @param id body models.NewUserSeller true "User". Thus, the swagger UI view like a struct object. Viewing on UI : I hope it can help someone. |
Наконец-то реальная помощь! Спасибо!!! |
not work, program regard postPet as operation id. and can i commet body in this way
generate swager spec success, but when i use this spec to generate client code, get error
how can a comment post parameters? |
I think your route definition is wrong, There is no support for the Parameters like that. You do it in 2 parts (because you can reuse parameters) To define the route: The last argument on that like specifies the id of the operation. You can then define your parameters as a struct:, the body is a property on there because parameters also capture headers and query params If you don't like the model where you need to define a struct, so that type information gets verified by the compiler too, you can use the |
@casualjim thanks |
Hi there and thanks for sharing your solution But in your example it looks like you also were able to add your custom values to your example This is something i need but could not achieve by now I can not add a created variable of this type to use values i stored in the variable Swagger only generates something like this without the possibility for me to change the shown number of items nor the values of the fields/keys
|
Hi:
Thanks
The text was updated successfully, but these errors were encountered: