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

OpenAPI generating incorrect requestBody example #3594

Closed
smithamax opened this issue Sep 19, 2024 · 1 comment · Fixed by #3596
Closed

OpenAPI generating incorrect requestBody example #3594

smithamax opened this issue Sep 19, 2024 · 1 comment · Fixed by #3596

Comments

@smithamax
Copy link

smithamax commented Sep 19, 2024

Design

package design

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

var _ = Service("foo", func() {
	Method("create", func() {
		Payload(func() {
			Attribute("foo", Foo, "foo")
		})

		HTTP(func() {
			POST("/foo")
			Body("foo")
		})
	})
})

var _ = Service("bar", func() {
	Method("create", func() {
		Payload(func() {
			Attribute("bar", Bar, "bar")
		})

		HTTP(func() {
			POST("/bar")
			Body("bar")
		})
	})
})

var Foo = Type("Foo", func() {
	Attribute("index", Int, "index of foo")
})

var Bar = Type("Bar", func() {
	Attribute("name", String, "name of bar")
})

Results in an incorrect example being generated for bar requestBody, foo is used to generate the example

                    application/json:
                        schema:
                            $ref: '#/components/schemas/Bar'
                        example:
                            index: 1078416284801620699

Full output

openapi: 3.0.3
info:
    title: Goa API
    version: 0.0.1
servers:
    - url: http://localhost:80
      description: Default server for foo
paths:
    /bar:
        post:
            tags:
                - bar
            summary: create bar
            operationId: bar#create
            requestBody:
                description: bar
                required: true
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/Bar'
                        example:
                            index: 1078416284801620699
            responses:
                "204":
                    description: No Content response.
    /foo:
        post:
            tags:
                - foo
            summary: create foo
            operationId: foo#create
            requestBody:
                description: foo
                required: true
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/Foo'
                        example:
                            index: 1078416284801620699
            responses:
                "204":
                    description: No Content response.
components:
    schemas:
        Bar:
            type: object
            properties:
                name:
                    type: string
                    description: name of bar
                    example: Vero nisi sint eum.
            example:
                name: Itaque tempore omnis quia.
        Foo:
            type: object
            properties:
                index:
                    type: integer
                    description: index of foo
                    example: 4530605782497482443
                    format: int64
            example:
                index: 3714141415529535030
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@smithamax and others