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

Fix OpenAPI v3 type naming issue #3571

Closed

Conversation

henryjcee
Copy link

@henryjcee henryjcee commented Aug 6, 2024

This PR modifies Goa's OpenAPI v3 generator to prevent de-duplication of explicit user types in the generated schema. this should address #3242. Presently, structurally similar types defined in the DSL e.g.:

var payload1 = Type("Payload1", func() {
	Attribute("foo", String)
})
var payload2 = Type("Payload2", func() {
	Attribute("foo", String)
})

Will result in a single entry in the generated v3 schema with an arbitrary name. After this change, Payload1 and Payload2 are generated as independent, named entries in the schema e.g.

"Payload1": {
  "example": {
    "foo": "Aut sed ducimus repudiandae sit explicabo asperiores."
  },
  "properties": {
    "foo": {
      "example": "Beatae non id consequatur.",
      "type": "string"
    }
  },
  "type": "object"
},
"Payload2": {
  "example": {
    "foo": "Vitae magni repellat minus minus dolor repellat."
  },
  "properties": {
    "foo": {
      "example": "Quas aut maxime aut non enim ullam.",
      "type": "string"
    }
  },
  "type": "object"
}

Issues

If you rely on type deduplication to generate your v3 schema, this may cause problems.

Testing

I've added a test case for this case and have formatted the test fixtures to a common style (hence the large diff). I'm currently using this fork to generate our public API docs and things are looking good.

Previous approach

As discussed with @raphael earlier, I've been looking at some ideas for fixing #3242. This PR takes a very dumb approach of merging openapi:typename tags into every Result and Payload DSL node, using the name from the endpoint.

This feels pretty bad and that's reflected in the fact that I've got test failures in quite a few places as a result of this. I do feel like this change should be taking place entirely within the openapiv3 package given that the problem appears to manifest only when generating OpenAPI v3 specs.

I am pretty new to Go and very new to Goa so I'd appreciate some eyes and advice on this if anyone has the time.

…s if none is provided. This seems like quite a big hammer approach to this problem and this is reflected in the number of tests that are failing as a result of this.
@henryjcee henryjcee changed the title Merge openapi:typename Meta keys into the Payload and Result DSL call… Fix OpenAPI v3 type naming issue Aug 6, 2024
@raphael
Copy link
Member

raphael commented Aug 14, 2024

PR #3572 achieves the desired outcome and there are a few issues with this PR (the hashing still needs to happen in the OpenAPI generators) so closing in favor of the other PR.

@raphael raphael closed this Aug 14, 2024
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 this pull request may close these issues.

2 participants