in path parameter is ignored by go-swagger - go

I am typing to generate in path parameters using go-swagger. But after running swagger generate spec -o ./swagger.yaml --scan-models I see the generated swagger has in:query rather than in:path
package types
package types
type URCapID struct {
Vendor string `yaml:"vendorID" json:"vendorID" mapstructure:"vendorID"`
ID string `yaml:"urcapID" json:"urcapID" mapstructure:"urcapID"`
Version string `yaml:"version" json:"version" mapstructure:"version"`
}
Handle function
// swagger:parameters deleteURCap
type urcapIDParam struct {
// The id of the urcap to uninstall/delete
// in: path
// required: true
types.URCapID
}
// Uninstall and deletes urcap if installed
func Uninstall(w http.ResponseWriter, r *http.Request) {
// swagger:route DELETE /urcap/{vendorID}/{urcapID}/{version} URCap deleteURCap
//
// Delete/Uninstall URCap if installed.
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Schemes: http
//
// Responses:
// 201: noContent
}
Auto generated swagger.yaml
/urcap/{vendorID}/{urcapID}/{version}:
delete:
consumes:
- application/json
operationId: deleteURCap
parameters:
- in: query
name: vendorID
type: string
x-go-name: Vendor
- in: query
name: urcapID
type: string
x-go-name: ID
- in: query
name: version
type: string
x-go-name: Version
produces:
- application/json
responses:
"201":
$ref: '#/responses/noContent'
schemes:
- http
summary: Delete/Uninstall URCap if installed.
tags:
- URCap

Related

Uncaught SyntaxError: Invalid regular expression: missing / when using go-swagger

I'm trying to implement go-swagger but this error keep flashing. I'm using windows machine. I appreciate any help.
My implementation:
opts := middleware.RedocOpts{RedocURL: "/swagger.yaml"}
sh := middleware.Redoc(opts, nil)
getRouter.Handle("/docs", sh)
getRouter.Handle("/swagger.yaml", http.FileServer(http.Dir("./")))
My swagger definition:
// Package classification of Product API.
//
// Documentation for Product API
// Schemes: http
// BasePath: /
// version: 1.0.0
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
// swagger:meta
Error message:
The option of Redoc must be
SpecURL
opts := middleware.RedocOpts{SpecURL: "/swagger.yaml"}
instead of RedocURL
opts := middleware.RedocOpts{RedocURL: "/swagger.yaml"}

Create AWS::Pinpoint::PushTemplate using CF template

Hi I want to create AWS::Pinpoint::PushTemplate using cloudformation template and I am following this link: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-pinpoint-pushtemplate.html.
Type: AWS::Pinpoint::PushTemplate
Properties:
Default:
Action: OPEN_APP
Body: FirstName - {{firstName}}, LastName - {{lastName}}
Title: Title
DefaultSubstitutions:
firstName: default
lastName: default
Tags:
project: project
tashi: "Pinpoint Template"
TemplateName: template_name
I am getting type validation error for`DefaultSubstitutions: Property validation failure: [Value of property {/DefaultSubstitutions} does not match type {String}]
According to docs DefaultSubstitutions is a String.
However, in your case, you set it up as map:
DefaultSubstitutions:
firstName: default
lastName: default
Maybe have to try using it as json string:
DefaultSubstitutions: "{\"firstName"\:\"default\", \"lastName"\:\"default\"}"

Empty Swagger specification is created in Go API

I am trying to use generate swagger spec from my API handler.
I have installed the go-swagger from go get:
go get -u github.com/go-swagger/go-swagger/cmd/swagger
See the project structure below:
main.go uses handler definitions in products.go. (API works and is tested)
Swagger spec in product.go:
// Package classification of Product API.
//
// Documenting for Product API
//
//
//
// Schemes: http, https
// BasePath: /
// Version: 0.0.1
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta
Running the following command from main.go path:
GO111MODULE=off swagger generate spec -o ./swagger.yaml --scan-models
Response:
info: {}
paths: {}
swagger: "2.0"
Expected Response:
basePath: /
consumes:
- application/json
info:
description: Documenting for Product API
title:
version: 0.0.1
paths: {}
producrs:
- application/json
schemes:
- http
swagger: "2.0"
I assume you are following Nic's MSA Go tutorial.
In case you haven't figure out the issue yet, you forgot to add a space for the contents. (lines between the first and last line)
Your documentation comment should be as below
// Documentation for Product API
//
// Schemes: http
// BasePath: /
// Version: 1.0.0
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta
In adition to #sssang comment. Make sure you leave no space between Documentation comment and the package definition.
// Documentation for Product API
//
// Schemes: http
// BasePath: /
// Version: 1.0.0
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta
package handlers
[...rest of your code]

#AO\JsonContent in parameter of get request

In swagger's documentation using OpenApi specification, you can wrap schema in parameter to content with application/json:
parameters:
- in: query
name: filter
# Wrap 'schema' into 'content.<media-type>'
content:
application/json: # <---- media type indicates how to serialize / deserialize the parameter content
schema:
type: object
properties:
type:
type: string
color:
type: string
to send objects like this filter={"type":"t-shirt","color":"blue"}.
How to do it in swagger-php?
The swagger-editor and swagger-ui have added support for http://swagger.io/docs/specification/describing-parameters
The swagger-php library has added support too, it will be part of the 3.0.4 release.

How to Define Enum as Query Params in OpenAPI Spec

I want to define an enum value in the query string parameter of a function in an OpenAPI specification.
Here is an example of how I specify the parameter in my OpenAPI specification (yaml):
openapi: 3.0.0
info:
description: Vends sodas
version: 1.0.0
title: VendingMachineService
paths:
/soda/{bill}:
get:
summary: Provides a soda for a provided amount of money
description: Provides a soda for a provided amount of money
operationId: getSoda
parameters:
- name: bill
in: path
description: Money (e.g. one, two, five)
required: true
schema:
$ref: "#/components/schemas/Bill"
responses:
"200":
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/Result"
"404":
description: Templates for Source not found
servers:
- url: http://localhost:8080/
components:
schemas:
Bill:
type: string
enum:
- one
- two
- five
Result:
type: string
The key part of the OpenAPI spec is that I define the enum in a schema object at the bottom, type string, and refer to it in the parameters section of the function, also defining it as part of the path /{bill}
I then use openapi-generator to generate the spring server:
openapi-generator generate -i ~/vending-machine.yaml -g spring -o ~/output
I then spin up the server (importing the project into Intellij and running in a spring-boot configuration) and go to localhost:8080/ to open the Swagger UI. I try to exercise the api and get the following error:
{ "timestamp": "2019-03-29T15:43:14.737Z", "status": 400,
"error": "Bad Request", "message": "Failed to convert value of type
'java.lang.String' to required type 'org.openapitools.model.Bill';
nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type [java.lang.String] to type
[#javax.validation.constraints.NotNull
#io.swagger.annotations.ApiParam #javax.validation.Valid
#org.springframework.web.bind.annotation.RequestParam
org.openapitools.model.Bill] for value 'null'; nested exception is
java.lang.IllegalArgumentException: No enum constant
org.openapitools.model.Bill.null", "path": "/soda/%7Bbill%7D" }
(501 Not Implemented expected)
What is the proper way to define the query params & enum in the OpenAPI spec to use enum values?

Resources