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

v3: When Extend is used in ResultType, Attributes are not displayed in OpenAPI document. #2393

Closed
ikawaha opened this issue Nov 27, 2019 · 5 comments
Labels

Comments

@ikawaha
Copy link
Contributor

ikawaha commented Nov 27, 2019

When Extend is used in ResultType, expanded Attribute is not displayed in OpenAPI document.

These Attributes will be displayed if they are specified in View.
There is no problem when using Extend in Payload.

Example design

package design

import (
	. "goa.design/goa/v3/dsl"
)

var AddResult = Type("AddResult", func() {
	Attribute("result", Int, func() {
		Description("add result")
	})
	Required("result")
})

var CalcResult = ResultType("application/vnd.hoge+json", func() {
	Attributes(func() {
		Attribute("x", Int)
		Attribute("y", Int)
		Extend(AddResult)   // ← import `result` attribute
	})
})

var _ = Service("calc", func() {
	Description("The calc service performs operations on numbers.")

	Method("add", func() {
		Payload(func() {
			Attribute("a", Int, "Left operand")
			Attribute("b", Int, "Right operand")
		})
		Result(CalcResult)
		HTTP(func() {
			GET("/add/{a}/{b}")
		})
	})
})

goa gen openapi.yaml

CalcAddResponseBody does not contain result propety.

openapi.yaml
definitions:
  CalcAddResponseBody:
    title: 'Mediatype identifier: application/vnd.hoge+json; view=default'
    type: object
    properties:
      x:
        type: integer
        example: 5401762099778430809
        format: int64
      "y":
        type: integer
        example: 1918630006328122782
        format: int64
    description: AddResponseBody result type (default view)
    example:
      x: 4288748512599820841
      "y": 4212629202012168060

swagger: "2.0"
info:
  title: ""
  version: ""
host: localhost:80
consumes:
- application/json
- application/xml
- application/gob
produces:
- application/json
- application/xml
- application/gob
paths:
  /add/{a}/{b}:
    get:
      tags:
      - calc
      summary: add calc
      operationId: calc#add
      parameters:
      - name: a
        in: path
        description: Left operand
        required: true
        type: integer
      - name: b
        in: path
        description: Right operand
        required: true
        type: integer
      responses:
        "200":
          description: OK response.
          schema:
            $ref: '#/definitions/CalcAddResponseBody'
      schemes:
      - http
definitions:
  CalcAddResponseBody:
    title: 'Mediatype identifier: application/vnd.hoge+json; view=default'
    type: object
    properties:
      x:
        type: integer
        example: 5401762099778430809
        format: int64
      "y":
        type: integer
        example: 1918630006328122782
        format: int64
    description: AddResponseBody result type (default view)
    example:
      x: 4288748512599820841
      "y": 4212629202012168060

Expected

The response body contains the result property.

openapi.yaml
definitions:
  CalcAddResponseBody:
    title: 'Mediatype identifier: application/vnd.hoge+json; view=default'
    type: object
    properties:
      result:
        type: integer
        description: add result
        example: 4212629202012168060
        format: int64
      x:
        type: integer
        example: 1918630006328122782
        format: int64
      "y":
        type: integer
        example: 4288748512599820841
        format: int64
    description: AddResponseBody result type (default view)
    example:
      result: 5855163322465186600
      x: 1698882017578366363
      "y": 6747375795581831989
    required:
    - result
swagger: "2.0"
info:
  title: ""
  version: ""
host: localhost:80
consumes:
- application/json
- application/xml
- application/gob
produces:
- application/json
- application/xml
- application/gob
paths:
  /add/{a}/{b}:
    get:
      tags:
      - calc
      summary: add calc
      operationId: calc#add
      parameters:
      - name: a
        in: path
        description: Left operand
        required: true
        type: integer
      - name: b
        in: path
        description: Right operand
        required: true
        type: integer
      responses:
        "200":
          description: OK response.
          schema:
            $ref: '#/definitions/CalcAddResponseBody'
      schemes:
      - http
definitions:
  CalcAddResponseBody:
    title: 'Mediatype identifier: application/vnd.hoge+json; view=default'
    type: object
    properties:
      result:
        type: integer
        description: add result
        example: 4212629202012168060
        format: int64
      x:
        type: integer
        example: 1918630006328122782
        format: int64
      "y":
        type: integer
        example: 4288748512599820841
        format: int64
    description: AddResponseBody result type (default view)
    example:
      result: 5855163322465186600
      x: 1698882017578366363
      "y": 6747375795581831989
    required:
    - result

🤔 Although it is not related to this case, why is only the letter y quoted in the above example openapi.yaml?

@tchssk
Copy link
Member

tchssk commented Nov 27, 2019

This seems an issue caused by gopkg.in/yaml.v2. The quotes were disappeard when I change to import v3 instead of v2 in http/codegen/openapi.go .

swagger: "2.0"
info:
    title: ""
    version: ""
host: localhost:80
consumes:
  - application/json
  - application/xml
  - application/gob
produces:
  - application/json
  - application/xml
  - application/gob
paths:
    /add/{a}/{b}:
        get:
            tags:
              - calc
            summary: add calc
            operationId: calc#add
            parameters:
              - name: a
                in: path
                description: Left operand
                required: true
                type: integer
              - name: b
                in: path
                description: Right operand
                required: true
                type: integer
            responses:
                "200":
                    description: OK response.
                    schema:
                        $ref: '#/definitions/CalcAddResponseBody'
            schemes:
              - http
definitions:
    CalcAddResponseBody:
        title: 'Mediatype identifier: application/vnd.hoge+json; view=default'
        type: object
        properties:
            x:
                type: integer
                example: 5401762099778430809
                format: int64
            y:
                type: integer
                example: 1918630006328122782
                format: int64
        description: AddResponseBody result type (default view)
        example:
            x: 4288748512599820841
            y: 4212629202012168060

@tchssk
Copy link
Member

tchssk commented Nov 27, 2019

#2392 seems related to this.

@CJakey
Copy link

CJakey commented Jan 17, 2020

This doesn't just affect the documentation, but the actual result as well. I'm not seeing properties included by extended in the response body. Seems like extended properties are not included in the default view generated and are thus not projected onto the final response in gen/{servicename}/service.go

@nitinmohan87
Copy link
Contributor

@tchssk y has a special meaning in yaml files I think - go-yaml/yaml#283
It is interpreted as true. Is that what you are running into?

@stale
Copy link

stale bot commented Apr 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 25, 2020
@stale stale bot closed this as completed May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants