gnostic icon indicating copy to clipboard operation
gnostic copied to clipboard

invalid generated swagger from proto with protoc-gen-openapi

Open vtolstov opened this issue 3 years ago • 4 comments

i have proto file with { post: "/some/path/XXX?RqUID={RqUID}&RqTm={RqTm}"; body: "*"; }; so i think that generated swagger have RqUID and RqTm in path query parameters and other in body but

paths:
    /some/path/XXX?RqUID={RqTm: // this is invalid
        post:
            tags:
                - XXX
            operationId: someOperation
            parameters:
                - name: RqUID
                  in: path
                  required: true
                  schema:
                    type: string
                - name: RqTm
                  in: path
                  required: true
                  schema:
                    type: string

vtolstov avatar Feb 17 '22 20:02 vtolstov

if u, err := url.Parse(path); err == nil {
		mp := u.Query()
		path = u.Path
		if mp != nil {
			for _, field := range inputMessage.Fields {
				fieldName := string(field.Desc.Name())
				if _, ok := mp[fieldName]; ok && fieldName != bodyField {
					fieldParams := g.buildQueryParamsV3(field)
					parameters = append(parameters, fieldParams...)
					coveredParameters = append(coveredParameters, fieldName)
				}
			}
		}
	}

	// Find simple path parameters like {id}
	if allMatches := g.pathPattern.FindAllStringSubmatch(path, -1); allMatches != nil {
	```

vtolstov avatar Feb 17 '22 21:02 vtolstov

this is my ugly code to fix my issue, do you have better ?

vtolstov avatar Feb 17 '22 21:02 vtolstov

i'm parse path via url.Path and check Query parameters if it not nil i'm check does it contains message field name, if so - generate query parameter in swagger

vtolstov avatar Feb 17 '22 21:02 vtolstov

@vtolstov I'm not sure if the post: value is supposed to contain query parameters. In all of the examples provided by google, I don't see any that specifies query parameters in the path. For example, if you look at: https://cloud.google.com/apis/design/standard_methods#create

it says:

All remaining request message fields shall map to the URL query parameters.

So I'm not sure if this is a valid case.

jeffsawatzky avatar Apr 07 '23 02:04 jeffsawatzky