Skip to content
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

generate: allOf in response doesn't use $ref #2761

Open
Kangaroux opened this issue Apr 14, 2022 · 0 comments
Open

generate: allOf in response doesn't use $ref #2761

Kangaroux opened this issue Apr 14, 2022 · 0 comments
Labels
generate spec Related to spec generation from code scanner

Comments

@Kangaroux
Copy link

Expected Behavior

Include an embedded struct in a response, label it with swagger:allOf, and expect to see a $ref in the generated schema.

Actual Behavior

The fields are listed as properties

Swagger specification

Note the allOf section for userResponse

This is the actual generated spec:

responses:
  baseResponse:
    description: ""
    headers:
      error:
        description: An error message describing what went wrong
        type: string
      ok:
        description: Whether the request was successful or not
        type: boolean
  userResponse:
    description: ""
    schema:
      allOf:
      - properties:
          error:
            description: An error message describing what went wrong
            type: string
          ok:
            description: Whether the request was successful or not
            type: boolean
        type: object
      - properties:
          user:
            $ref: '#/definitions/User'
        type: object

And this is what should be generated:

responses:
  baseResponse:
    description: ""
    headers:
      error:
        description: An error message describing what went wrong
        type: string
      ok:
        description: Whether the request was successful or not
        type: boolean
  userResponse:
    description: ""
    schema:
      allOf:
      - $ref: '#/responses/baseResponse'
      - properties:
          user:
            $ref: '#/definitions/User'
        type: object

Steps to reproduce

// swagger:response baseResponse
type BaseResponse struct {
	// An error message describing what went wrong
	Error string `json:"error,omitempty"`

	// Whether the request was successful or not
	OK bool `json:"ok"`
}

// swagger:response userResponse
type UserResponse struct {
	// in: body
	Body struct {
		// swagger:allOf
		BaseResponse

		User User `json:"user"`
	}
}

Environment

swagger version: v0.29.0
go version: go1.18 linux/amd64
OS: Pop!_OS 21.04

@Kangaroux Kangaroux changed the title generate: allOf in response body doesn't use $ref generate: allOf in response doesn't use $ref Apr 14, 2022
@fredbi fredbi added scanner generate spec Related to spec generation from code labels Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generate spec Related to spec generation from code scanner
Projects
None yet
Development

No branches or pull requests

2 participants