goadesign / goadesign/goa

Generating OpenAPI file has wrong schemas used

Open
#3,242 6 comments 1 reaction 0 assignees View on GitHub
no-issue-activity
Dominant language
Go
Stars
6.1k
Forks
583
Avg merge
2d 10h
Merged PRs (30d)
15

Description

I'm having an issue where the generated OpenAPI file is using a different type (though identical in format) than what is specified. We are running ~3.10.2~ 3.11.0 of goa.

Say I have two files that contain design documentation (ObjectA & ObjectB) and each has a PUT api method and both bodies have a "child" field object that contains the field "ref" that is a string.

__Body Objects__

```
// ObjectA Body Object
{
child: {
ref: string;
}
}

// ObjectB Body Object
{
child: {
ref: string;
}
}
```

_object_a.go_
```go
package design

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

var _ = Service("objectA", func() {

HTTP(func() {
Path("/objectA")
CanonicalMethod("push")
})

Method("push", func() {
Payload(func() {
Attribute("objectA", ObjectAPayload, "")
})

HTTP(func() {
PUT("/")
Body("objectA")
})
})
})

var ObjectAPayload = Type("ObjectAPayload", func() {
Attribute("child", ObjectAChild, "")

Required("child")
})

var ObjectAChild = Type("ObjectAChild", func() {
Attribute("ref", String, "Unique reference", func() {
Example("aac4894c-357b-46b5-a57e-bd6dfcee8a88")
})

Required("ref")
})
```

_object_b.go_

```go
package design

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

var _ = Service("objectB", func() {

HTTP(func() {
Path("/objectA")
CanonicalMethod("push")
})

Method("push", func() {
Payload(func() {
Attribute("objectB", ObjectBPayload, "")
})

HTTP(func() {
PUT("/")
Body("objectB")
})
})
})

var ObjectBPayload = Type("ObjectBPayload", func() {
Attribute("child", ObjectBChild, "")

Required("child")
})

var ObjectBChild = Type("ObjectBChild", func() {
Attribute("ref", String, "Unique reference", func() {
Example("aac4894c-357b-46b5-a57e-bd6dfcee8a89")
})

Required("ref")
})
```

When running "gen" I get the following in the OpenApi yaml file (abbreviated version)

```yaml
ObjectAPayload:
type: object
properties:
child:
$ref: '#/components/schemas/ObjectAChild'

...

ObjectBPayload:
type: object
properties:
child:
$ref: '#/components/schemas/ObjectAChild'
```

If you notice it has used ObjectAChild (incorrectly) as the type for `ObjectBPayload.child` instead of ObjectBChild. If I rename the `object_b.go` file to `aobject_b.go` (i.e. earlier lexicographically) then ObjectB get's set correctly but ObjectA.child is ObjectBChild instead.

So it seams to check if any objects match the structure and it that structure is already defined then it uses the existing one instead of the type specified.

What get's the types generated correctly

- In one of the child objects change "ref" to "ref1"
- Add another field to ObjectB to make it different from ObjectA

What does not work getting the types generated correctly

- Changing the examples to be different
- Ensuring different descriptions

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.